##// END OF EJS Templates
Unicode fixes, basic input/printing of unicode works.
Fernando Perez -
Show More
@@ -2265,13 +2265,17 b' class InteractiveShell(Configurable, Magic):'
2265 The return value can be used to decide whether to use sys.ps1 or
2265 The return value can be used to decide whether to use sys.ps1 or
2266 sys.ps2 to prompt the next line."""
2266 sys.ps2 to prompt the next line."""
2267
2267
2268 # We need to ensure that the source is unicode from here on.
2269 if type(source)==str:
2270 source = source.decode(self.stdin_encoding)
2271
2268 # if the source code has leading blanks, add 'if 1:\n' to it
2272 # if the source code has leading blanks, add 'if 1:\n' to it
2269 # this allows execution of indented pasted code. It is tempting
2273 # this allows execution of indented pasted code. It is tempting
2270 # to add '\n' at the end of source to run commands like ' a=1'
2274 # to add '\n' at the end of source to run commands like ' a=1'
2271 # directly, but this fails for more complicated scenarios
2275 # directly, but this fails for more complicated scenarios
2272 source=source.encode(self.stdin_encoding)
2276
2273 if source[:1] in [' ', '\t']:
2277 if source[:1] in [' ', '\t']:
2274 source = 'if 1:\n%s' % source
2278 source = u'if 1:\n%s' % source
2275
2279
2276 try:
2280 try:
2277 code = self.compile(source,filename,symbol)
2281 code = self.compile(source,filename,symbol)
@@ -21,6 +21,7 b' Authors:'
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22
22
23 import re
23 import re
24 import sys
24
25
25 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
26 # Main function
27 # Main function
@@ -55,7 +56,10 b' def split_user_input(line, pattern=None):'
55 This is currently handles lines with '=' in them in a very inconsistent
56 This is currently handles lines with '=' in them in a very inconsistent
56 manner.
57 manner.
57 """
58 """
58
59 # We need to ensure that the rest of this routine deals only with unicode
60 if type(line)==str:
61 line = line.decode(sys.stdin.encoding)
62
59 if pattern is None:
63 if pattern is None:
60 pattern = line_split
64 pattern = line_split
61 match = pattern.match(line)
65 match = pattern.match(line)
@@ -65,15 +69,16 b' def split_user_input(line, pattern=None):'
65 ifun, the_rest = line.split(None,1)
69 ifun, the_rest = line.split(None,1)
66 except ValueError:
70 except ValueError:
67 # print "split failed for line '%s'" % line
71 # print "split failed for line '%s'" % line
68 ifun, the_rest = line,''
72 ifun, the_rest = line, u''
69 pre = re.match('^(\s*)(.*)',line).groups()[0]
73 pre = re.match('^(\s*)(.*)',line).groups()[0]
70 else:
74 else:
71 pre,ifun,the_rest = match.groups()
75 pre,ifun,the_rest = match.groups()
72
76
73 # ifun has to be a valid python identifier, so it better be only pure
77 # ifun has to be a valid python identifier, so it better encode into
74 # ascii, no unicode:
78 # ascii. We do still make it a unicode string so that we consistently
79 # return unicode, but it will be one that is guaranteed to be pure ascii
75 try:
80 try:
76 ifun = ifun.encode('ascii')
81 ifun = unicode(ifun.encode('ascii'))
77 except UnicodeEncodeError:
82 except UnicodeEncodeError:
78 the_rest = ifun + u' ' + the_rest
83 the_rest = ifun + u' ' + the_rest
79 ifun = u''
84 ifun = u''
@@ -61,6 +61,11 b' class OutStream(object):'
61 if self.pub_socket is None:
61 if self.pub_socket is None:
62 raise ValueError('I/O operation on closed file')
62 raise ValueError('I/O operation on closed file')
63 else:
63 else:
64 # We can only send raw bytes, not unicode objects, so we encode
65 # into utf-8 for all frontends if we get unicode inputs.
66 if type(string) == unicode:
67 string = string.encode('utf-8')
68
64 self._buffer.write(string)
69 self._buffer.write(string)
65 current_time = time.time()
70 current_time = time.time()
66 if self._start <= 0:
71 if self._start <= 0:
General Comments 0
You need to be logged in to leave comments. Login now