##// END OF EJS Templates
var = !cmd is no longer verbose
vivainio -
Show More
@@ -1,66 +1,66 b''
1 1 # -*- coding: utf-8 -*-
2 2 """ IPython extension: new prefilters for output grabbing
3 3
4 4 Provides
5 5
6 6 var = %magic blah blah
7 7
8 8 var = !ls
9 9
10 10 $Id: genutils.py 1077 2006-01-24 18:15:27Z vivainio $
11 11
12 12 """
13 13
14 14 import IPython.ipapi
15 15 from IPython.genutils import *
16 16
17 17 ip = IPython.ipapi.get()
18 18
19 19 import re
20 20
21 21 def hnd_magic(line,mo):
22 22 """ Handle a = %mymagic blah blah """
23 23 #cmd = genutils.make_quoted_expr(mo.group('syscmd'))
24 24 #mag = 'ipmagic
25 25 #return "%s = %s"
26 26 var = mo.group('varname')
27 27 cmd = mo.group('cmd')
28 28 expr = make_quoted_expr(cmd)
29 29 return itpl('$var = _ip.magic($expr)')
30 30
31 31 def hnd_syscmd(line,mo):
32 32 """ Handle a = !ls """
33 33 #cmd = genutils.make_quoted_expr(mo.group('syscmd'))
34 34 #mag = 'ipmagic
35 35 #return "%s = %s"
36 36 var = mo.group('varname')
37 37 cmd = mo.group('cmd')
38 expr = make_quoted_expr(itpl("sc -lv =$cmd"))
38 expr = make_quoted_expr(itpl("sc -l =$cmd"))
39 39 return itpl('$var = _ip.magic($expr)')
40 40
41 41 def install_re_handler(pat, hnd):
42 42 ip.meta.re_prefilters.append((re.compile(pat), hnd))
43 43
44 44 def init_handlers():
45 45
46 46 ip.meta.re_prefilters = []
47 47
48 48 install_re_handler('(?P<varname>[\w\.]+)\s*=\s*%(?P<cmd>.*)',
49 49 hnd_magic
50 50 )
51 51
52 52 install_re_handler('(?P<varname>[\w\.]+)\s*=\s*!(?P<cmd>.*)',
53 53 hnd_syscmd
54 54 )
55 55
56 56 init_handlers()
57 57
58 58 def regex_prefilter_f(self,line):
59 59 for pat, handler in ip.meta.re_prefilters:
60 60 mo = pat.match(line)
61 61 if mo:
62 62 return handler(line,mo)
63 63
64 64 raise IPython.ipapi.TryNext
65 65
66 66 ip.set_hook('input_prefilter', regex_prefilter_f)
General Comments 0
You need to be logged in to leave comments. Login now