MCPcopy Index your code
hub / github.com/ipython/ipython / psearch

Method psearch

IPython/core/oinspect.py:1109–1173  ·  view source on GitHub ↗

Search namespaces with wildcards for objects. Arguments: - pattern: string containing shell-like wildcards to use in namespace searches and optionally a type specification to narrow the search to objects of that type. - ns_table: dict of name->namespace

(self,pattern,ns_table,ns_search=[],
                ignore_case=False,show_all=False, *, list_types=False)

Source from the content-addressed store, hash-verified

1107 return False
1108
1109 def psearch(self,pattern,ns_table,ns_search=[],
1110 ignore_case=False,show_all=False, *, list_types=False):
1111 """Search namespaces with wildcards for objects.
1112
1113 Arguments:
1114
1115 - pattern: string containing shell-like wildcards to use in namespace
1116 searches and optionally a type specification to narrow the search to
1117 objects of that type.
1118
1119 - ns_table: dict of name->namespaces for search.
1120
1121 Optional arguments:
1122
1123 - ns_search: list of namespace names to include in search.
1124
1125 - ignore_case(False): make the search case-insensitive.
1126
1127 - show_all(False): show all names, including those starting with
1128 underscores.
1129
1130 - list_types(False): list all available object types for object matching.
1131 """
1132 # print('ps pattern:<%r>' % pattern) # dbg
1133
1134 # defaults
1135 type_pattern = 'all'
1136 filter = ''
1137
1138 # list all object types
1139 if list_types:
1140 page.page('\n'.join(sorted(typestr2type)))
1141 return
1142
1143 cmds = pattern.split()
1144 len_cmds = len(cmds)
1145 if len_cmds == 1:
1146 # Only filter pattern given
1147 filter = cmds[0]
1148 elif len_cmds == 2:
1149 # Both filter and type specified
1150 filter,type_pattern = cmds
1151 else:
1152 raise ValueError('invalid argument string for psearch: <%s>' %
1153 pattern)
1154
1155 # filter search namespaces
1156 for name in ns_search:
1157 if name not in ns_table:
1158 raise ValueError('invalid namespace <%s>. Valid names: %s' %
1159 (name,ns_table.keys()))
1160
1161 # print('type_pattern:',type_pattern) # dbg
1162 search_result, namespaces_seen = set(), set()
1163 for ns_name in ns_search:
1164 ns = ns_table[ns_name]
1165 # Normally, locals and globals are the same, so we just check one.
1166 if id(ns) in namespaces_seen:

Callers

nothing calls this directly

Calls 5

list_namespaceFunction · 0.90
pageMethod · 0.80
keysMethod · 0.80
addMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected