This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit 4c1b4805 authored by Manuel Jacob's avatar Manuel Jacob
Browse files

pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*

On Python 3, pycompat.{stdin,stdout,stderr} are usually block-buffered even if
connected to a TTY. procutil.{stdin,stdout,stderr} provide consistent behavior
across platforms and Python versions.
parent 922dbf0df4f1
......@@ -28,7 +28,7 @@
def printb(data, end=b'\n'):
sys.stdout.flush()
pycompat.stdout.write(data + end)
procutil.stdout.write(data + end)
for f in sys.argv[1:]:
......
......@@ -45,8 +45,8 @@
def showhelp():
pycompat.stdout.write(usage)
pycompat.stdout.write(b'\noptions:\n')
procutil.stdout.write(usage)
procutil.stdout.write(b'\noptions:\n')
out_opts = []
for shortopt, longopt, default, desc in options:
......@@ -62,7 +62,7 @@
)
opts_len = max([len(opt[0]) for opt in out_opts])
for first, second in out_opts:
pycompat.stdout.write(b' %-*s %s\n' % (opts_len, first, second))
procutil.stdout.write(b' %-*s %s\n' % (opts_len, first, second))
try:
......@@ -66,7 +66,7 @@
try:
for fp in (sys.stdin, pycompat.stdout, sys.stderr):
for fp in (sys.stdin, procutil.stdout, sys.stderr):
procutil.setbinary(fp)
opts = {}
......@@ -92,7 +92,7 @@
)
except ParseError as e:
e = stringutil.forcebytestr(e)
pycompat.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e))
procutil.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e))
showhelp()
sys.exit(1)
except error.Abort as e:
......@@ -96,7 +96,7 @@
showhelp()
sys.exit(1)
except error.Abort as e:
pycompat.stderr.write(b"abort: %s\n" % e)
procutil.stderr.write(b"abort: %s\n" % e)
sys.exit(255)
except KeyboardInterrupt:
sys.exit(255)
......@@ -9,7 +9,6 @@
from mercurial import (
encoding,
node,
pycompat,
revlog,
transaction,
vfs as vfsmod,
......@@ -30,7 +29,7 @@
if l.startswith("file:"):
f = encoding.strtolocal(l[6:-1])
r = revlog.revlog(opener, f)
pycompat.stdout.write(b'%s\n' % f)
procutil.stdout.write(b'%s\n' % f)
elif l.startswith("node:"):
n = node.bin(l[6:-1])
elif l.startswith("linkrev:"):
......
......@@ -30,7 +30,10 @@
scmutil,
util,
)
from mercurial.utils import stringutil
from mercurial.utils import (
procutil,
stringutil,
)
cmdtable = {}
command = registrar.command(cmdtable)
......@@ -689,7 +692,7 @@
def debugparsereleasenotes(ui, path, repo=None):
"""parse release notes and print resulting data structure"""
if path == b'-':
text = pycompat.stdin.read()
text = procutil.stdin.read()
else:
with open(path, b'rb') as fh:
text = fh.read()
......
......@@ -22,5 +22,4 @@
> from mercurial import changegroup
> from mercurial import error
> from mercurial import obsolete
> from mercurial import pycompat
> from mercurial import registrar
......@@ -26,4 +25,5 @@
> from mercurial import registrar
> from mercurial.utils import procutil
>
>
> try:
......@@ -148,7 +148,7 @@
> bundler.newpart(b'output', data=genraise(), mandatory=False)
>
> if path is None:
> file = pycompat.stdout
> file = procutil.stdout
> else:
> file = open(path, 'wb')
>
......@@ -181,7 +181,7 @@
> lock = repo.lock()
> tr = repo.transaction(b'processbundle')
> try:
> unbundler = bundle2.getunbundler(ui, pycompat.stdin)
> unbundler = bundle2.getunbundler(ui, procutil.stdin)
> op = bundle2.processbundle(repo, unbundler, lambda: tr)
> tr.close()
> except error.BundleValueError as exc:
......@@ -192,7 +192,7 @@
> if tr is not None:
> tr.release()
> lock.release()
> remains = pycompat.stdin.read()
> remains = procutil.stdin.read()
> ui.write(b'%i unread bytes\n' % len(remains))
> if op.records[b'song']:
> totalverses = sum(r[b'verses'] for r in op.records[b'song'])
......@@ -207,7 +207,7 @@
> @command(b'statbundle2', [], b'')
> def cmdstatbundle2(ui, repo):
> """print statistic on the bundle2 container read from stdin"""
> unbundler = bundle2.getunbundler(ui, pycompat.stdin)
> unbundler = bundle2.getunbundler(ui, procutil.stdin)
> try:
> params = unbundler.params
> except error.BundleValueError as exc:
......
......@@ -573,6 +573,5 @@
$ cat > debugstacktrace.py << EOF
> from __future__ import absolute_import
> from mercurial import (
> pycompat,
> util,
> )
......@@ -577,3 +576,6 @@
> util,
> )
> from mercurial.utils import (
> procutil,
> )
> def f():
......@@ -579,5 +581,5 @@
> def f():
> util.debugstacktrace(f=pycompat.stdout)
> util.debugstacktrace(f=procutil.stdout)
> g()
> def g():
> util.dst(b'hello from g\\n', skip=1)
......@@ -588,6 +590,6 @@
> EOF
$ "$PYTHON" debugstacktrace.py
stacktrace at:
*debugstacktrace.py:14 in * (glob)
*debugstacktrace.py:7 in f (glob)
*debugstacktrace.py:16 in * (glob)
*debugstacktrace.py:9 in f (glob)
hello from g at:
......@@ -593,5 +595,5 @@
hello from g at:
*debugstacktrace.py:14 in * (glob)
*debugstacktrace.py:8 in f (glob)
*debugstacktrace.py:16 in * (glob)
*debugstacktrace.py:10 in f (glob)
hi ...
from h hidden in g at:
......@@ -596,7 +598,7 @@
hi ...
from h hidden in g at:
*debugstacktrace.py:8 in f (glob)
*debugstacktrace.py:11 in g (glob)
*debugstacktrace.py:10 in f (glob)
*debugstacktrace.py:13 in g (glob)
Test debugcapabilities command:
......
......@@ -1917,5 +1917,5 @@
> EOF
$ "$PYTHON" <<EOF | sh
> from mercurial import pycompat
> from mercurial.utils import procutil
> upper = b"\x8bL\x98^"
......@@ -1921,5 +1921,5 @@
> upper = b"\x8bL\x98^"
> pycompat.stdout.write(b"hg --encoding cp932 help -e ambiguous.%s\n" % upper)
> procutil.stdout.write(b"hg --encoding cp932 help -e ambiguous.%s\n" % upper)
> EOF
\x8bL\x98^ (esc)
----
......@@ -1928,5 +1928,5 @@
$ "$PYTHON" <<EOF | sh
> from mercurial import pycompat
> from mercurial.utils import procutil
> lower = b"\x8bl\x98^"
......@@ -1932,5 +1932,5 @@
> lower = b"\x8bl\x98^"
> pycompat.stdout.write(b"hg --encoding cp932 help -e ambiguous.%s\n" % lower)
> procutil.stdout.write(b"hg --encoding cp932 help -e ambiguous.%s\n" % lower)
> EOF
\x8bl\x98^ (esc)
----
......
......@@ -14,7 +14,6 @@
> dispatch,
> encoding,
> hg,
> pycompat,
> ui as uimod,
> util,
> )
......@@ -18,6 +17,9 @@
> ui as uimod,
> util,
> )
> from mercurial.utils import (
> procutil,
> )
> ui = uimod.ui
> from mercurial.hgweb import hgweb_mod
> stringio = util.stringio
......@@ -69,8 +71,8 @@
> for c in i(env, startrsp):
> pass
> sys.stdout.flush()
> pycompat.stdout.write(b'---- ERRORS\n')
> pycompat.stdout.write(b'%s\n' % errors.getvalue())
> procutil.stdout.write(b'---- ERRORS\n')
> procutil.stdout.write(b'%s\n' % errors.getvalue())
> print('---- OS.ENVIRON wsgi variables')
> print(sorted([x for x in os.environ if x.startswith('wsgi')]))
> print('---- request.ENVIRON wsgi variables')
......
......@@ -19,9 +19,8 @@
> EOF
$ cat > cat.py <<EOF
> import sys
> from mercurial import pycompat
> from mercurial.utils import stringutil
> pycompat.stdout.write(b'%s\n'
> from mercurial.utils import procutil, stringutil
> procutil.stdout.write(b'%s\n'
> % stringutil.pprint(open(sys.argv[1], 'rb').read()))
> EOF
......
......@@ -697,6 +697,7 @@
> revlog,
> )
> from mercurial.utils import (
> procutil,
> stringutil,
> )
> def hash(rawtext):
......@@ -713,7 +714,7 @@
> texts = [fl.rawdata(i) for i in fl]
> flags = [int(fl._revlog.flags(i)) for i in fl]
> hashes = [hash(t) for t in texts]
> pycompat.stdout.write(b' %s: rawsizes=%r flags=%r hashes=%s\n'
> procutil.stdout.write(b' %s: rawsizes=%r flags=%r hashes=%s\n'
> % (name, sizes, flags, stringutil.pprint(hashes)))
> EOF
......
......@@ -1575,7 +1575,6 @@
> from __future__ import absolute_import
> from mercurial import (
> dispatch,
> pycompat,
> )
> from mercurial.utils import (
> cborutil,
......@@ -1579,6 +1578,7 @@
> )
> from mercurial.utils import (
> cborutil,
> procutil,
> stringutil,
> )
> dispatch.initstdio()
......@@ -1582,8 +1582,8 @@
> stringutil,
> )
> dispatch.initstdio()
> items = cborutil.decodeall(pycompat.stdin.read())
> pycompat.stdout.write(stringutil.pprint(items, indent=1) + b'\n')
> items = cborutil.decodeall(procutil.stdin.read())
> procutil.stdout.write(stringutil.pprint(items, indent=1) + b'\n')
> EOF
$ hg log -T "{rev|cbor}" -R a -l2 | "$PYTHON" "$TESTTMP/decodecbor.py"
......
......@@ -675,7 +675,6 @@
> from __future__ import absolute_import
> from mercurial import (
> dispatch,
> pycompat,
> )
> from mercurial.utils import (
> cborutil,
......@@ -679,6 +678,7 @@
> )
> from mercurial.utils import (
> cborutil,
> procutil,
> stringutil,
> )
> dispatch.initstdio()
......@@ -682,9 +682,9 @@
> stringutil,
> )
> dispatch.initstdio()
> data = pycompat.stdin.read()
> data = procutil.stdin.read()
> # our CBOR decoder doesn't support parsing indefinite-length arrays,
> # but the log output is indefinite stream by nature.
> assert data[:1] == cborutil.BEGIN_INDEFINITE_ARRAY
> assert data[-1:] == cborutil.BREAK
> items = cborutil.decodeall(data[1:-1])
......@@ -686,9 +686,9 @@
> # our CBOR decoder doesn't support parsing indefinite-length arrays,
> # but the log output is indefinite stream by nature.
> assert data[:1] == cborutil.BEGIN_INDEFINITE_ARRAY
> assert data[-1:] == cborutil.BREAK
> items = cborutil.decodeall(data[1:-1])
> pycompat.stdout.write(stringutil.pprint(items, indent=1) + b'\n')
> procutil.stdout.write(stringutil.pprint(items, indent=1) + b'\n')
> EOF
$ hg log -k nosuch -Tcbor | "$PYTHON" "$TESTTMP/decodecborarray.py"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment