##// END OF EJS Templates
py3: make encoding.strio() an identity function on Python 2...
Yuya Nishihara -
r33852:f18b1153 default
parent child Browse files
Show More
@@ -575,15 +575,17 b' def fromutf8b(s):'
575 r += c
575 r += c
576 return r
576 return r
577
577
578 class strio(io.TextIOWrapper):
578 if pycompat.ispy3:
579 """Wrapper around TextIOWrapper that respects hg's encoding assumptions.
579 class strio(io.TextIOWrapper):
580 """Wrapper around TextIOWrapper that respects hg's encoding assumptions.
580
581
581 Also works around Python closing streams.
582 Also works around Python closing streams.
582 """
583 """
583
584
584 def __init__(self, buffer, **kwargs):
585 def __init__(self, buffer):
585 kwargs[r'encoding'] = _sysstr(encoding)
586 super(strio, self).__init__(buffer, encoding=_sysstr(encoding))
586 super(strio, self).__init__(buffer, **kwargs)
587
587
588 def __del__(self):
588 def __del__(self):
589 """Override __del__ so it doesn't close the underlying stream."""
589 """Override __del__ so it doesn't close the underlying stream."""
590 else:
591 strio = pycompat.identity
@@ -175,11 +175,10 b' def safehasattr(thing, attr):'
175 def bytesinput(fin, fout, *args, **kwargs):
175 def bytesinput(fin, fout, *args, **kwargs):
176 sin, sout = sys.stdin, sys.stdout
176 sin, sout = sys.stdin, sys.stdout
177 try:
177 try:
178 sys.stdin, sys.stdout = encoding.strio(fin), encoding.strio(fout)
178 if pycompat.ispy3:
179 if pycompat.ispy3:
179 sys.stdin, sys.stdout = encoding.strio(fin), encoding.strio(fout)
180 return encoding.strtolocal(input(*args, **kwargs))
180 return encoding.strtolocal(input(*args, **kwargs))
181 else:
181 else:
182 sys.stdin, sys.stdout = fin, fout
183 return raw_input(*args, **kwargs)
182 return raw_input(*args, **kwargs)
184 finally:
183 finally:
185 sys.stdin, sys.stdout = sin, sout
184 sys.stdin, sys.stdout = sin, sout
General Comments 0
You need to be logged in to leave comments. Login now