Look for registered object factory if given factory is an interface
authorThierry Florac <thierry.florac@onf.fr>
Thu, 14 Jun 2018 17:32:18 +0200
changeset 196 c0db0561ded3
parent 195 65b6d930b42b
child 197 00af28a2352d
child 266 b63d9050929d
Look for registered object factory if given factory is an interface
src/pyams_utils/adapter.py
--- a/src/pyams_utils/adapter.py	Thu Jun 14 13:57:57 2018 +0200
+++ b/src/pyams_utils/adapter.py	Thu Jun 14 17:32:18 2018 +0200
@@ -31,8 +31,9 @@
 from zope.annotation.interfaces import IAnnotations
 
 # import packages
+from pyams_utils.factory import get_object_factory
 from pyams_utils.registry import get_current_registry
-from zope.interface import implementedBy, alsoProvides
+from zope.interface import implementedBy, alsoProvides, Interface
 from zope.lifecycleevent import ObjectCreatedEvent
 from zope.location import locate as zope_locate
 
@@ -157,6 +158,9 @@
         elif factory is None:
             return None
         else:
+            if issubclass(factory, Interface):
+                factory = get_object_factory(factory)
+                assert factory is not None, "Missing object factory"
             adapter = annotations[key] = factory()
             if markers:
                 if not isinstance(markers, (list, tuple, set)):