# HG changeset patch # User Yuya Nishihara # Date 2017-08-16 04:50:11 # Node ID f18b11534274be15d64209a9e5dd972217262915 # Parent 7827fbbd0b0684b1e47f5fd4eab4dadf13a634df py3: make encoding.strio() an identity function on Python 2 It's the convention the other encoding.str*() functions follow. To make things simple, this also drops kwargs from the strio() constructor. diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -575,15 +575,17 @@ def fromutf8b(s): r += c return r -class strio(io.TextIOWrapper): - """Wrapper around TextIOWrapper that respects hg's encoding assumptions. +if pycompat.ispy3: + class strio(io.TextIOWrapper): + """Wrapper around TextIOWrapper that respects hg's encoding assumptions. - Also works around Python closing streams. - """ + Also works around Python closing streams. + """ - def __init__(self, buffer, **kwargs): - kwargs[r'encoding'] = _sysstr(encoding) - super(strio, self).__init__(buffer, **kwargs) + def __init__(self, buffer): + super(strio, self).__init__(buffer, encoding=_sysstr(encoding)) - def __del__(self): - """Override __del__ so it doesn't close the underlying stream.""" + def __del__(self): + """Override __del__ so it doesn't close the underlying stream.""" +else: + strio = pycompat.identity diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -175,11 +175,10 @@ def safehasattr(thing, attr): def bytesinput(fin, fout, *args, **kwargs): sin, sout = sys.stdin, sys.stdout try: + sys.stdin, sys.stdout = encoding.strio(fin), encoding.strio(fout) if pycompat.ispy3: - sys.stdin, sys.stdout = encoding.strio(fin), encoding.strio(fout) return encoding.strtolocal(input(*args, **kwargs)) else: - sys.stdin, sys.stdout = fin, fout return raw_input(*args, **kwargs) finally: sys.stdin, sys.stdout = sin, sout