##// 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 res = pre + self.IP.expand_aliases(fn,rest)
362 res = pre + self.IP.expand_aliases(fn,rest)
363 return res
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 def defalias(self, name, cmd):
373 def defalias(self, name, cmd):
366 """ Define a new alias
374 """ Define a new alias
367
375
@@ -463,7 +471,7 b' class IPApi:'
463
471
464 self.extensions[mod] = m
472 self.extensions[mod] = m
465 return m
473 return m
466
474
467
475
468 class DebugTools:
476 class DebugTools:
469 """ Used for debugging mishaps in api usage
477 """ Used for debugging mishaps in api usage
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
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 'internal':self.internal_ns,
316 'internal':self.internal_ns,
317 'builtin':__builtin__.__dict__
317 'builtin':__builtin__.__dict__
318 }
318 }
319
320 # The user namespace MUST have a pointer to the shell itself.
319 # The user namespace MUST have a pointer to the shell itself.
321 self.user_ns[name] = self
320 self.user_ns[name] = self
322
321
@@ -592,6 +591,8 b' class InteractiveShell(object,Magic):'
592 # tracking what it did via the builtins_added dict.
591 # tracking what it did via the builtins_added dict.
593 self.add_builtins()
592 self.add_builtins()
594
593
594
595
595 # end __init__
596 # end __init__
596
597
597 def var_expand(self,cmd,depth=0):
598 def var_expand(self,cmd,depth=0):
@@ -2172,8 +2173,13 b' want to merge them back into the new files.""" % locals()'
2172 tgt = self.alias_table[line_info.iFun]
2173 tgt = self.alias_table[line_info.iFun]
2173 # print "=>",tgt #dbg
2174 # print "=>",tgt #dbg
2174 if callable(tgt):
2175 if callable(tgt):
2175 line_out = "_sh.%s(%s)" % (line_info.iFun,
2176 if '$' in line_info.line:
2176 make_quoted_expr(self.var_expand(line_info.line, depth=2)))
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 else:
2183 else:
2178 transformed = self.expand_aliases(line_info.iFun,line_info.theRest)
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