merge default doc-dc
authorDamien Correia
Fri, 15 Jun 2018 16:36:40 +0200
branchdoc-dc
changeset 268 34af60bf1683
parent 267 6d2469d780f7 (current diff)
parent 198 7d70896756f2 (diff)
child 269 4815c9f22461
merge default
--- a/src/pyams_utils/adapter.py	Fri Jun 15 14:12:02 2018 +0200
+++ b/src/pyams_utils/adapter.py	Fri Jun 15 16:36:40 2018 +0200
@@ -27,13 +27,11 @@
 
 import venusian
 
-from inspect import isclass
-
 # import interfaces
 from zope.annotation.interfaces import IAnnotations
 
 # import packages
-from pyams_utils.factory import get_object_factory
+from pyams_utils.factory import get_object_factory, is_interface
 from pyams_utils.registry import get_current_registry
 from zope.interface import implementedBy, alsoProvides, Interface
 from zope.lifecycleevent import ObjectCreatedEvent
@@ -160,7 +158,7 @@
         elif factory is None:
             return None
         else:
-            if isclass(factory) and issubclass(factory, Interface):
+            if is_interface(factory):
                 factory = get_object_factory(factory)
                 assert factory is not None, "Missing object factory"
             adapter = annotations[key] = factory()
--- a/src/pyams_utils/factory.py	Fri Jun 15 14:12:02 2018 +0200
+++ b/src/pyams_utils/factory.py	Fri Jun 15 16:36:40 2018 +0200
@@ -26,6 +26,7 @@
 from pyams_utils.registry import get_global_registry
 from zope.component import adapter, queryAdapter
 from zope.interface import implementer, Interface
+from zope.interface.interface import InterfaceClass
 
 
 @adapter(Interface)
@@ -42,6 +43,11 @@
         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__