[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture - hooks.py:1.1.2.5
Jim Fulton
jim@zope.com
Tue, 20 Nov 2001 17:10:38 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv24952
Modified Files:
Tag: Zope-3x-branch
hooks.py
Log Message:
Checked in so Tres can test.
=== Zope3/lib/python/Zope/ComponentArchitecture/hooks.py 1.1.2.4 => 1.1.2.5 ===
"""
+from Exceptions import ComponentLookupError
+
+_marker=[]
def provideFeature(forInterface, providedInterface, maker):
return provideFeature_hook(forInterface, providedInterface, maker)
-def getFeature(object, interface, default=None):
- return getFeature_hook(object, interface, default)
+def getFeature(object, interface, default=_marker):
+ r=getFeature_hook(object, interface, default)
+ if r is _marker: raise ComponentLookupError(object, interface)
+ return r
+
def provideUtility(providedInterface, component):
return provideUtility_hook(providedInterface, component)
-def getUtility(object, interface, default=None):
- return getUtility_hook(object, interface, default)
+def getUtility(object, interface, default=_marker):
+ r = getUtility_hook(object, interface, default)
+ if r is _marker: raise ComponentLookupError(object, interface)
+ return r
def providePresentation(forInterface, name, type, maker):
return providePresentation_hook(forInterface, name, type, maker)
-def getPresentation(object, name, type, default=None):
- return getPresentation_hook(object, name, type, default)
+def getPresentation(object, name, type, default=_marker):
+ r = getPresentation_hook(object, name, type, default)
+ if r is _marker: raise ComponentLookupError(object, interface)
+ return r
def provideFactory(qname, factory):
return provideFactory_hook(qname, factory)
@@ -36,7 +46,6 @@
from IToIRegistry import IToIRegistry
-_features = IToIRegistry()
def provideFeature_hook(forInterface, providedInterface, maker):
_features.register(forInterface, providedInterface, maker)
@@ -46,7 +55,6 @@
if c is None: return default
return c(object)
-_utilities = IToIRegistry()
def provideUtility_hook(providedInterface, component):
_utilities.register(None, providedInterface, component)
@@ -55,7 +63,6 @@
if c is None: return default
return c
-_presentations = {}
def providePresentation_hook(forInterface, name, type, maker):
reg=_presentations.get(name, None)
if reg is None:
@@ -73,12 +80,23 @@
from Interface.verify import verify as _verify
from Zope.ComponentArchitecture.IFactory import IFactory as _IFactory
-_factories = {}
def provideFactory_hook(qname, factory):
_verify(_IFactory, factory.__class__)
_factories[qname] = factory
-def createObject_hook(qname):
- factory = _factories[qname]
+def createObject_hook(object, name):
+ try: factory = _factories[name]
+ except KeyError:
+ raise ComponentLookupError(qname)
return factory()
+
+def _clear():
+ global _features, _utilities, _presentations, _factories
+ _features = IToIRegistry()
+ _utilities = IToIRegistry()
+ _presentations = {}
+ _factories = {}
+
+_clear()
+