Show More
@@ -50,6 +50,7 b' from mercurial import (' | |||
|
50 | 50 | patch, |
|
51 | 51 | registrar, |
|
52 | 52 | scmutil, |
|
53 | util, | |
|
53 | 54 | ) |
|
54 | 55 | |
|
55 | 56 | cmdtable = {} |
@@ -96,7 +97,7 b' def difftree(ui, repo, node1=None, node2' | |||
|
96 | 97 | while True: |
|
97 | 98 | if opts['stdin']: |
|
98 | 99 | try: |
|
99 |
line = |
|
|
100 | line = util.bytesinput(ui.fin, ui.fout).split(' ') | |
|
100 | 101 | node1 = line[0] |
|
101 | 102 | if len(line) > 1: |
|
102 | 103 | node2 = line[1] |
@@ -177,7 +178,7 b' def catfile(ui, repo, type=None, r=None,' | |||
|
177 | 178 | prefix = "" |
|
178 | 179 | if opts['stdin']: |
|
179 | 180 | try: |
|
180 |
(type, r) = |
|
|
181 | (type, r) = util.bytesinput(ui.fin, ui.fout).split(' ') | |
|
181 | 182 | prefix = " " |
|
182 | 183 | except EOFError: |
|
183 | 184 | return |
@@ -195,7 +196,7 b' def catfile(ui, repo, type=None, r=None,' | |||
|
195 | 196 | catcommit(ui, repo, n, prefix) |
|
196 | 197 | if opts['stdin']: |
|
197 | 198 | try: |
|
198 |
(type, r) = |
|
|
199 | (type, r) = util.bytesinput(ui.fin, ui.fout).split(' ') | |
|
199 | 200 | except EOFError: |
|
200 | 201 | break |
|
201 | 202 | else: |
@@ -8,6 +8,7 b'' | |||
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import array |
|
11 | import io | |
|
11 | 12 | import locale |
|
12 | 13 | import os |
|
13 | 14 | import unicodedata |
@@ -573,3 +574,16 b' def fromutf8b(s):' | |||
|
573 | 574 | c = chr(ord(c.decode("utf-8")) & 0xff) |
|
574 | 575 | r += c |
|
575 | 576 | return r |
|
577 | ||
|
578 | class strio(io.TextIOWrapper): | |
|
579 | """Wrapper around TextIOWrapper that respects hg's encoding assumptions. | |
|
580 | ||
|
581 | Also works around Python closing streams. | |
|
582 | """ | |
|
583 | ||
|
584 | def __init__(self, buffer, **kwargs): | |
|
585 | kwargs[r'encoding'] = _sysstr(encoding) | |
|
586 | super(strio, self).__init__(buffer, **kwargs) | |
|
587 | ||
|
588 | def __del__(self): | |
|
589 | """Override __del__ so it doesn't close the underlying stream.""" |
@@ -1217,18 +1217,10 b' class ui(object):' | |||
|
1217 | 1217 | self.write(prompt, prompt=True) |
|
1218 | 1218 | self.flush() |
|
1219 | 1219 | |
|
1220 | # instead of trying to emulate raw_input, swap (self.fin, | |
|
1221 | # self.fout) with (sys.stdin, sys.stdout) | |
|
1222 | oldin = sys.stdin | |
|
1223 | oldout = sys.stdout | |
|
1224 | sys.stdin = self.fin | |
|
1225 | sys.stdout = self.fout | |
|
1226 | 1220 | # prompt ' ' must exist; otherwise readline may delete entire line |
|
1227 | 1221 | # - http://bugs.python.org/issue12833 |
|
1228 | 1222 | with self.timeblockedsection('stdio'): |
|
1229 |
line = |
|
|
1230 | sys.stdin = oldin | |
|
1231 | sys.stdout = oldout | |
|
1223 | line = util.bytesinput(self.fin, self.fout, r' ') | |
|
1232 | 1224 | |
|
1233 | 1225 | # When stdin is in binary mode on Windows, it can cause |
|
1234 | 1226 | # raw_input() to emit an extra trailing carriage return |
@@ -172,6 +172,18 b' os.stat_float_times(False)' | |||
|
172 | 172 | def safehasattr(thing, attr): |
|
173 | 173 | return getattr(thing, attr, _notset) is not _notset |
|
174 | 174 | |
|
175 | def bytesinput(fin, fout, *args, **kwargs): | |
|
176 | sin, sout = sys.stdin, sys.stdout | |
|
177 | try: | |
|
178 | if pycompat.ispy3: | |
|
179 | sys.stdin, sys.stdout = encoding.strio(fin), encoding.strio(fout) | |
|
180 | return encoding.strtolocal(input(*args, **kwargs)) | |
|
181 | else: | |
|
182 | sys.stdin, sys.stdout = fin, fout | |
|
183 | return raw_input(*args, **kwargs) | |
|
184 | finally: | |
|
185 | sys.stdin, sys.stdout = sin, sout | |
|
186 | ||
|
175 | 187 | def bitsfrom(container): |
|
176 | 188 | bits = 0 |
|
177 | 189 | for bit in container: |
General Comments 0
You need to be logged in to leave comments.
Login now