[Zope3-checkins] CVS: Zope3/src/zope/app/event - subs.py:1.10
Steve Alexander
steve@cat-box.net
Tue, 18 Feb 2003 10:19:53 -0500
Update of /cvs-repository/Zope3/src/zope/app/event
In directory cvs.zope.org:/tmp/cvs-serv5632/src/zope/app/event
Modified Files:
subs.py
Log Message:
Fixed bug in event service where it was subscribing three times
to its parent event service. This was revealed by a unit test when the
erroneous 'Subscriptions' service id was replaced with the symbolic
constant. One bug had hidden the other. Symbolic service names are a
good idea.
=== Zope3/src/zope/app/event/subs.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/event/subs.py:1.9 Mon Feb 17 13:22:02 2003
+++ Zope3/src/zope/app/event/subs.py Tue Feb 18 10:19:22 2003
@@ -32,7 +32,7 @@
from zope.app.interfaces.event import IEvent, ISubscriber, ISubscribable
from zope.app.interfaces.event import ISubscribingAware
-from zope.component import getService, getAdapter, queryAdapter
+from zope.component import getService, queryService, getAdapter, queryAdapter
from zope.component import ComponentLookupError
from zope.app.services.servicenames import HubIds
from zope.app.services.type import PersistentTypeRegistry
@@ -79,13 +79,19 @@
if not event_type.extends(IEvent, strict=False):
raise TypeError('event_type must be IEvent or extend IEvent',
event_type)
- reftype, token, wrapped_object = getWayToSubscribe(
+ reftype, token, wrapped_object, clean_object = getWayToSubscribe(
wrapped_self, reference)
+
# If wrapped_object is None, the object can't be traversed to,
# so raise an exception
if wrapped_object is None:
raise NotFoundError(reference)
+ clean_self = removeAllProxies(wrapped_self)
+
+ if clean_object is clean_self:
+ raise RuntimeError("Cannot subscribe to self")
+
# Check that ISubscriber adapter exists for the wrapped object.
# This will raise an error if there is no such adapter.
getAdapter(wrapped_object, ISubscriber)
@@ -96,8 +102,6 @@
else:
ev_type = event_type
- clean_self = removeAllProxies(wrapped_self)
-
subscribers = clean_self._registry.get(ev_type)
if subscribers is None:
subscribers = []
@@ -463,11 +467,11 @@
clean, wrapped, path, hubId, reftype = getWaysToSubscribe(
context, reference, allways=False)
if reftype is unicode or hubId is None:
- return unicode, path, wrapped
+ return unicode, path, wrapped, clean
if path is None and hubId is None:
raise Exception('Can get neither path nor hubId for reference',
reference)
- return int, hubId, wrapped
+ return int, hubId, wrapped, clean
def getWaysToSubscribe(context, reference, allways=True):
'''Get the various means of subscription available for the given
@@ -514,11 +518,8 @@
else:
cleanobj = removeAllProxies(wrappedobj)
if allways:
- try:
- hub = getService(context, HubIds)
- except ComponentLookupError:
- pass
- else:
+ hub = queryService(context, HubIds)
+ if hub is not None:
try:
hubId = hub.getHubId(path)
except NotFoundError:
@@ -528,11 +529,8 @@
wrappedobj = reference
cleanobj = clean_reference
path = getPhysicalPathString(wrappedobj)
- try:
- hub = getService(context, HubIds)
- except ComponentLookupError:
- pass
- else:
+ hub = queryService(context, HubIds)
+ if hub is not None:
try:
hubId = hub.getHubId(path)
except NotFoundError: