[Zope3-checkins] SVN: Zope3/branches/3.3/src/zope/app/component/
Added some more compatibility.
Jim Fulton
jim at zope.com
Mon Jul 31 12:12:50 EDT 2006
Log message for revision 69310:
Added some more compatibility.
Changed:
U Zope3/branches/3.3/src/zope/app/component/back35.py
U Zope3/branches/3.3/src/zope/app/component/tests/deprecated35_registration.txt
-=-
Modified: Zope3/branches/3.3/src/zope/app/component/back35.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/component/back35.py 2006-07-31 15:50:22 UTC (rev 69309)
+++ Zope3/branches/3.3/src/zope/app/component/back35.py 2006-07-31 16:12:49 UTC (rev 69310)
@@ -25,6 +25,7 @@
from persistent import Persistent
+from zope import component
import zope.cachedescriptors.property
import zope.event
import zope.schema
@@ -532,7 +533,6 @@
# See zope.app.component.interfaces.registration.IComponentRegistration
interface = None
-
class Registered:
"""An adapter from IRegisterable to IRegistered.
@@ -546,10 +546,12 @@
self.registerable = registerable
def registrations(self):
- rm = zapi.getParent(self.registerable).registrationManager
- return [reg for reg in rm.values()
- if (IComponentRegistration.providedBy(reg) and
- reg.component is self.registerable)]
+ context = self.registerable
+ return [
+ r
+ for r in component.getSiteManager(context).registeredUtilities()
+ if r.component == context
+ ]
class RegistrationManager(BTreeContainer):
@@ -849,6 +851,10 @@
def __setitem__(self, k, v):
self.update([(k, v)])
+ def __delitem__(self, k):
+ self.update(())
+ del getattr(self.site, self.__name__)[k]
+
class _OldAdapterRegistrations(_OldUtilityRegistrations):
def _getOldRegistrations(self):
Modified: Zope3/branches/3.3/src/zope/app/component/tests/deprecated35_registration.txt
===================================================================
--- Zope3/branches/3.3/src/zope/app/component/tests/deprecated35_registration.txt 2006-07-31 15:50:22 UTC (rev 69309)
+++ Zope3/branches/3.3/src/zope/app/component/tests/deprecated35_registration.txt 2006-07-31 16:12:49 UTC (rev 69310)
@@ -32,6 +32,8 @@
... """See zope.component.interfaces.IRegistry"""
... return self._registrations
...
+ ... registeredUtilities = registrations
+ ...
... def register(self, registration):
... """See interfaces.registration.IRegistry"""
... self._registrations.append(registration)
@@ -78,6 +80,7 @@
registration class, let's test what we have so far. To do that we have to
create a component that we would like to register:
+ >>> import zope.component.interfaces
>>> from zope.app.container.contained import Contained
>>> class Component(Contained):
... zope.interface.implements(interfaces.registration.IRegisterable)
@@ -85,6 +88,10 @@
... self.title = title
... def __repr__(self):
... return "<Component: '%s'>" %self.title
+ ...
+ ... def __conform__(self, iface):
+ ... if iface == zope.component.interfaces.IComponentLookup:
+ ... return registry
Note that `Contained` is used as a base class, since `IRegisterable` requires
it to be. We will later see why this is the case.
@@ -323,6 +330,7 @@
The `Registered` Adapter
------------------------
+
Registerable components are able to get a list of all their
registrations. However, the adapter only works for components and
registrations that are stored in the registerable container and registration
@@ -333,15 +341,4 @@
>>> registered.registrations() #doctest: +NORMALIZE_WHITESPACE
[<Registration for '<Component: 'Foo'>'>,
<Registration for '<Component: 'Foo'>'>]
-
-If the registerable component is not stored in a registrable container, a
-type error is raised, since no parent can be found:
-
- >>> registered = Registered(something)
- >>> registered.registrations() #doctest: +NORMALIZE_WHITESPACE
- Traceback (most recent call last):
- ...
- TypeError: ('Not enough context information to get parent',
- <Component: 'Something'>)
-
More information about the Zope3-Checkins
mailing list