[PATCH 1 of 2 hglib] hglib: abstract out use of cStringIO.StringIO (issue4520)

Brett Cannon brett at python.org
Fri Mar 13 15:37:45 UTC 2015


# HG changeset patch
# User Brett Cannon <brett at python.org>
# Date 1426260714 14400
#      Fri Mar 13 11:31:54 2015 -0400
# Node ID f3c430afa59888273201c715123649ee6ec48b3a
# Parent  3c59643a2bc3e80ede1af6a9b19836cd39dc2fae
hglib: abstract out use of cStringIO.StringIO (issue4520)

The cStringIO module does not exist in Python 3, but io.BytesIO does.
This change prepares for the use of io.BytesIO when available by
replacing all uses of cStringIO.StringIO with an object named BytesIO.

diff -r 3c59643a2bc3 -r f3c430afa598 hglib/client.py
--- a/hglib/client.py	Wed Mar 11 14:53:36 2015 -0500
+++ b/hglib/client.py	Fri Mar 13 11:31:54 2015 -0400
@@ -1,4 +1,5 @@
-import subprocess, os, struct, cStringIO, re, datetime
+import subprocess, os, struct, re, datetime
+from cStringIO import StringIO as BytesIO
 import hglib, error, util, templates, merge, context
 
 from util import b, cmdbuilder
@@ -162,7 +163,7 @@
         input is used to reply to bulk data requests by the server
         It receives the max number of bytes to return
         """
-        out, err = cStringIO.StringIO(), cStringIO.StringIO()
+        out, err = BytesIO(), BytesIO()
         outchannels = {b('o') : out.write, b('e') : err.write}
 
         inchannels = {}
diff -r 3c59643a2bc3 -r f3c430afa598 hglib/util.py
--- a/hglib/util.py	Wed Mar 11 14:53:36 2015 -0500
+++ b/hglib/util.py	Fri Mar 13 11:31:54 2015 -0400
@@ -1,4 +1,5 @@
-import itertools, cStringIO, error, os, subprocess, sys
+import itertools, error, os, subprocess, sys
+from cStringIO import StringIO as BytesIO
 
 if sys.version_info[0] > 2:
     def b(s):
@@ -25,7 +26,7 @@
     >>> eatlines("1\\n2\\n3", 1)
     '2\\n3'
     """
-    cs = cStringIO.StringIO(s)
+    cs = BytesIO(s)
 
     for line in cs:
         n -= 1
@@ -46,7 +47,7 @@
     >>> skiplines('a\\nb', 'b')
     'a\\nb'
     """
-    cs = cStringIO.StringIO(s)
+    cs = BytesIO(s)
 
     for line in cs:
         if not line.startswith(prefix):
diff -r 3c59643a2bc3 -r f3c430afa598 tests/test-import.py
--- a/tests/test-import.py	Wed Mar 11 14:53:36 2015 -0500
+++ b/tests/test-import.py	Fri Mar 13 11:31:54 2015 -0400
@@ -1,4 +1,5 @@
-import common, cStringIO, os
+import common, os
+from cStringIO import StringIO as BytesIO
 import hglib
 from hglib.util import b
 
@@ -19,7 +20,7 @@
 
 class test_import(common.basetest):
     def test_basic_cstringio(self):
-        self.client.import_(cStringIO.StringIO(patch))
+        self.client.import_(BytesIO(patch))
         self.assertEquals(self.client.cat([b('a')]), b('1\n'))
 
     def test_basic_file(self):


More information about the Mercurial-devel mailing list