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