def jobctrl_prefilter_f(self,line): if line.startswith('&'): pre,fn,rest = self.split_user_input(line[1:]) line = ip.expand_aliases(fn,rest) if not _jobq: return 'get_ipython().startjob(%s)' % make_quoted_expr(line) return 'get_ipython().jobq(%s)' % make_quoted_expr(line) raise TryNext
def jobctrl_prefilter_f(self, line): if line.startswith('&'): pre, fn, rest = self.split_user_input(line[1:]) line = ip.expand_aliases(fn, rest) if not _jobq: return 'get_ipython().startjob(%s)' % make_quoted_expr(line) return 'get_ipython().jobq(%s)' % make_quoted_expr(line) raise TryNext
def _make_help_call(target, esc, lspace, next_input=None): """Prepares a pinfo(2)/psearch call from a target name and the escape (i.e. ? or ??)""" method = "pinfo2" if esc == "??" else "psearch" if "*" in target else "pinfo" arg = make_quoted_expr(" ".join([method, target])) if next_input: tpl = "%sget_ipython().magic(%s, next_input=%s)" return tpl % (lspace, arg, make_quoted_expr(next_input)) else: return "%sget_ipython().magic(%s)" % (lspace, arg)
def _make_help_call(target, esc, lspace, next_input=None): """Prepares a pinfo(2)/psearch call from a target name and the escape (i.e. ? or ??)""" method = 'pinfo2' if esc == '??' \ else 'psearch' if '*' in target \ else 'pinfo' arg = make_quoted_expr(" ".join([method, target])) if next_input: tpl = '%sget_ipython().magic(%s, next_input=%s)' return tpl % (lspace, arg, make_quoted_expr(next_input)) else: return '%sget_ipython().magic(%s)' % (lspace, arg)
def handle(self, line_info): """Execute magic functions.""" ifun = line_info.ifun the_rest = line_info.the_rest cmd = '%sget_ipython().magic(%s)' % ( line_info.pre_whitespace, make_quoted_expr(ifun + " " + the_rest)) return cmd
def handle(self, line_info): """Execute magic functions.""" ifun = line_info.ifun the_rest = line_info.the_rest cmd = '%sget_ipython().magic(%s)' % (line_info.pre_whitespace, make_quoted_expr(ifun + " " + the_rest)) return cmd
def handle(self, line_info): """Handle alias input lines. """ transformed = self.shell.alias_manager.expand_aliases(line_info.ifun, line_info.the_rest) # pre is needed, because it carries the leading whitespace. Otherwise # aliases won't work in indented sections. line_out = "%sget_ipython().system(%s)" % (line_info.pre_whitespace, make_quoted_expr(transformed)) return line_out
def handle(self, line_info): """Execute magic functions.""" ifun = line_info.ifun the_rest = line_info.the_rest cmd = '%sget_ipython().magic(%s)' % (line_info.pre_whitespace, make_quoted_expr(ifun + " " + the_rest)) self.shell.log(line_info.line, cmd, line_info.continue_prompt) return cmd
def transform(self, line, continue_prompt): m = _assign_system_re.match(line) if m is not None: cmd = m.group("cmd") lhs = m.group("lhs") expr = make_quoted_expr("sc =%s" % cmd) new_line = "%s = get_ipython().magic(%s)" % (lhs, expr) return new_line return line
def transform(self, line, continue_prompt): m = _assign_magic_re.match(line) if m is not None: cmd = m.group('cmd') lhs = m.group('lhs') expr = make_quoted_expr(cmd) new_line = '%s = get_ipython().magic(%s)' % (lhs, expr) return new_line return line
def handle(self, line_info): """Handle alias input lines. """ transformed = self.shell.alias_manager.expand_aliases(line_info.ifun,line_info.the_rest) # pre is needed, because it carries the leading whitespace. Otherwise # aliases won't work in indented sections. line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace, make_quoted_expr(transformed)) return line_out
def _make_help_call(target, esc, lspace, next_input=None): """Prepares a pinfo(2)/psearch call from a target name and the escape (i.e. ? or ??)""" method = "pinfo2" if esc == "??" else "psearch" if "*" in target else "pinfo" if next_input: tpl = '%sget_ipython().magic(u"%s %s", next_input=%s)' return tpl % (lspace, method, target, make_quoted_expr(next_input)) else: return '%sget_ipython().magic(u"%s %s")' % (lspace, method, target)
def transform_assign_system(line): """Handle the `files = !ls` syntax.""" m = _assign_system_re.match(line) if m is not None: cmd = m.group('cmd') lhs = m.group('lhs') expr = make_quoted_expr(cmd) new_line = '%s = get_ipython().getoutput(%s)' % (lhs, expr) return new_line return line
def transform_assign_magic(line): """Handle the `a = %who` syntax.""" m = _assign_magic_re.match(line) if m is not None: cmd = m.group('cmd') lhs = m.group('lhs') expr = make_quoted_expr(cmd) new_line = '%s = get_ipython().magic(%s)' % (lhs, expr) return new_line return line
def handle(self, line_info): """Execute the line in a shell, empty return value""" magic_handler = self.prefilter_manager.get_handler_by_name("magic") line = line_info.line if line.lstrip().startswith(ESC_SH_CAP): # rewrite LineInfo's line, ifun and the_rest to properly hold the # call to %sx and the actual command to be executed, so # handle_magic can work correctly. Note that this works even if # the line is indented, so it handles multi_line_specials # properly. new_rest = line.lstrip()[2:] line_info.line = "%ssx %s" % (ESC_MAGIC, new_rest) line_info.ifun = "sx" line_info.the_rest = new_rest return magic_handler.handle(line_info) else: cmd = line.lstrip().lstrip(ESC_SHELL) line_out = "%sget_ipython().system(%s)" % (line_info.pre_whitespace, make_quoted_expr(cmd)) return line_out
def handle(self, line_info): """Execute the line in a shell, empty return value""" magic_handler = self.prefilter_manager.get_handler_by_name('magic') line = line_info.line if line.lstrip().startswith(ESC_SH_CAP): # rewrite LineInfo's line, ifun and the_rest to properly hold the # call to %sx and the actual command to be executed, so # handle_magic can work correctly. Note that this works even if # the line is indented, so it handles multi_line_specials # properly. new_rest = line.lstrip()[2:] line_info.line = '%ssx %s' % (ESC_MAGIC, new_rest) line_info.ifun = 'sx' line_info.the_rest = new_rest return magic_handler.handle(line_info) else: cmd = line.lstrip().lstrip(ESC_SHELL) line_out = '%sget_ipython().system(%s)' % ( line_info.pre_whitespace, make_quoted_expr(cmd)) return line_out
def hnd_magic(line, mo): """ Handle a = %mymagic blah blah """ var = mo.group('varname') cmd = mo.group('cmd') expr = make_quoted_expr(cmd) return itpl('$var = get_ipython().magic($expr)')
def _tr_system(line_info): "Translate lines escaped with: !" cmd = line_info.line.lstrip().lstrip(ESC_SHELL) return '%sget_ipython().system(%s)' % (line_info.pre, make_quoted_expr(cmd))
def _tr_magic(line_info): "Translate lines escaped with: %" tpl = '%sget_ipython().magic(%s)' cmd = make_quoted_expr(' '.join([line_info.fpart, line_info.rest]).strip()) return tpl % (line_info.lspace, cmd)
def _tr_system2(line_info): "Translate lines escaped with: !!" cmd = line_info.line.lstrip()[2:] return '%sget_ipython().getoutput(%s)' % (line_info.lspace, make_quoted_expr(cmd))
def _tr_system(line_info): "Translate lines escaped with: !" cmd = line_info.line.lstrip().lstrip(ESC_SHELL) return '%sget_ipython().system(%s)' % (line_info.lspace, make_quoted_expr(cmd))
def _tr_system2(line_info): "Translate lines escaped with: !!" cmd = line_info.line.lstrip()[2:] return '%sget_ipython().getoutput(%s)' % (line_info.pre, make_quoted_expr(cmd))
def _tr_magic(line_info): "Translate lines escaped with: %" tpl = '%sget_ipython().magic(%s)' cmd = make_quoted_expr(' '.join([line_info.ifun, line_info.the_rest]).strip()) return tpl % (line_info.pre, cmd)
def hnd_magic(line,mo): """ Handle a = %mymagic blah blah """ var = mo.group('varname') cmd = mo.group('cmd') expr = make_quoted_expr(cmd) return itpl('$var = get_ipython().magic($expr)')
def hnd_syscmd(line, mo): """ Handle a = !ls """ var = mo.group('varname') cmd = mo.group('cmd') expr = make_quoted_expr(itpl("sc -l =$cmd")) return itpl('$var = get_ipython().magic($expr)')
def _tr_magic(line_info): "Translate lines escaped with: %" tpl = "%sget_ipython().magic(%s)" cmd = make_quoted_expr(" ".join([line_info.ifun, line_info.the_rest]).strip()) return tpl % (line_info.pre, cmd)
def hnd_syscmd(line,mo): """ Handle a = !ls """ var = mo.group('varname') cmd = mo.group('cmd') expr = make_quoted_expr(itpl("sc -l =$cmd")) return itpl('$var = get_ipython().magic($expr)')