コード例 #1
0
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)' % genutils.make_quoted_expr(
                line)
        return 'get_ipython().jobq(%s)' % genutils.make_quoted_expr(line)

    raise TryNext
コード例 #2
0
 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
コード例 #3
0
def slash_prefilter_f(self,line):
    """ ./foo, ~/foo and /bin/foo now run foo as system command
    
    Removes the need for doing !./foo, !~/foo or !/bin/foo
    """
    from IPython.utils import genutils
    if re.match('(?:[.~]|/[a-zA-Z_0-9]+)/', line):
        return "get_ipython().system(" + genutils.make_quoted_expr(line)+")"
    raise TryNext
コード例 #4
0
def slash_prefilter_f(self, line):
    """ ./foo, ~/foo and /bin/foo now run foo as system command

    Removes the need for doing !./foo, !~/foo or !/bin/foo
    """
    from IPython.utils import genutils
    if re.match('(?:[.~]|/[a-zA-Z_0-9]+)/', line):
        return "get_ipython().system(" + genutils.make_quoted_expr(line) + ")"
    raise TryNext
コード例 #5
0
 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
コード例 #6
0
    def handle(self, line_info):
        """Handle alias input lines. """
        transformed = self.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))

        self.shell.log(line_info.line, line_out, line_info.continue_prompt)
        return line_out
コード例 #7
0
    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))
        # update cache/log and return
        self.shell.log(line, line_out, line_info.continue_prompt)
        return line_out