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)
| 922 | return False |
| 923 | |
| 924 | def psearch(self,pattern,ns_table,ns_search=[], |
| 925 | ignore_case=False,show_all=False, *, list_types=False): |
| 926 | """Search namespaces with wildcards for objects. |
| 927 | |
| 928 | Arguments: |
| 929 | |
| 930 | - pattern: string containing shell-like wildcards to use in namespace |
| 931 | searches and optionally a type specification to narrow the search to |
| 932 | objects of that type. |
| 933 | |
| 934 | - ns_table: dict of name->namespaces for search. |
| 935 | |
| 936 | Optional arguments: |
| 937 | |
| 938 | - ns_search: list of namespace names to include in search. |
| 939 | |
| 940 | - ignore_case(False): make the search case-insensitive. |
| 941 | |
| 942 | - show_all(False): show all names, including those starting with |
| 943 | underscores. |
| 944 | |
| 945 | - list_types(False): list all available object types for object matching. |
| 946 | """ |
| 947 | #print 'ps pattern:<%r>' % pattern # dbg |
| 948 | |
| 949 | # defaults |
| 950 | type_pattern = 'all' |
| 951 | filter = '' |
| 952 | |
| 953 | # list all object types |
| 954 | if list_types: |
| 955 | page.page('\n'.join(sorted(typestr2type))) |
| 956 | return |
| 957 | |
| 958 | cmds = pattern.split() |
| 959 | len_cmds = len(cmds) |
| 960 | if len_cmds == 1: |
| 961 | # Only filter pattern given |
| 962 | filter = cmds[0] |
| 963 | elif len_cmds == 2: |
| 964 | # Both filter and type specified |
| 965 | filter,type_pattern = cmds |
| 966 | else: |
| 967 | raise ValueError('invalid argument string for psearch: <%s>' % |
| 968 | pattern) |
| 969 | |
| 970 | # filter search namespaces |
| 971 | for name in ns_search: |
| 972 | if name not in ns_table: |
| 973 | raise ValueError('invalid namespace <%s>. Valid names: %s' % |
| 974 | (name,ns_table.keys())) |
| 975 | |
| 976 | #print 'type_pattern:',type_pattern # dbg |
| 977 | search_result, namespaces_seen = set(), set() |
| 978 | for ns_name in ns_search: |
| 979 | ns = ns_table[ns_name] |
| 980 | # Normally, locals and globals are the same, so we just check one. |
| 981 | if id(ns) in namespaces_seen: |
nothing calls this directly
no test coverage detected