示例#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
示例#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
示例#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)
示例#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)
示例#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)
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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)
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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)')
示例#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))
示例#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)
示例#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))
示例#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))
示例#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))
示例#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)
示例#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)')
示例#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)')
示例#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)
示例#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)')