##// 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 106 #print 'line:<%s>' % line # dbg
107 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 111 # RegExp for splitting line contents into pre-char//first word-method//rest.
@@ -122,10 +122,10 b' def splitUserInput(line, pattern=None):'
122 122 # The three parts of the regex are:
123 123 # 1) pre: pre_char *or* initial whitespace
124 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 126 line_split = re.compile(r'^([,;/%?]|!!?|\s*)'
127 r'\s*([\w\.]+)\s*'
128 r'(.*)$')
127 r'\s*([\w\.]+)'
128 r'(\s+.*$|$)')
129 129
130 130 shell_line_split = re.compile(r'^(\s*)(\S*\s*)(.*$)')
131 131
@@ -17,7 +17,8 b' def run(tests):'
17 17 ip.runlines(pre)
18 18 ip.runlines('_i') # Not sure why I need this...
19 19 actual = ip.user_ns['_i']
20 if actual != None: actual = actual.rstrip('\n')
20 if actual != None:
21 actual = actual.rstrip('\n')
21 22 if actual != post:
22 23 failures.append('Expected %r to become %r, found %r' % (
23 24 pre, post, actual))
@@ -53,8 +54,8 b' try:'
53 54 # write anything to stdout.
54 55
55 56 # Turn off actual execution of aliases, because it's noisy
56 old_system_cmd = ip.IP.system
57 ip.IP.system = lambda cmd: None
57 old_system_cmd = ip.system
58 ip.system = lambda cmd: None
58 59
59 60
60 61 ip.IP.alias_table['an_alias'] = (0, 'true')
@@ -66,7 +67,7 b' try:'
66 67 # chars, *not* initial chars which happen to be aliases:
67 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 73 call_idx = CallableIndexable()
@@ -154,12 +154,24 b' esc_handler_tests = ['
154 154 # XXX Possibly, add test for /,; once those are unhooked from %autocall
155 155 ( 'emacs_mode # PYTHON-MODE', handle_emacs ),
156 156 ( ' ', handle_normal),
157
157 158 # Trailing qmark combos. Odd special cases abound
158 ( '!thing?', handle_shell_escape), # trailing '?' loses to shell esc
159 ( '!thing ?', handle_shell_escape),
160 ( '!!thing?', handle_shell_escape),
159
160 # The key is: we don't want the trailing ? to trigger help if it's a
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 171 ( '%cmd?', handle_help),
172 ( '%cmd ?', handle_help),
162 173 ( '/cmd?', handle_help),
174 ( '/cmd ?', handle_help),
163 175 ( ';cmd?', handle_help),
164 176 ( ',cmd?', handle_help),
165 177 ]
@@ -216,6 +228,9 b' run_handler_tests(['
216 228 ( '%does_not_exist', handle_magic),
217 229 ( 'cd /', handle_magic),
218 230 ( 'cd = 2', handle_normal),
231 ( 'r', handle_magic),
232 ( 'r thing', handle_magic),
233 ( 'r"str"', handle_normal),
219 234 ])
220 235
221 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