##// END OF EJS Templates
Moving clearcmd.py to quarantine....
Moving clearcmd.py to quarantine. When a module is moved to quarantine, it means that while we intend to keep it, it is currently broken or sufficiently untested that it can't be in the main IPython codebase. To be moved back into the main IPython codebase a module must: 1. Work fully. 2. Have a test suite as much as possible. 3. Have members of the IPython dev team who are willing to maintain it.

File last commit:

r2256:b7bb7522
r2266:eda4ef85
Show More
ext_rescapture.py
58 lines | 1.3 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.core.error import TryNext
from IPython.utils.genutils import *
ip = ipapi.get()
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)
return itpl('$var = get_ipython().magic($expr)')
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)')
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 TryNext
ip.set_hook('input_prefilter', regex_prefilter_f)