def test_autocall_should_ignore_raw_strings(): line_info = LineInfo("r'a'") pm = ip.prefilter_manager ac = AutocallChecker(shell=pm.shell, prefilter_manager=pm, config=pm.config) assert ac.check(line_info) is None
def escaped_commands(line): """Transform escaped commands - %magic, !system, ?help + various autocalls. """ if not line or line.isspace(): return line lineinf = LineInfo(line) if lineinf.esc not in tr: return line return tr[lineinf.esc](lineinf)
def prefilter_line(self, line, continue_prompt=False): """Prefilter a single input line as text. This method prefilters a single line of text by calling the transformers and then the checkers/handlers. """ # print "prefilter_line: ", line, continue_prompt # All handlers *must* return a value, even if it's blank (''). # save the line away in case we crash, so the post-mortem handler can # record it self.shell._last_input_line = line if not line: # Return immediately on purely empty lines, so that if the user # previously typed some whitespace that started a continuation # prompt, he can break out of that loop with just an empty line. # This is how the default python prompt works. return '' # At this point, we invoke our transformers. if not continue_prompt or (continue_prompt and self.multi_line_specials): line = self.transform_line(line, continue_prompt) # Now we compute line_info for the checkers and handlers line_info = LineInfo(line, continue_prompt) # the input history needs to track even empty lines stripped = line.strip() normal_handler = self.get_handler_by_name('normal') if not stripped: if not continue_prompt: self.shell.displayhook.prompt_count -= 1 return normal_handler.handle(line_info) # special handlers are only allowed for single line statements if continue_prompt and not self.multi_line_specials: return normal_handler.handle(line_info) prefiltered = self.prefilter_line_info(line_info) # print "prefiltered line: %r" % prefiltered return prefiltered
def __call__(self, line): """Class to transform lines that are explicitly escaped out. This calls the above _tr_* static methods for the actual line translations.""" # Empty lines just get returned unmodified if not line or line.isspace(): return line # Get line endpoints, where the escapes can be line_info = LineInfo(line) if not line_info.esc in self.tr: # If we don't recognize the escape, don't modify the line return line return self.tr[line_info.esc](line_info)
def test_LineInfo(): """Simple test for LineInfo construction and str()""" linfo = LineInfo(" %cd /home") nt.assert_equal(str(linfo), "LineInfo [ |%|cd|/home]")
def test_LineInfo(): """Simple test for LineInfo construction and str()""" linfo = LineInfo(" %cd /home") assert str(linfo) == "LineInfo [ |%|cd|/home]"