Mercurial > python-hglib
changeset 145:f3c430afa598
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.
author | Brett Cannon <brett@python.org> |
---|---|
date | Fri, 13 Mar 2015 11:31:54 -0400 |
parents | 3c59643a2bc3 |
children | 8d7bf729a4db |
files | hglib/client.py hglib/util.py tests/test-import.py |
diffstat | 3 files changed, 10 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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 = {}
--- 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):
--- 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):