##// END OF EJS Templates
wildcard fixes for subclasses
fperez -
Show More
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 919 2005-10-15 07:57:05Z fperez $"""
4 $Id: Magic.py 922 2005-11-13 10:21:08Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -816,7 +816,7 b' Currently the magic system has the following functions:\\n"""'
816 array_type = Numeric.ArrayType.__name__
816 array_type = Numeric.ArrayType.__name__
817
817
818 # Find all variable names and types so we can figure out column sizes
818 # Find all variable names and types so we can figure out column sizes
819 get_vars = lambda i: self.locals[i]
819 get_vars = lambda i: self.shell.user_ns[i]
820 type_name = lambda v: type(v).__name__
820 type_name = lambda v: type(v).__name__
821 varlist = map(get_vars,varnames)
821 varlist = map(get_vars,varnames)
822 typelist = map(type_name,varlist)
822 typelist = map(type_name,varlist)
@@ -871,8 +871,9 b' Currently the magic system has the following functions:\\n"""'
871 if not ans.lower() == 'y':
871 if not ans.lower() == 'y':
872 print 'Nothing done.'
872 print 'Nothing done.'
873 return
873 return
874 user_ns = self.shell.user_ns
874 for i in self.magic_who_ls():
875 for i in self.magic_who_ls():
875 del(self.locals[i])
876 del(user_ns[i])
876
877
877 def magic_config(self,parameter_s=''):
878 def magic_config(self,parameter_s=''):
878 """Show IPython's internal configuration."""
879 """Show IPython's internal configuration."""
@@ -6,7 +6,7 b' Uses syntax highlighting for presenting the various information elements.'
6 Similar in spirit to the inspect module, but all calls take a name argument to
6 Similar in spirit to the inspect module, but all calls take a name argument to
7 reference the name under which an object is being read.
7 reference the name under which an object is being read.
8
8
9 $Id: OInspect.py 919 2005-10-15 07:57:05Z fperez $
9 $Id: OInspect.py 922 2005-11-13 10:21:08Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -398,45 +398,45 b' class Inspector:'
398 page(output)
398 page(output)
399 # end pinfo
399 # end pinfo
400
400
401 def psearch(self,oname='',formatter = None,shell=None):
401 def psearch(self,oname='',formatter=None,shell=None):
402 """Search namespaces with wildcards for objects.
402 """Search namespaces with wildcards for objects.
403
403
404 Optional arguments:
404 Optional arguments:
405
405
406 - oname: rest of the commandline containging pattern and options
406 - oname: rest of the commandline containging pattern and options.
407
407
408 - formatter: Not used
408 - formatter: Not used.
409
409
410 - shell: The shell object from the Magic class. Needed to
410 - shell: The shell object from the Magic class. Needed to access
411 access the namespaces
411 the namespaces.
412
412 """
413 """
413 option_list = ['-c','-a']
414 option_list=["-c","-a"]
414 cmds = oname.split()
415 import pdb
415 filter = ''
416 # pdb.set_trace()
416 type_pattern = 'all'
417 cmds=oname.split()
417 options = [x for x in cmds if x in option_list]
418 filter=""
418 ignorecase = '-c' not in options
419 type_pattern="all"
419 showhidden = '-a' in options
420 ns_cmds=[]
420 ns_cmds = [x for x in cmds if x[0] in '-+' and x not in option_list]
421 options=[x for x in cmds if x in option_list]
421 cmds = [x for x in cmds if x[0] not in '-+']
422 ignorecase="-c" not in options
422 len_cmds = len(cmds)
423 showhidden="-a" in options
423 if len_cmds == 1:
424 ns_cmds=[x for x in cmds if x[0] in "-+" and x not in option_list]
424 filter = cmds[0].strip()
425 cmds=[x for x in cmds if x[0] not in "-+"]
425 elif len_cmds == 2:
426 if len(cmds)>2: #assume we want to choose name spaces.
426 filter,type_pattern = cmds
427 #Rather poor design forces the use of a typepattern in order to choose name spaces
427 elif len_cmds>2:
428 cmds=cmds[:2]
428 # assume we want to choose name spaces. Rather poor design forces
429 if len(cmds)==2:
429 #the use of a typepattern in order to choose name spaces
430 filter,type_pattern=cmds
430 cmds = cmds[:2]
431 elif len(cmds)==1:
431
432 filter=cmds[0].strip()
432 do_list = choose_namespaces(shell,ns_cmds)
433
433
434 do_list=choose_namespaces(shell,ns_cmds)
434 search_result = []
435
435 for ns in do_list:
436 search_result=[]
436 tmp_res = list(list_namespace(ns,type_pattern,filter,
437 for ns in do_list:
437 ignorecase=ignorecase,
438 tmp_res=list(list_namespace(ns,type_pattern,filter,ignorecase=ignorecase,showhidden=showhidden))
438 showhidden=showhidden))
439 search_result.extend(tmp_res)
439 search_result.extend(tmp_res)
440 search_result.sort()
440 search_result.sort()
441
441
442 page("\n".join(search_result))
442 page('\n'.join(search_result))
@@ -69,19 +69,18 b' class NameSpace(object):'
69 on name and types"""
69 on name and types"""
70 def __init__(self,obj,namepattern="*",typepattern="all",ignorecase=True,
70 def __init__(self,obj,namepattern="*",typepattern="all",ignorecase=True,
71 showhidden=True):
71 showhidden=True):
72 self.showhidden=showhidden #Hide names beginning with single _
72 self.showhidden = showhidden #Hide names beginning with single _
73 self.object=obj
73 self.object = obj
74 self.namepattern=namepattern
74 self.namepattern = namepattern
75 self.typepattern=typepattern
75 self.typepattern = typepattern
76 self.ignorecase=ignorecase
76 self.ignorecase = ignorecase
77 if type(obj)==type(dict()):
77
78 self._ns=obj
78 # We should only match EXACT dicts here, so DON'T use isinstance()
79 if type(obj) == types.DictType:
80 self._ns = obj
79 else:
81 else:
80 try:
82 self._ns = dict([(key,getattr(obj,key)) for key in dir(obj)
81 self._ns=self.object.__dict__
83 if isinstance(key, basestring)])
82 except exceptions.AttributeError:
83 self._ns=dict([(key,getattr(self.object,key))
84 for key in dir(self.object)])
85
84
86 def get_ns(self):
85 def get_ns(self):
87 """Return name space dictionary with objects matching type and name patterns."""
86 """Return name space dictionary with objects matching type and name patterns."""
@@ -1,3 +1,9 b''
1 2005-11-13 <Fernando.Perez@colorado.edu>
2
3 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
4 attributes in wildcard searches for subclasses. Modified version
5 of a patch by Jorgen.
6
1 2005-11-12 <Fernando.Perez@colorado.edu>
7 2005-11-12 <Fernando.Perez@colorado.edu>
2
8
3 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
9 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
General Comments 0
You need to be logged in to leave comments. Login now