Exemplo n.º 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)' % make_quoted_expr(line)
        return 'get_ipython().jobq(%s)' % make_quoted_expr(line)

    raise TryNext
Exemplo n.º 2
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)' % make_quoted_expr(line)
        return 'get_ipython().jobq(%s)' % make_quoted_expr(line)

    raise TryNext
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
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))
     return cmd
Exemplo n.º 7
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))
     return cmd
Exemplo n.º 8
0
    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
Exemplo n.º 9
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
Exemplo n.º 10
0
 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
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
0
 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
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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
Exemplo n.º 17
0
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
Exemplo n.º 18
0
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
Exemplo n.º 19
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))
        return line_out
Exemplo n.º 20
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))
        return line_out
Exemplo n.º 21
0
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)')
Exemplo n.º 22
0
 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))
Exemplo n.º 23
0
 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)
Exemplo n.º 24
0
 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))
Exemplo n.º 25
0
 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))
Exemplo n.º 26
0
 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))
Exemplo n.º 27
0
 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)
Exemplo n.º 28
0
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)')
Exemplo n.º 29
0
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)')
Exemplo n.º 30
0
 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)
Exemplo n.º 31
0
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)')