[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/component/components.py Added error checks and checks for required values == None.

Jim Fulton jim at zope.com
Tue Feb 28 17:38:55 EST 2006


Log message for revision 65619:
  Added error checks and checks for required values == None.
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/component/components.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/component/components.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/component/components.py	2006-02-28 22:38:38 UTC (rev 65618)
+++ Zope3/branches/jim-adapter/src/zope/component/components.py	2006-02-28 22:38:55 UTC (rev 65619)
@@ -16,6 +16,7 @@
 $Id$
 """
 
+import types
 import zope.interface.adapter
 from zope import interface
 from zope.component import interfaces
@@ -283,6 +284,8 @@
         "The adapter factory doesn't implement a single interface "
         "and no provided interface was specified.")
 
+
+classTypes = type, types.ClassType
 def _getAdapterRequired(factory, required):
     if required is None:
         try:
@@ -292,11 +295,21 @@
                 "The adapter factory doesn't have a __component_adapts__ "
                 "attribute and no required specifications were specified"
                 )
+    elif zope.interface.interfaces.ISpecification.providedBy(required):
+        raise TypeError("the required argument should be a list of "
+                        "interfaces, not a single interface")
 
     result = []
     for r in required:
-        if not zope.interface.interfaces.ISpecification.providedBy(r):
-            r = interface.implementedBy(r)
+        if r is None:
+            r = interface.Interface
+        elif not zope.interface.interfaces.ISpecification.providedBy(r):
+            if isinstance(r, classTypes):
+                r = interface.implementedBy(r)
+            else:
+                raise TypeError("Required specification must be a "
+                                "specification or class."
+                                )
         result.append(r)
     return tuple(result)
         



More information about the Zope3-Checkins mailing list