##// END OF EJS Templates
py3: use io.BytesIO directly...
Gregory Szorc -
r49728:5aafc3c5 default
parent child Browse files
Show More
@@ -62,6 +62,7 b' from __future__ import absolute_import'
62 import base64
62 import base64
63 import contextlib
63 import contextlib
64 import hashlib
64 import hashlib
65 import io
65 import itertools
66 import itertools
66 import json
67 import json
67 import mimetypes
68 import mimetypes
@@ -2200,7 +2201,7 b' def phabimport(ui, repo, *specs, **opts)'
2200 for drev, contents in patches:
2201 for drev, contents in patches:
2201 ui.status(_(b'applying patch from D%s\n') % drev)
2202 ui.status(_(b'applying patch from D%s\n') % drev)
2202
2203
2203 with patch.extract(ui, pycompat.bytesio(contents)) as patchdata:
2204 with patch.extract(ui, io.BytesIO(contents)) as patchdata:
2204 msg, node, rej = cmdutil.tryimportone(
2205 msg, node, rej = cmdutil.tryimportone(
2205 ui,
2206 ui,
2206 repo,
2207 repo,
@@ -7,11 +7,11 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import io
10 import struct
11 import struct
11
12
12 from .. import pycompat
13
13
14 stringio = pycompat.bytesio
14 stringio = io.BytesIO
15
15
16
16
17 class mpatchError(Exception):
17 class mpatchError(Exception):
@@ -7,6 +7,7 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import io
10 import stat
11 import stat
11 import struct
12 import struct
12 import zlib
13 import zlib
@@ -26,7 +27,7 b' from .. import ('
26 from ..revlogutils import nodemap as nodemaputil
27 from ..revlogutils import nodemap as nodemaputil
27 from ..revlogutils import constants as revlog_constants
28 from ..revlogutils import constants as revlog_constants
28
29
29 stringio = pycompat.bytesio
30 stringio = io.BytesIO
30
31
31
32
32 _pack = struct.pack
33 _pack = struct.pack
@@ -111,9 +111,6 b" sysplatform = sys.platform.encode('ascii"
111 sysexecutable = sys.executable
111 sysexecutable = sys.executable
112 if sysexecutable:
112 if sysexecutable:
113 sysexecutable = os.fsencode(sysexecutable)
113 sysexecutable = os.fsencode(sysexecutable)
114 bytesio = io.BytesIO
115 # TODO deprecate stringio name, as it is a lie on Python 3.
116 stringio = bytesio
117
114
118
115
119 def maplist(*args):
116 def maplist(*args):
@@ -21,6 +21,7 b' import contextlib'
21 import errno
21 import errno
22 import gc
22 import gc
23 import hashlib
23 import hashlib
24 import io
24 import itertools
25 import itertools
25 import locale
26 import locale
26 import mmap
27 import mmap
@@ -78,7 +79,7 b' cookielib = pycompat.cookielib'
78 httplib = pycompat.httplib
79 httplib = pycompat.httplib
79 safehasattr = pycompat.safehasattr
80 safehasattr = pycompat.safehasattr
80 socketserver = pycompat.socketserver
81 socketserver = pycompat.socketserver
81 bytesio = pycompat.bytesio
82 bytesio = io.BytesIO
82 # TODO deprecate stringio name, as it is a lie on Python 3.
83 # TODO deprecate stringio name, as it is a lie on Python 3.
83 stringio = bytesio
84 stringio = bytesio
84 xmlrpclib = pycompat.xmlrpclib
85 xmlrpclib = pycompat.xmlrpclib
@@ -240,15 +240,16 b' Invalid ui.message-output option:'
240 Underlying message streams should be updated when ui.fout/ferr are set:
240 Underlying message streams should be updated when ui.fout/ferr are set:
241
241
242 $ cat <<'EOF' > capui.py
242 $ cat <<'EOF' > capui.py
243 > from mercurial import pycompat, registrar
243 > import io
244 > from mercurial import registrar
244 > cmdtable = {}
245 > cmdtable = {}
245 > command = registrar.command(cmdtable)
246 > command = registrar.command(cmdtable)
246 > @command(b'capui', norepo=True)
247 > @command(b'capui', norepo=True)
247 > def capui(ui):
248 > def capui(ui):
248 > out = ui.fout
249 > out = ui.fout
249 > ui.fout = pycompat.bytesio()
250 > ui.fout = io.BytesIO()
250 > ui.status(b'status\n')
251 > ui.status(b'status\n')
251 > ui.ferr = pycompat.bytesio()
252 > ui.ferr = io.BytesIO()
252 > ui.warn(b'warn\n')
253 > ui.warn(b'warn\n')
253 > out.write(b'stdout: %s' % ui.fout.getvalue())
254 > out.write(b'stdout: %s' % ui.fout.getvalue())
254 > out.write(b'stderr: %s' % ui.ferr.getvalue())
255 > out.write(b'stderr: %s' % ui.ferr.getvalue())
@@ -2,6 +2,7 b''
2 from __future__ import absolute_import
2 from __future__ import absolute_import
3
3
4 import contextlib
4 import contextlib
5 import io
5 import itertools
6 import itertools
6 import unittest
7 import unittest
7
8
@@ -55,7 +56,7 b' def mocktimer(incr=0.1, *additional_targ'
55
56
56 @contextlib.contextmanager
57 @contextlib.contextmanager
57 def capturestderr():
58 def capturestderr():
58 """Replace utils.procutil.stderr with a pycompat.bytesio instance
59 """Replace utils.procutil.stderr with an io.BytesIO instance
59
60
60 The instance is made available as the return value of __enter__.
61 The instance is made available as the return value of __enter__.
61
62
@@ -63,7 +64,7 b' def capturestderr():'
63
64
64 """
65 """
65 orig = utils.procutil.stderr
66 orig = utils.procutil.stderr
66 utils.procutil.stderr = pycompat.bytesio()
67 utils.procutil.stderr = io.BytesIO()
67 try:
68 try:
68 yield utils.procutil.stderr
69 yield utils.procutil.stderr
69 finally:
70 finally:
General Comments 0
You need to be logged in to leave comments. Login now