[Zope3-checkins] CVS: Zope3/lib/python/Interface/Registry - AdapterRegistry.py:1.2 ImplementorRegistry.py:1.2 TypeRegistry.py:1.2
Jim Fulton
jim@zope.com
Thu, 1 Aug 2002 12:07:11 -0400
Update of /cvs-repository/Zope3/lib/python/Interface/Registry
In directory cvs.zope.org:/tmp/cvs-serv10436/lib/python/Interface/Registry
Modified Files:
AdapterRegistry.py ImplementorRegistry.py TypeRegistry.py
Log Message:
Added type checks to registration functions to make sure interfaces
are passed where expected. A common annoying error is to pass the
module containing an interface, rather than the interface.
Interestingly, this change revealed 4 such errors in the check-in
sources.
=== Zope3/lib/python/Interface/Registry/AdapterRegistry.py 1.1 => 1.2 ===
__metaclass__ = type # All classes are new style when run with Python 2.2+
from Interface import Interface
+from Interface.IInterface import IInterface
from _flatten import _flatten
from IAdapterRegistry import IAdapterRegistry
@@ -64,7 +65,14 @@
self._registerAllProvided(require, primary_provide, object, base)
- def register(self, require, provide, object):
+ def register(self, require, provide, object):
+ if require is not None and not IInterface.isImplementedBy(require):
+ raise TypeError(
+ "The require argument must be an interface (or None)")
+ if not IInterface.isImplementedBy(provide):
+ raise TypeError(
+ "The provide argument must be an interface (or None)")
+
self._registerAllProvided(require, provide, object, provide)
def get(self, (ob_interface, provide), default=None):
=== Zope3/lib/python/Interface/Registry/ImplementorRegistry.py 1.1 => 1.2 ===
__metaclass__ = type # All classes are new style when run with Python 2.2+
from Interface import Interface
+from Interface.IInterface import IInterface
from IImplementorRegistry import IImplementorRegistry
class ImplementorRegistry:
@@ -63,6 +64,10 @@
def register(self, provide, object):
+ if not IInterface.isImplementedBy(provide):
+ raise TypeError(
+ "The provide argument must be an interface (or None)")
+
self._registerAllProvided(provide, object, provide)
def get(self, provide, default=None):
=== Zope3/lib/python/Interface/Registry/TypeRegistry.py 1.1 => 1.2 ===
__metaclass__ = type # All classes are new style when run with Python 2.2+
from Interface import Interface
+from Interface.IInterface import IInterface
from _flatten import _flatten
from ITypeRegistry import ITypeRegistry
@@ -41,6 +42,9 @@
self._reg = {}
def register(self, interface, object):
+ if interface is not None and not IInterface.isImplementedBy(interface):
+ raise TypeError(
+ "The interface argument must be an interface (or None)")
self._reg[interface] = object
def get(self, interface, default=None):