Mercurial > public > mercurial-scm > python-hglib
diff hglib/util.py @ 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 | fe74d5599539 |
children | 8d7bf729a4db |
line wrap: on
line diff
--- 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):