##// END OF EJS Templates
Added support to list available object types, to use on object type matching in magic function %psearch.
Andreas -
Show More
@@ -173,6 +173,9 b' class NamespaceMagics(Magics):'
173 173 'builtin', 'user', 'user_global','internal', 'alias', where
174 174 'builtin' and 'user' are the search defaults. Note that you should
175 175 not use quotes when specifying namespaces.
176
177 -l: List all available object types for object matching. This function
178 can be used without arguments.
176 179
177 180 'Builtin' contains the python module builtin, 'user' contains all
178 181 user data, 'alias' only contain the shell aliases and no python
@@ -200,6 +203,10 b' class NamespaceMagics(Magics):'
200 203 Show objects beginning with a single _::
201 204
202 205 %psearch -a _* list objects beginning with a single underscore
206
207 List available objects::
208
209 %psearch -l list all available object types
203 210 """
204 211 try:
205 212 parameter_s.encode('ascii')
@@ -211,10 +218,15 b' class NamespaceMagics(Magics):'
211 218 def_search = ['user_local', 'user_global', 'builtin']
212 219
213 220 # Process options/args
214 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
221 opts,args = self.parse_options(parameter_s,'cias:e:l',list_all=True)
215 222 opt = opts.get
216 223 shell = self.shell
217 224 psearch = shell.inspector.psearch
225
226 # select list object types
227 list_types = False
228 if 'l' in opts:
229 list_types = True
218 230
219 231 # select case options
220 232 if 'i' in opts:
@@ -232,7 +244,7 b' class NamespaceMagics(Magics):'
232 244 # Call the actual search
233 245 try:
234 246 psearch(args,shell.ns_table,ns_search,
235 show_all=opt('a'),ignore_case=ignore_case)
247 show_all=opt('a'),ignore_case=ignore_case, list_types=list_types)
236 248 except:
237 249 shell.showtraceback()
238 250
@@ -35,6 +35,7 b' from IPython.utils.dir2 import safe_hasattr'
35 35 from IPython.utils.path import compress_user
36 36 from IPython.utils.text import indent
37 37 from IPython.utils.wildcard import list_namespace
38 from IPython.utils.wildcard import typestr2type
38 39 from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable
39 40 from IPython.utils.py3compat import cast_unicode
40 41 from IPython.utils.colorable import Colorable
@@ -962,7 +963,7 b' class Inspector(Colorable):'
962 963 return False
963 964
964 965 def psearch(self,pattern,ns_table,ns_search=[],
965 ignore_case=False,show_all=False):
966 ignore_case=False,show_all=False, list_types=False):
966 967 """Search namespaces with wildcards for objects.
967 968
968 969 Arguments:
@@ -981,6 +982,8 b' class Inspector(Colorable):'
981 982
982 983 - show_all(False): show all names, including those starting with
983 984 underscores.
985
986 - list_types(False): list all available object types for object matching.
984 987 """
985 988 #print 'ps pattern:<%r>' % pattern # dbg
986 989
@@ -988,6 +991,11 b' class Inspector(Colorable):'
988 991 type_pattern = 'all'
989 992 filter = ''
990 993
994 # list all object types
995 if list_types:
996 page.page('\n'.join(sorted(typestr2type)))
997 return
998
991 999 cmds = pattern.split()
992 1000 len_cmds = len(cmds)
993 1001 if len_cmds == 1:
General Comments 0
You need to be logged in to leave comments. Login now