##// END OF EJS Templates
added _ip.itpl, to enable var expansion with callable aliases
vivainio -
Show More
@@ -362,6 +362,14 b' class IPApi:'
362 362 res = pre + self.IP.expand_aliases(fn,rest)
363 363 return res
364 364
365 def itpl(self, s, depth = 1):
366 """ Expand Itpl format string s.
367
368 Only callable from command line (i.e. prefilter results);
369 If you use in your scripts, you need to use a bigger depth!
370 """
371 return self.IP.var_expand(s, depth)
372
365 373 def defalias(self, name, cmd):
366 374 """ Define a new alias
367 375
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 2713 2007-09-05 18:34:29Z vivainio $
9 $Id: iplib.py 2718 2007-09-05 21:54:50Z vivainio $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -316,7 +316,6 b' class InteractiveShell(object,Magic):'
316 316 'internal':self.internal_ns,
317 317 'builtin':__builtin__.__dict__
318 318 }
319
320 319 # The user namespace MUST have a pointer to the shell itself.
321 320 self.user_ns[name] = self
322 321
@@ -592,6 +591,8 b' class InteractiveShell(object,Magic):'
592 591 # tracking what it did via the builtins_added dict.
593 592 self.add_builtins()
594 593
594
595
595 596 # end __init__
596 597
597 598 def var_expand(self,cmd,depth=0):
@@ -2172,8 +2173,13 b' want to merge them back into the new files.""" % locals()'
2172 2173 tgt = self.alias_table[line_info.iFun]
2173 2174 # print "=>",tgt #dbg
2174 2175 if callable(tgt):
2175 line_out = "_sh.%s(%s)" % (line_info.iFun,
2176 make_quoted_expr(self.var_expand(line_info.line, depth=2)))
2176 if '$' in line_info.line:
2177 call_meth = '(_ip.itpl(%s))'
2178 else:
2179 call_meth = '(%s)'
2180 line_out = ("%s_sh.%s" + call_meth) % (line_info.preWhitespace,
2181 line_info.iFun,
2182 make_quoted_expr(line_info.line))
2177 2183 else:
2178 2184 transformed = self.expand_aliases(line_info.iFun,line_info.theRest)
2179 2185
General Comments 0
You need to be logged in to leave comments. Login now