##// END OF EJS Templates
More work on componentizing everything....
More work on componentizing everything. I have also done some work on component: * componenets whose __init__ method fails are now unregistered. * Added a masquerade_as function to enable components to masquerade as one another. This is really a cheap and informal way of doing parts of an interface system.

File last commit:

r2205:8ce57664
r2243:5b86c0c8
Show More
ext_rescapture.py
58 lines | 1.3 KiB | text/x-python | PythonLexer
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151 # -*- coding: utf-8 -*-
""" IPython extension: new prefilters for output grabbing
Provides
var = %magic blah blah
var = !ls
"""
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
Brian Granger
Continuing a massive refactor of everything.
r2205 from IPython.core.error import TryNext
Brian Granger
genutils.py => utils/genutils.py and updated imports and tests.
r2023 from IPython.utils.genutils import *
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 ip = ipapi.get()
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
import re
def hnd_magic(line,mo):
""" Handle a = %mymagic blah blah """
var = mo.group('varname')
cmd = mo.group('cmd')
expr = make_quoted_expr(cmd)
vivainio
-Expose IPApi is _ip in user namespace....
r158 return itpl('$var = _ip.magic($expr)')
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
def hnd_syscmd(line,mo):
""" Handle a = !ls """
var = mo.group('varname')
cmd = mo.group('cmd')
vivainio
var = !cmd is no longer verbose
r902 expr = make_quoted_expr(itpl("sc -l =$cmd"))
vivainio
-Expose IPApi is _ip in user namespace....
r158 return itpl('$var = _ip.magic($expr)')
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
def install_re_handler(pat, hnd):
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 ip.meta.re_prefilters.append((re.compile(pat), hnd))
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
def init_handlers():
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 ip.meta.re_prefilters = []
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
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):
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 for pat, handler in ip.meta.re_prefilters:
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151 mo = pat.match(line)
if mo:
return handler(line,mo)
Brian Granger
Continuing a massive refactor of everything.
r2205 raise TryNext
vivainio
a = !ls, a = %alias now work (captures output or gets ret val for aliases)...
r151
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 ip.set_hook('input_prefilter', regex_prefilter_f)