##// END OF EJS Templates
Added compatibility layer for Shell/ipapi/iplib....
Added compatibility layer for Shell/ipapi/iplib. These 3 top-level modules have been moved to core. But, to ease the transition to their new location, we have re-created these modules at the top-level. The new top-level modules print a warning statement and simple import the moved modules for now. In the long run, we can use these for further compatibility related things.

File last commit:

r2027:bff26de7
r2061:73165067
Show More
ext_rescapture.py
63 lines | 1.5 KiB | text/x-python | PythonLexer
# -*- coding: utf-8 -*-
""" IPython extension: new prefilters for output grabbing
Provides
var = %magic blah blah
var = !ls
"""
from IPython.core import ipapi
from IPython.utils.genutils import *
ip = ipapi.get()
import re
def hnd_magic(line,mo):
""" Handle a = %mymagic blah blah """
#cmd = genutils.make_quoted_expr(mo.group('syscmd'))
#mag = 'ipmagic
#return "%s = %s"
var = mo.group('varname')
cmd = mo.group('cmd')
expr = make_quoted_expr(cmd)
return itpl('$var = _ip.magic($expr)')
def hnd_syscmd(line,mo):
""" Handle a = !ls """
#cmd = genutils.make_quoted_expr(mo.group('syscmd'))
#mag = 'ipmagic
#return "%s = %s"
var = mo.group('varname')
cmd = mo.group('cmd')
expr = make_quoted_expr(itpl("sc -l =$cmd"))
return itpl('$var = _ip.magic($expr)')
def install_re_handler(pat, hnd):
ip.meta.re_prefilters.append((re.compile(pat), hnd))
def init_handlers():
ip.meta.re_prefilters = []
install_re_handler('(?P<varname>[\w\.]+)\s*=\s*%(?P<cmd>.*)',
hnd_magic
)
install_re_handler('(?P<varname>[\w\.]+)\s*=\s*!(?P<cmd>.*)',
hnd_syscmd
)
init_handlers()
def regex_prefilter_f(self,line):
for pat, handler in ip.meta.re_prefilters:
mo = pat.match(line)
if mo:
return handler(line,mo)
raise ipapi.TryNext
ip.set_hook('input_prefilter', regex_prefilter_f)