Cleanup...
--- a/src/pyams_utils/factory.py Thu Jan 17 10:59:39 2019 +0100
+++ b/src/pyams_utils/factory.py Thu Jan 17 14:23:59 2019 +0100
@@ -30,11 +30,13 @@
.. code-block:: python
- @implementer(IMyInterface)
@factory_config(IMyInterface)
class MyClass(object):
'''Class implementing my interface'''
+A class declared as factory for a specific interface automatically implements the given interface.
+You can also provide a tuple or set of interfaces in "factory_config()" decorator.
+
When a factory is registered, you can look for a factory:
.. code-block:: python
@@ -51,21 +53,27 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
import logging
-logger = logging.getLogger('PyAMS (utils)')
import venusian
+from zope.component import adapter
+from zope.interface import Interface, classImplements, implementer
+from zope.interface.interface import InterfaceClass
-# import interfaces
from pyams_utils.interfaces import IObjectFactory
+from pyams_utils.registry import get_global_registry
+
+logger = logging.getLogger('PyAMS (utils)')
-# import packages
-from pyams_utils.registry import get_global_registry
-from zope.component import adapter, queryAdapter
-from zope.interface import implementer, Interface, provider, classImplements
-from zope.interface.interface import InterfaceClass
+
+def is_interface(object):
+ """Check if given object is an interface"""
+ return issubclass(object.__class__, InterfaceClass)
+
+
+def get_interface_name(iface):
+ """Get interface full name"""
+ return iface.__module__ + '.' + iface.__name__
@adapter(Interface)
@@ -82,16 +90,6 @@
return self.factory()
-def is_interface(object):
- """Check if given object is an interface"""
- return issubclass(object.__class__, InterfaceClass)
-
-
-def get_interface_name(iface):
- """Get interface full name"""
- return iface.__module__ + '.' + iface.__name__
-
-
def register_factory(interface, klass, registry=None, name=''):
"""Register factory for a given interface