Show More
@@ -50,6 +50,7 b' from mercurial import (' | |||||
50 | patch, |
|
50 | patch, | |
51 | registrar, |
|
51 | registrar, | |
52 | scmutil, |
|
52 | scmutil, | |
|
53 | util, | |||
53 | ) |
|
54 | ) | |
54 |
|
55 | |||
55 | cmdtable = {} |
|
56 | cmdtable = {} | |
@@ -96,7 +97,7 b' def difftree(ui, repo, node1=None, node2' | |||||
96 | while True: |
|
97 | while True: | |
97 | if opts['stdin']: |
|
98 | if opts['stdin']: | |
98 | try: |
|
99 | try: | |
99 |
line = |
|
100 | line = util.bytesinput(ui.fin, ui.fout).split(' ') | |
100 | node1 = line[0] |
|
101 | node1 = line[0] | |
101 | if len(line) > 1: |
|
102 | if len(line) > 1: | |
102 | node2 = line[1] |
|
103 | node2 = line[1] | |
@@ -177,7 +178,7 b' def catfile(ui, repo, type=None, r=None,' | |||||
177 | prefix = "" |
|
178 | prefix = "" | |
178 | if opts['stdin']: |
|
179 | if opts['stdin']: | |
179 | try: |
|
180 | try: | |
180 |
(type, r) = |
|
181 | (type, r) = util.bytesinput(ui.fin, ui.fout).split(' ') | |
181 | prefix = " " |
|
182 | prefix = " " | |
182 | except EOFError: |
|
183 | except EOFError: | |
183 | return |
|
184 | return | |
@@ -195,7 +196,7 b' def catfile(ui, repo, type=None, r=None,' | |||||
195 | catcommit(ui, repo, n, prefix) |
|
196 | catcommit(ui, repo, n, prefix) | |
196 | if opts['stdin']: |
|
197 | if opts['stdin']: | |
197 | try: |
|
198 | try: | |
198 |
(type, r) = |
|
199 | (type, r) = util.bytesinput(ui.fin, ui.fout).split(' ') | |
199 | except EOFError: |
|
200 | except EOFError: | |
200 | break |
|
201 | break | |
201 | else: |
|
202 | else: |
@@ -8,6 +8,7 b'' | |||||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import array |
|
10 | import array | |
|
11 | import io | |||
11 | import locale |
|
12 | import locale | |
12 | import os |
|
13 | import os | |
13 | import unicodedata |
|
14 | import unicodedata | |
@@ -573,3 +574,16 b' def fromutf8b(s):' | |||||
573 | c = chr(ord(c.decode("utf-8")) & 0xff) |
|
574 | c = chr(ord(c.decode("utf-8")) & 0xff) | |
574 | r += c |
|
575 | r += c | |
575 | return r |
|
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 | self.write(prompt, prompt=True) |
|
1217 | self.write(prompt, prompt=True) | |
1218 | self.flush() |
|
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 | # prompt ' ' must exist; otherwise readline may delete entire line |
|
1220 | # prompt ' ' must exist; otherwise readline may delete entire line | |
1227 | # - http://bugs.python.org/issue12833 |
|
1221 | # - http://bugs.python.org/issue12833 | |
1228 | with self.timeblockedsection('stdio'): |
|
1222 | with self.timeblockedsection('stdio'): | |
1229 |
line = |
|
1223 | line = util.bytesinput(self.fin, self.fout, r' ') | |
1230 | sys.stdin = oldin |
|
|||
1231 | sys.stdout = oldout |
|
|||
1232 |
|
1224 | |||
1233 | # When stdin is in binary mode on Windows, it can cause |
|
1225 | # When stdin is in binary mode on Windows, it can cause | |
1234 | # raw_input() to emit an extra trailing carriage return |
|
1226 | # raw_input() to emit an extra trailing carriage return |
@@ -172,6 +172,18 b' os.stat_float_times(False)' | |||||
172 | def safehasattr(thing, attr): |
|
172 | def safehasattr(thing, attr): | |
173 | return getattr(thing, attr, _notset) is not _notset |
|
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 | def bitsfrom(container): |
|
187 | def bitsfrom(container): | |
176 | bits = 0 |
|
188 | bits = 0 | |
177 | for bit in container: |
|
189 | for bit in container: |
General Comments 0
You need to be logged in to leave comments.
Login now