diff options
Diffstat (limited to 'src/mailman/app/finder.py')
| -rw-r--r-- | src/mailman/app/finder.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/mailman/app/finder.py b/src/mailman/app/finder.py index 41685730a..bd1305c21 100644 --- a/src/mailman/app/finder.py +++ b/src/mailman/app/finder.py @@ -22,6 +22,7 @@ from __future__ import absolute_import, unicode_literals __metaclass__ = type __all__ = [ 'find_components', + 'scan_module', ] @@ -32,6 +33,25 @@ from pkg_resources import resource_listdir +def scan_module(module, interface): + """Return all the items in a module that conform to an interface. + + :param module: A module object. The module's `__all__` will be scanned. + :type module: module + :param interface: The interface that returned objects must conform to. + :type interface: `Interface` + :return: The sequence of matching components. + :rtype: objects implementing `interface` + """ + missing = object() + for name in module.__all__: + component = getattr(module, name, missing) + assert component is not missing, ( + '%s has bad __all__: %s' % (module, name)) + if interface.implementedBy(component): + yield component + + def find_components(package, interface): """Find components which conform to a given interface. @@ -54,10 +74,5 @@ def find_components(package, interface): module = sys.modules[module_name] if not hasattr(module, '__all__'): continue - for name in module.__all__: - missing = object() - component = getattr(module, name, missing) - assert component is not missing, ( - '%s has bad __all__: %s' % (module, name)) - if interface.implementedBy(component): - yield component + for component in scan_module(module, interface): + yield component |
