Hello
This checkin contains the following change to
zope.component/trunk/src/zope/component/registry.py
which looks wrong to me (it's a noop). It looks to me as if the [:2]
should move outside the ) following it. I am surprised that this
doesn't break any tests, as it means that reregistrations are not
detected as such.
-if (self._utility_registrations.get((provided, name))
+if (self._utility_registrations.get((provided, name)[:2])
Wichert Akkerman wrote:
Log message for revision 88794:
Merge wichert-utility-factories branch to trunk
Changed:
D zope.component/branches/wichert-utility-factories/
U zope.component/trunk/README.txt
U zope.component/trunk/src/zope/component/interfaces.py
U zope.component/trunk/src/zope/component/registry.py
U zope.component/trunk/src/zope/component/registry.txt
U zope.component/trunk/src/zope/component/zcml.py
-=-
Modified: zope.component/trunk/README.txt
===
--- zope.component/trunk/README.txt 2008-07-24 16:00:26 UTC (rev 88793)
+++ zope.component/trunk/README.txt 2008-07-24 16:17:58 UTC (rev 88794)
@@ -14,6 +14,10 @@
3.5.0 (unreleased)
==
+Support registration of utilities via factories through the component registry
+and return factory information in the registration information. This fixes
+https://bugs.launchpad.net/zope3/+bug/240631
+
Optimized un/registerUtility via storing an optimized data structure for
efficient retrieval of already registered utilities. This avoids looping over
all utilities when registering a new one.
Modified: zope.component/trunk/src/zope/component/interfaces.py
===
--- zope.component/trunk/src/zope/component/interfaces.py 2008-07-24
16:00:26 UTC (rev 88793)
+++ zope.component/trunk/src/zope/component/interfaces.py 2008-07-24
16:17:58 UTC (rev 88794)
@@ -512,6 +512,7 @@
Information about the registration of a utility
+factory = interface.Attribute(The factory used to create the utility. Optional.)
component = interface.Attribute(The object registered)
provided = interface.Attribute(The interface provided by the component)
@@ -583,9 +584,12 @@
Register components
-def registerUtility(component, provided=None, name=u'', info=u''):
+def registerUtility(component=None, provided=None, name=u'', info=u'',
factory=None):
Register a utility
+factory
+ Factory for the component to be registerd.
+
component
The registered component
@@ -602,10 +606,11 @@
An object that can be converted to a string to provide
information about the registration.
+Only one of component and factory can be used.
A Registered event is generated with an IUtilityRegistration.
-def unregisterUtility(component=None, provided=None, name=u''):
+def unregisterUtility(component=None, provided=None, name=u'',
factory=None):
Unregister a utility
A boolean is returned indicating whether the registry was
@@ -614,6 +619,9 @@
None and is not registered, then the function returns
False, otherwise it returns True.
+factory
+ Factory for the component to be unregisterd.
+
component
The registered component The given component can be
None, in which case any component registered to provide
@@ -629,6 +637,7 @@
name
The utility name.
+Only one of component and factory can be used.
An UnRegistered event is generated with an IUtilityRegistration.
Modified: zope.component/trunk/src/zope/component/registry.py
===
--- zope.component/trunk/src/zope/component/registry.py 2008-07-24 16:00:26 UTC
(rev 88793)
+++ zope.component/trunk/src/zope/component/registry.py 2008-07-24 16:17:58 UTC
(rev 88794)
@@ -65,12 +65,17 @@
lambda self, bases: self._setBases(bases),
)
-def registerUtility(self, component, provided=None, name=u'', info=u'',
-event=True):
+def registerUtility(self, component=None, provided=None, name=u'',
info=u'',
+event=True, factory=None):
+if factory:
+if component:
+raise TypeError(Can't specify factory and component.)
+component = factory()
+
if provided is None:
provided = _getUtilityProvided(component)
-if (self._utility_registrations.get((provided, name))
+if (self._utility_registrations.get((provided, name)[:2])
== (component, info)):
# already registered
return
@@ -81,7 +86,7 @@
subscribed = True
break
-