##// END OF EJS Templates
pythonw in py3k sets std{in,out,err} to None...
Brandon Parsons -
Show More
@@ -53,7 +53,8 b' def split_user_input(line, pattern=None):'
53 and the rest.
53 and the rest.
54 """
54 """
55 # We need to ensure that the rest of this routine deals only with unicode
55 # We need to ensure that the rest of this routine deals only with unicode
56 line = py3compat.cast_unicode(line, sys.stdin.encoding or 'utf-8')
56 encoding = py3compat.get_stream_enc(sys.stdin, 'utf-8')
57 line = py3compat.cast_unicode(line, encoding)
57
58
58 if pattern is None:
59 if pattern is None:
59 pattern = line_split
60 pattern = line_split
@@ -319,7 +319,7 b' class TerminalInteractiveShell(InteractiveShell):'
319
319
320 for i in range(hlen - hlen_before_cell):
320 for i in range(hlen - hlen_before_cell):
321 self.readline.remove_history_item(hlen - i - 1)
321 self.readline.remove_history_item(hlen - i - 1)
322 stdin_encoding = sys.stdin.encoding or "utf-8"
322 stdin_encoding = py3compat.get_stream_enc(sys.stdin, 'utf-8')
323 self.readline.add_history(py3compat.unicode_to_str(source_raw.rstrip(),
323 self.readline.add_history(py3compat.unicode_to_str(source_raw.rstrip(),
324 stdin_encoding))
324 stdin_encoding))
325 return self.readline.get_current_history_length()
325 return self.readline.get_current_history_length()
@@ -87,9 +87,9 b' class IOTerm:'
87 self.stderr = IOStream(stderr, sys.stderr)
87 self.stderr = IOStream(stderr, sys.stderr)
88
88
89 # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr
89 # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr
90 stdin = IOStream(sys.stdin)
90 stdin = sys.stdin if not sys.stdin else IOStream(sys.stdin)
91 stdout = IOStream(sys.stdout)
91 stdout = sys.stdout if not sys.stdout else IOStream(sys.stdout)
92 stderr = IOStream(sys.stderr)
92 stderr = sys.stderr if not sys.stderr else IOStream(sys.stderr)
93
93
94
94
95 class Tee(object):
95 class Tee(object):
@@ -11,14 +11,22 b' orig_open = open'
11 def no_code(x, encoding=None):
11 def no_code(x, encoding=None):
12 return x
12 return x
13
13
14 # to deal with the possibility of sys.std* not being a stream at all
15 def get_stream_enc(stream, default=None):
16 if not hasattr(stream, 'encoding') or not stream.encoding:
17 return default
18 else:
19 return stream.encoding
20
14 def decode(s, encoding=None):
21 def decode(s, encoding=None):
15 encoding = encoding or sys.stdin.encoding or sys.getdefaultencoding()
22 encoding = get_stream_enc(sys.stdin, encoding) or sys.getdefaultencoding()
16 return s.decode(encoding, "replace")
23 return s.decode(encoding, "replace")
17
24
18 def encode(u, encoding=None):
25 def encode(u, encoding=None):
19 encoding = encoding or sys.stdin.encoding or sys.getdefaultencoding()
26 encoding = get_stream_enc(sys.stdin, encoding) or sys.getdefaultencoding()
20 return u.encode(encoding, "replace")
27 return u.encode(encoding, "replace")
21
28
29
22 def cast_unicode(s, encoding=None):
30 def cast_unicode(s, encoding=None):
23 if isinstance(s, bytes):
31 if isinstance(s, bytes):
24 return decode(s, encoding)
32 return decode(s, encoding)
@@ -47,7 +47,7 b' def getdefaultencoding():'
47 and finally to sys.getdefaultencoding() which is the most conservative option,
47 and finally to sys.getdefaultencoding() which is the most conservative option,
48 and usually ASCII.
48 and usually ASCII.
49 """
49 """
50 enc = sys.stdin.encoding
50 enc = py3compat.get_stream_enc(sys.stdin)
51 if not enc or enc=='ascii':
51 if not enc or enc=='ascii':
52 try:
52 try:
53 # There are reports of getpreferredencoding raising errors
53 # There are reports of getpreferredencoding raising errors
General Comments 0
You need to be logged in to leave comments. Login now