[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture - __init__.py:1.1.6.4 hooks.py:1.1.2.4
Fred Drake Jr
fdrake@acm.org
Tue, 20 Nov 2001 15:38:59 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv5302
Modified Files:
Tag: Zope-3x-branch
__init__.py hooks.py
Log Message:
Add provideFactory(), createObject().
=== Zope3/lib/python/Zope/ComponentArchitecture/__init__.py 1.1.6.3 => 1.1.6.4 ===
from hooks import provideUtility, getUtility
from hooks import providePresentation, getPresentation
+from hooks import provideFactory, createObject
=== Zope3/lib/python/Zope/ComponentArchitecture/hooks.py 1.1.2.3 => 1.1.2.4 ===
return getPresentation_hook(object, name, type, default)
+def provideFactory(qname, factory):
+ return provideFactory_hook(qname, factory)
+
+def createObject(qname):
+ return createObject_hook(qname)
+
# default hooks
from IToIRegistry import IToIRegistry
@@ -63,4 +69,16 @@
c=reg.getForObject(object, type)
if c is None: return default
return c(object)
-
+
+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]
+ return factory()