Filter a namespace dictionary by name pattern and item type.
(ns, name_pattern="*", type_pattern="all", ignore_case=True,
show_all=True)
| 73 | return ns |
| 74 | |
| 75 | def filter_ns(ns, name_pattern="*", type_pattern="all", ignore_case=True, |
| 76 | show_all=True): |
| 77 | """Filter a namespace dictionary by name pattern and item type.""" |
| 78 | pattern = name_pattern.replace("*",".*").replace("?",".") |
| 79 | if ignore_case: |
| 80 | reg = re.compile(pattern+"$", re.I) |
| 81 | else: |
| 82 | reg = re.compile(pattern+"$") |
| 83 | |
| 84 | # Check each one matches regex; shouldn't be hidden; of correct type. |
| 85 | return dict((key,obj) for key, obj in ns.items() if reg.match(key) \ |
| 86 | and show_hidden(key, show_all) \ |
| 87 | and is_type(obj, type_pattern) ) |
| 88 | |
| 89 | def list_namespace(namespace, type_pattern, filter, ignore_case=False, show_all=False): |
| 90 | """Return dictionary of all objects in a namespace dictionary that match |
no test coverage detected
searching dependent graphs…