##// END OF EJS Templates
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ipython branch. This is not a true merge in the formal sense because all history is not coming over with the files. For a detailed history of the added files, please see the ipython1-dev branch or the svn repository on scipy.org that ipython1-dev came from. More specifically, here is what I have done in this commit: 1) Moved the following by hand ipython1.config -> IPython.config ipython1.kernel -> IPython.kernel ipython1.external -> IPython.external ipython1.core -> IPython.kernel.core ipython1.testutils -> IPython.testing ipython1.tools -> IPython.tools 2) Moved IPython.tools.guid -> IPython1.external.guid 3) Renamed: ipython1 -> IPython IPython.core -> IPython.kernel.core IPython.testutils -> IPython.testing 4) Then did a "bzr add" for all the new stuff. That is all folks!

File last commit:

r902:213157fc
r1234:52b55407
Show More
ext_rescapture.py
66 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
$Id: genutils.py 1077 2006-01-24 18:15:27Z vivainio $
"""
import IPython.ipapi
from IPython.genutils import *
ip = IPython.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 IPython.ipapi.TryNext
ip.set_hook('input_prefilter', regex_prefilter_f)