Mercurial > public > mercurial-scm > hg
comparison mercurial/pycompat.py @ 36958:644a02f6b34f
util: prefer "bytesio" to "stringio"
The io.BytesIO and io.StringIO types enforce the type of
data being operated on. On Python 2, we use cStringIO.StringIO(),
which is lax about mixing types. On Python 3, we actually use
io.BytesIO. Ideally, we'd use io.BytesIO on Python 2. But I believe
its performance is poor compared to cString.StringIO().
Anyway, we canonically define our pycompat type as "stringio."
That name is misleading, especially on Python 3.
This commit renames the canonical symbols to "bytesio."
"stringio" is preserved as an alias for API compatibility. There
are a lot of callers in the repo and I hesitate to take away the
old name. I also don't feel like changing everything at this time.
But at least new callers can use a "proper" name.
Differential Revision: https://phab.mercurial-scm.org/D2868
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 14 Mar 2018 11:52:35 -0700 |
parents | dbae581010ea |
children | 434e520adb8c |
comparison
equal
deleted
inserted
replaced
36957:a8d540d2628c | 36958:644a02f6b34f |
---|---|
62 getcwd = os.getcwdb | 62 getcwd = os.getcwdb |
63 sysplatform = sys.platform.encode('ascii') | 63 sysplatform = sys.platform.encode('ascii') |
64 sysexecutable = sys.executable | 64 sysexecutable = sys.executable |
65 if sysexecutable: | 65 if sysexecutable: |
66 sysexecutable = os.fsencode(sysexecutable) | 66 sysexecutable = os.fsencode(sysexecutable) |
67 stringio = io.BytesIO | 67 bytesio = io.BytesIO |
68 # TODO deprecate stringio name, as it is a lie on Python 3. | |
69 stringio = bytesio | |
68 | 70 |
69 def maplist(*args): | 71 def maplist(*args): |
70 return list(map(*args)) | 72 return list(map(*args)) |
71 | 73 |
72 def ziplist(*args): | 74 def ziplist(*args): |
341 sysargv = sys.argv | 343 sysargv = sys.argv |
342 sysplatform = sys.platform | 344 sysplatform = sys.platform |
343 getcwd = os.getcwd | 345 getcwd = os.getcwd |
344 sysexecutable = sys.executable | 346 sysexecutable = sys.executable |
345 shlexsplit = shlex.split | 347 shlexsplit = shlex.split |
346 stringio = cStringIO.StringIO | 348 bytesio = cStringIO.StringIO |
349 stringio = bytesio | |
347 maplist = map | 350 maplist = map |
348 ziplist = zip | 351 ziplist = zip |
349 rawinput = raw_input | 352 rawinput = raw_input |
350 getargspec = inspect.getargspec | 353 getargspec = inspect.getargspec |
351 | 354 |