Mercurial > hg-stable
changeset 33873:f18b11534274
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 16 Aug 2017 13:50:11 +0900 |
parents | 7827fbbd0b06 |
children | cfcfbe6c96f8 |
files | mercurial/encoding.py mercurial/util.py |
diffstat | 2 files changed, 12 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/encoding.py Sun Aug 13 14:12:28 2017 +0900 +++ b/mercurial/encoding.py Wed Aug 16 13:50:11 2017 +0900 @@ -575,15 +575,17 @@ 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
--- a/mercurial/util.py Sun Aug 13 14:12:28 2017 +0900 +++ b/mercurial/util.py Wed Aug 16 13:50:11 2017 +0900 @@ -175,11 +175,10 @@ 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