##// END OF EJS Templates
Changing input filtering to require whitespace separation between the initial command (alias, magic, autocall) and rest of line. ...
dan.milstein -
Show More
@@ -105,7 +105,7 b' def splitUserInput(line, pattern=None):'
105
105
106 #print 'line:<%s>' % line # dbg
106 #print 'line:<%s>' % line # dbg
107 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
107 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
108 return pre,iFun.strip(),theRest
108 return pre,iFun.strip(),theRest.lstrip()
109
109
110
110
111 # RegExp for splitting line contents into pre-char//first word-method//rest.
111 # RegExp for splitting line contents into pre-char//first word-method//rest.
@@ -122,10 +122,10 b' def splitUserInput(line, pattern=None):'
122 # The three parts of the regex are:
122 # The three parts of the regex are:
123 # 1) pre: pre_char *or* initial whitespace
123 # 1) pre: pre_char *or* initial whitespace
124 # 2) iFun: first word/method (mix of \w and '.')
124 # 2) iFun: first word/method (mix of \w and '.')
125 # 3) theRest: rest of line
125 # 3) theRest: rest of line (separated from iFun by space if non-empty)
126 line_split = re.compile(r'^([,;/%?]|!!?|\s*)'
126 line_split = re.compile(r'^([,;/%?]|!!?|\s*)'
127 r'\s*([\w\.]+)\s*'
127 r'\s*([\w\.]+)'
128 r'(.*)$')
128 r'(\s+.*$|$)')
129
129
130 shell_line_split = re.compile(r'^(\s*)(\S*\s*)(.*$)')
130 shell_line_split = re.compile(r'^(\s*)(\S*\s*)(.*$)')
131
131
@@ -17,7 +17,8 b' def run(tests):'
17 ip.runlines(pre)
17 ip.runlines(pre)
18 ip.runlines('_i') # Not sure why I need this...
18 ip.runlines('_i') # Not sure why I need this...
19 actual = ip.user_ns['_i']
19 actual = ip.user_ns['_i']
20 if actual != None: actual = actual.rstrip('\n')
20 if actual != None:
21 actual = actual.rstrip('\n')
21 if actual != post:
22 if actual != post:
22 failures.append('Expected %r to become %r, found %r' % (
23 failures.append('Expected %r to become %r, found %r' % (
23 pre, post, actual))
24 pre, post, actual))
@@ -53,8 +54,8 b' try:'
53 # write anything to stdout.
54 # write anything to stdout.
54
55
55 # Turn off actual execution of aliases, because it's noisy
56 # Turn off actual execution of aliases, because it's noisy
56 old_system_cmd = ip.IP.system
57 old_system_cmd = ip.system
57 ip.IP.system = lambda cmd: None
58 ip.system = lambda cmd: None
58
59
59
60
60 ip.IP.alias_table['an_alias'] = (0, 'true')
61 ip.IP.alias_table['an_alias'] = (0, 'true')
@@ -66,7 +67,7 b' try:'
66 # chars, *not* initial chars which happen to be aliases:
67 # chars, *not* initial chars which happen to be aliases:
67 ("top", '_ip.system("d:/cygwin/top ")'),
68 ("top", '_ip.system("d:/cygwin/top ")'),
68 ])
69 ])
69 ip.IP.system = old_system_cmd
70 ip.system = old_system_cmd
70
71
71
72
72 call_idx = CallableIndexable()
73 call_idx = CallableIndexable()
@@ -154,11 +154,23 b' esc_handler_tests = ['
154 # XXX Possibly, add test for /,; once those are unhooked from %autocall
154 # XXX Possibly, add test for /,; once those are unhooked from %autocall
155 ( 'emacs_mode # PYTHON-MODE', handle_emacs ),
155 ( 'emacs_mode # PYTHON-MODE', handle_emacs ),
156 ( ' ', handle_normal),
156 ( ' ', handle_normal),
157
157 # Trailing qmark combos. Odd special cases abound
158 # Trailing qmark combos. Odd special cases abound
158 ( '!thing?', handle_shell_escape), # trailing '?' loses to shell esc
159
159 ( '!thing ?', handle_shell_escape),
160 # The key is: we don't want the trailing ? to trigger help if it's a
160 ( '!!thing?', handle_shell_escape),
161 # part of a shell glob (like, e.g. '!ls file.?'). Instead, we want the
162 # shell handler to be called. Due to subtleties of the input string
163 # parsing, however, we only call the shell handler if the trailing ? is
164 # part of something whitespace-separated from the !cmd. See examples.
165 ( '!thing?', handle_help),
166 ( '!thing arg?', handle_shell_escape),
167 ( '!!thing?', handle_help),
168 ( '!!thing arg?', handle_shell_escape),
169
170 # For all other leading esc chars, we always trigger help
161 ( '%cmd?', handle_help),
171 ( '%cmd?', handle_help),
172 ( '%cmd ?', handle_help),
173 ( '/cmd?', handle_help),
162 ( '/cmd?', handle_help),
174 ( '/cmd ?', handle_help),
163 ( ';cmd?', handle_help),
175 ( ';cmd?', handle_help),
164 ( ',cmd?', handle_help),
176 ( ',cmd?', handle_help),
@@ -216,6 +228,9 b' run_handler_tests(['
216 ( '%does_not_exist', handle_magic),
228 ( '%does_not_exist', handle_magic),
217 ( 'cd /', handle_magic),
229 ( 'cd /', handle_magic),
218 ( 'cd = 2', handle_normal),
230 ( 'cd = 2', handle_normal),
231 ( 'r', handle_magic),
232 ( 'r thing', handle_magic),
233 ( 'r"str"', handle_normal),
219 ])
234 ])
220
235
221 # If next elt starts with anything that could be an assignment, func call,
236 # If next elt starts with anything that could be an assignment, func call,
General Comments 0
You need to be logged in to leave comments. Login now