##// END OF EJS Templates
support for unicode identifiers...
Markus Wageringel -
Show More
@@ -52,7 +52,7 b' TIMEOUT_STORAGE = 2'
52 TIMEOUT_GIVEUP = 20
52 TIMEOUT_GIVEUP = 20
53
53
54 # Regular expression for the python import statement
54 # Regular expression for the python import statement
55 import_re = re.compile(r'(?P<name>[a-zA-Z_][a-zA-Z0-9_]*?)'
55 import_re = re.compile(r'(?P<name>[^\W\d]\w*?)'
56 r'(?P<package>[/\\]__init__)?'
56 r'(?P<package>[/\\]__init__)?'
57 r'(?P<suffix>%s)$' %
57 r'(?P<suffix>%s)$' %
58 r'|'.join(re.escape(s) for s in _suffixes))
58 r'|'.join(re.escape(s) for s in _suffixes))
@@ -278,8 +278,8 b' def escaped_commands(line):'
278 _initial_space_re = re.compile(r'\s*')
278 _initial_space_re = re.compile(r'\s*')
279
279
280 _help_end_re = re.compile(r"""(%{0,2}
280 _help_end_re = re.compile(r"""(%{0,2}
281 [a-zA-Z_*][\w*]* # Variable name
281 (?!\d)[\w*]+ # Variable name
282 (\.[a-zA-Z_*][\w*]*)* # .etc.etc
282 (\.(?!\d)[\w*]+)* # .etc.etc
283 )
283 )
284 (\?\??)$ # ? or ??
284 (\?\??)$ # ? or ??
285 """,
285 """,
@@ -405,8 +405,8 b' class EscapedCommand(TokenTransformBase):'
405 return lines_before + [new_line] + lines_after
405 return lines_before + [new_line] + lines_after
406
406
407 _help_end_re = re.compile(r"""(%{0,2}
407 _help_end_re = re.compile(r"""(%{0,2}
408 [a-zA-Z_*][\w*]* # Variable name
408 (?!\d)[\w*]+ # Variable name
409 (\.[a-zA-Z_*][\w*]*)* # .etc.etc
409 (\.(?!\d)[\w*]+)* # .etc.etc
410 )
410 )
411 (\?\??)$ # ? or ??
411 (\?\??)$ # ? or ??
412 """,
412 """,
@@ -208,12 +208,6 b' class NamespaceMagics(Magics):'
208
208
209 %psearch -l list all available object types
209 %psearch -l list all available object types
210 """
210 """
211 try:
212 parameter_s.encode('ascii')
213 except UnicodeEncodeError:
214 print('Python identifiers can only contain ascii characters.')
215 return
216
217 # default namespaces to be searched
211 # default namespaces to be searched
218 def_search = ['user_local', 'user_global', 'builtin']
212 def_search = ['user_local', 'user_global', 'builtin']
219
213
@@ -37,7 +37,7 b' class PrefilterError(Exception):'
37
37
38
38
39 # RegExp to identify potential function names
39 # RegExp to identify potential function names
40 re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
40 re_fun_name = re.compile(r'[^\W\d]([\w.]*) *$')
41
41
42 # RegExp to exclude strings with this start from autocalling. In
42 # RegExp to exclude strings with this start from autocalling. In
43 # particular, all binary operators should be excluded, so that if foo is
43 # particular, all binary operators should be excluded, so that if foo is
@@ -113,6 +113,7 b' syntax = \\'
113 (u'%hist2??', "get_ipython().run_line_magic('pinfo2', '%hist2')"),
113 (u'%hist2??', "get_ipython().run_line_magic('pinfo2', '%hist2')"),
114 (u'%%hist3?', "get_ipython().run_line_magic('pinfo', '%%hist3')"),
114 (u'%%hist3?', "get_ipython().run_line_magic('pinfo', '%%hist3')"),
115 (u'%%hist4??', "get_ipython().run_line_magic('pinfo2', '%%hist4')"),
115 (u'%%hist4??', "get_ipython().run_line_magic('pinfo2', '%%hist4')"),
116 (u'π.foo?', "get_ipython().run_line_magic('pinfo', 'π.foo')"),
116 (u'f*?', "get_ipython().run_line_magic('psearch', 'f*')"),
117 (u'f*?', "get_ipython().run_line_magic('psearch', 'f*')"),
117 (u'ax.*aspe*?', "get_ipython().run_line_magic('psearch', 'ax.*aspe*')"),
118 (u'ax.*aspe*?', "get_ipython().run_line_magic('psearch', 'ax.*aspe*')"),
118 (u'a = abc?', "get_ipython().set_next_input('a = abc');"
119 (u'a = abc?', "get_ipython().set_next_input('a = abc');"
@@ -119,6 +119,11 b' b) = zip?'
119 [r"get_ipython().set_next_input('(a,\nb) = zip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
119 [r"get_ipython().set_next_input('(a,\nb) = zip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
120 )
120 )
121
121
122 HELP_UNICODE = (
123 ["π.foo?\n"], (1, 0),
124 ["get_ipython().run_line_magic('pinfo', 'π.foo')\n"]
125 )
126
122
127
123 def null_cleanup_transformer(lines):
128 def null_cleanup_transformer(lines):
124 """
129 """
@@ -223,6 +228,9 b' def test_transform_help():'
223 tf = ipt2.HelpEnd((1, 0), (2, 8))
228 tf = ipt2.HelpEnd((1, 0), (2, 8))
224 nt.assert_equal(tf.transform(HELP_MULTILINE[0]), HELP_MULTILINE[2])
229 nt.assert_equal(tf.transform(HELP_MULTILINE[0]), HELP_MULTILINE[2])
225
230
231 tf = ipt2.HelpEnd((1, 0), (1, 0))
232 nt.assert_equal(tf.transform(HELP_UNICODE[0]), HELP_UNICODE[2])
233
226 def test_find_assign_op_dedent():
234 def test_find_assign_op_dedent():
227 """
235 """
228 be careful that empty token like dedent are not counted as parens
236 be careful that empty token like dedent are not counted as parens
@@ -602,6 +602,8 b' def doctest_precision():'
602 def test_psearch():
602 def test_psearch():
603 with tt.AssertPrints("dict.fromkeys"):
603 with tt.AssertPrints("dict.fromkeys"):
604 _ip.run_cell("dict.fr*?")
604 _ip.run_cell("dict.fr*?")
605 with tt.AssertPrints("π.is_integer"):
606 _ip.run_cell("π = 3.14;\nπ.is_integ*?")
605
607
606 def test_timeit_shlex():
608 def test_timeit_shlex():
607 """test shlex issues with timeit (#1109)"""
609 """test shlex issues with timeit (#1109)"""
@@ -115,3 +115,13 b' def test_prefilter_attribute_errors():'
115 finally:
115 finally:
116 del ip.user_ns['x']
116 del ip.user_ns['x']
117 ip.magic('autocall 0')
117 ip.magic('autocall 0')
118
119
120 def test_autocall_should_support_unicode():
121 ip.magic('autocall 2')
122 ip.user_ns['π'] = lambda x: x
123 try:
124 nt.assert_equal(ip.prefilter('π 3'),'π(3)')
125 finally:
126 ip.magic('autocall 0')
127 del ip.user_ns['π']
General Comments 0
You need to be logged in to leave comments. Login now