##// END OF EJS Templates
Fix namespace handling for magics and shell escapes in function definitions.
fptest -
Show More
@@ -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 1874 2006-11-03 08:17:34Z fptest $
9 $Id: iplib.py 1878 2006-11-03 23:00:22Z fptest $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -460,21 +460,19 b' class InteractiveShell(object,Magic):'
460 460
461 461 # Functions to call the underlying shell.
462 462
463 # utility to expand user variables via Itpl
464 self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'),
465 self.user_ns))
466 463 # The first is similar to os.system, but it doesn't return a value,
467 464 # and it allows interpolation of variables in the user's namespace.
468 self.system = lambda cmd: shell(self.var_expand(cmd),
469 header='IPython system call: ',
470 verbose=self.rc.system_verbose)
465 self.system = lambda cmd: \
466 shell(self.var_expand(cmd,depth=2),
467 header='IPython system call: ',
468 verbose=self.rc.system_verbose)
471 469 # These are for getoutput and getoutputerror:
472 470 self.getoutput = lambda cmd: \
473 getoutput(self.var_expand(cmd),
471 getoutput(self.var_expand(cmd,depth=2),
474 472 header='IPython system call: ',
475 473 verbose=self.rc.system_verbose)
476 474 self.getoutputerror = lambda cmd: \
477 getoutputerror(self.var_expand(cmd),
475 getoutputerror(self.var_expand(cmd,depth=2),
478 476 header='IPython system call: ',
479 477 verbose=self.rc.system_verbose)
480 478
@@ -616,6 +614,22 b' class InteractiveShell(object,Magic):'
616 614
617 615 # end __init__
618 616
617 def var_expand(self,cmd,depth=0):
618 """Expand python variables in a string.
619
620 The depth argument indicates how many frames above the caller should
621 be walked to look for the local namespace where to expand variables.
622
623 The global namespace for expansion is always the user's interactive
624 namespace.
625 """
626
627 return str(ItplNS(cmd.replace('#','\#'),
628 self.user_ns, # globals
629 # Skip our own frame in searching for locals:
630 sys._getframe(depth+1).f_locals # locals
631 ))
632
619 633 def pre_config_initialization(self):
620 634 """Pre-configuration init method
621 635
@@ -915,7 +929,7 b' class InteractiveShell(object,Magic):'
915 929 if fn is None:
916 930 error("Magic function `%s` not found." % magic_name)
917 931 else:
918 magic_args = self.var_expand(magic_args)
932 magic_args = self.var_expand(magic_args,1)
919 933 return fn(magic_args)
920 934
921 935 def ipalias(self,arg_s):
@@ -23,6 +23,10 b''
23 23
24 24 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu>
25 25
26 * IPython/iplib.py (InteractiveShell.var_expand): fix stack
27 handling in variable expansion so that shells and magics recognize
28 function local scopes correctly. Bug reported by Brian.
29
26 30 * scripts/ipython: remove the very first entry in sys.path which
27 31 Python auto-inserts for scripts, so that sys.path under IPython is
28 32 as similar as possible to that under plain Python.
General Comments 0
You need to be logged in to leave comments. Login now