[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/LocalEventService - LocalServiceSubscribable.py:1.5 LocalSubscribable.py:1.4
Gary Poster
garyposter@earthlink.net
Thu, 5 Sep 2002 22:14:32 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/LocalEventService
In directory cvs.zope.org:/tmp/cvs-serv2358
Modified Files:
LocalServiceSubscribable.py LocalSubscribable.py
Log Message:
Fixed bug in LocalSubscribable and LocalServiceSubscribable (a 'self' should have been a 'wrapped_self'). Replaced the blah = blah persistence trick with _p_changed (as per discussion list) for these two files only. Beautified two files hopefully as per style guide, or at least closer to it. Wrote yet another event service test so we would have one that would have caught the bug (actually the test would only catch the bug in LocalServiceSubscribable, not LocalSubscribable--when something uses the LocalSubscribable mixin, it can test it.)
=== Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/LocalServiceSubscribable.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/LocalServiceSubscribable.py:1.4 Thu Aug 1 14:42:11 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/LocalServiceSubscribable.py Thu Sep 5 22:14:31 2002
@@ -30,32 +30,37 @@
class LocalServiceSubscribable(LocalSubscribable, Persistent):
"""a local mix-in for services"""
- _serviceName=None # replace me
+ _serviceName = None # replace me
- def unsubscribe(wrapped_self, subscriber, event_type=None, filter=None):
- subscriber=removeAllProxies(subscriber) # might be wrapped, might not
+ def unsubscribe(wrapped_self,
+ subscriber,
+ event_type = None,
+ filter = None):
+ # might be wrapped, might not
+ subscriber = removeAllProxies(subscriber)
- clean_self=removeAllProxies(wrapped_self)
- wrapped_subscriber=ContextWrapper(subscriber, wrapped_self)
+ clean_self = removeAllProxies(wrapped_self)
+ wrapped_subscriber = ContextWrapper(subscriber, wrapped_self)
for subscriber_index in range(len(clean_self._subscribers)):
- sub=clean_self._subscribers[subscriber_index]
- if sub[0]==subscriber:
- ev_set=sub[1]
+ sub = clean_self._subscribers[subscriber_index]
+ if sub[0] == subscriber:
+ ev_set = sub[1]
break
else:
# raise NotFoundError(subscriber)
- getNextService(wrapped_self, clean_self._serviceName).unsubscribe(
- subscriber, event_type, filter)
+ getNextService(
+ wrapped_self, clean_self._serviceName).unsubscribe(
+ subscriber, event_type, filter)
return
- do_alert=ISubscriptionAware.isImplementedBy(subscriber)
+ do_alert = ISubscriptionAware.isImplementedBy(subscriber)
if event_type:
- ev_type=event_type
+ ev_type = event_type
if event_type is IEvent:
- ev_type=None # handle optimization
+ ev_type = None # handle optimization
if ev_type not in ev_set:
getNextService(
wrapped_self, clean_self._serviceName).unsubscribe(
@@ -68,42 +73,45 @@
raise NotFoundError(subscriber, event_type, filter)
if do_alert:
wrapped_subscriber.unsubscribedFrom(
- self, event_type, filter)
- if len(ev_set)==1:
+ wrapped_self, event_type, filter)
+ if len(ev_set) == 1:
for sub in subscriptions:
- if sub[0]==subscriber:
+ if sub[0] == subscriber:
break
else:
del clean_self._subscribers[subscriber_index]
else:
for ev_type in ev_set:
subscriptions = clean_self._registry.get(ev_type)
- subs=subscriptions[:]
+ subs = subscriptions[:]
subscriptions[:] = []
for sub in subs:
if sub[0] == subscriber: # deleted (not added back)
if do_alert:
wrapped_subscriber.unsubscribedFrom(
wrapped_self, ev_type or IEvent, sub[1])
- # IEvent switch is to make optimization transparent
+ # IEvent switch is to make optimization
+ # transparent
else: # kept (added back)
subscriptions.append(sub)
del clean_self._subscribers[subscriber_index]
- getNextService(wrapped_self, clean_self._serviceName).unsubscribe(
- subscriber, event_type, filter)
- clean_self._registry=clean_self._registry #trigger persistence
+ getNextService(
+ wrapped_self, clean_self._serviceName).unsubscribe(
+ subscriber, event_type, filter)
+ clean_self._p_changed = 1 #trigger persistence
- unsubscribe=ContextMethod(unsubscribe)
+ unsubscribe = ContextMethod(unsubscribe)
- def listSubscriptions(wrapped_self, subscriber, event_type=None):
- subscriber=removeAllProxies(subscriber) # might be wrapped, might not
+ def listSubscriptions(wrapped_self, subscriber, event_type = None):
+ # might be wrapped, might not
+ subscriber = removeAllProxies(subscriber)
- clean_self=removeAllProxies(wrapped_self)
- result=LocalSubscribable.listSubscriptions(
+ clean_self = removeAllProxies(wrapped_self)
+ result = LocalSubscribable.listSubscriptions(
clean_self, subscriber, event_type)
result.extend(getNextService(
wrapped_self, clean_self._serviceName).listSubscriptions(
subscriber, event_type))
return result
- listSubscriptions=ContextMethod(listSubscriptions)
+ listSubscriptions = ContextMethod(listSubscriptions)
=== Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/LocalSubscribable.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/LocalSubscribable.py:1.3 Thu Aug 1 11:33:43 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/LocalEventService/LocalSubscribable.py Thu Sep 5 22:14:31 2002
@@ -29,17 +29,24 @@
class LocalSubscribable(Subscribable, Persistent):
"""a local mix-in"""
- def subscribe(wrapped_self, subscriber, event_type=IEvent, filter=None):
- subscriber=removeAllProxies(subscriber) # might be wrapped, might not
+ def subscribe(wrapped_self,
+ subscriber,
+ event_type=IEvent,
+ filter=None):
+ # might be wrapped, might not
+ subscriber = removeAllProxies(subscriber)
- clean_self=removeAllProxies(wrapped_self)
- wrapped_subscriber=ContextWrapper(subscriber, wrapped_self)
+ clean_self = removeAllProxies(wrapped_self)
+ wrapped_subscriber = ContextWrapper(subscriber, wrapped_self)
if ISubscriptionAware.isImplementedBy(subscriber):
- wrapped_subscriber.subscribedTo(wrapped_self, event_type, filter)
+ wrapped_subscriber.subscribedTo(
+ wrapped_self,
+ event_type,
+ filter)
- ev_type=event_type
- if ev_type is IEvent: ev_type=None # optimization
+ ev_type = event_type
+ if ev_type is IEvent: ev_type = None # optimization
subscribers = clean_self._registry.get(ev_type)
if subscribers is None:
@@ -49,38 +56,42 @@
subs = clean_self._subscribers
for sub in subs:
- if sub[0]==subscriber:
- sub[1][ev_type]=1
+ if sub[0] == subscriber:
+ sub[1][ev_type] = 1
break
else:
subs.append((subscriber,{ev_type:1}))
- clean_self._registry=clean_self._registry #trigger persistence
+ clean_self._p_changed = 1 #trigger persistence
subscribe=ContextMethod(subscribe)
- def unsubscribe(wrapped_self, subscriber, event_type=None, filter=None):
- subscriber=removeAllProxies(subscriber) # might be wrapped, might not
+ def unsubscribe(wrapped_self,
+ subscriber,
+ event_type = None,
+ filter = None):
+ # subscriber might be wrapped, might not
+ subscriber = removeAllProxies(subscriber)
- clean_self=removeAllProxies(wrapped_self)
- wrapped_subscriber=ContextWrapper(subscriber, wrapped_self)
+ clean_self = removeAllProxies(wrapped_self)
+ wrapped_subscriber = ContextWrapper(subscriber, wrapped_self)
for subscriber_index in range(len(clean_self._subscribers)):
- sub=clean_self._subscribers[subscriber_index]
- if sub[0]==subscriber:
- ev_set=sub[1]
+ sub = clean_self._subscribers[subscriber_index]
+ if sub[0] == subscriber:
+ ev_set = sub[1]
break
else:
raise NotFoundError(subscriber)
- do_alert=ISubscriptionAware.isImplementedBy(subscriber)
+ do_alert = ISubscriptionAware.isImplementedBy(subscriber)
if event_type:
- ev_type=event_type
+ ev_type = event_type
if event_type is IEvent:
- ev_type=None # handle optimization
+ ev_type = None # handle optimization
if ev_type not in ev_set:
raise NotFoundError(subscriber, event_type, filter)
subscriptions = clean_self._registry.get(ev_type)
@@ -91,10 +102,11 @@
except ValueError:
raise NotFoundError(subscriber, event_type, filter)
if do_alert:
- wrapped_subscriber.unsubscribedFrom(self, event_type, filter)
- if len(ev_set)==1:
+ wrapped_subscriber.unsubscribedFrom(
+ wrapped_self, event_type, filter)
+ if len(ev_set) == 1:
for sub in subscriptions:
- if sub[0]==subscriber:
+ if sub[0] == subscriber:
break
else:
del clean_self._subscribers[subscriber_index]
@@ -108,10 +120,11 @@
if do_alert:
wrapped_subscriber.unsubscribedFrom(
wrapped_self, ev_type or IEvent, sub[1])
- # IEvent switch is to make optimization transparent
+ # IEvent switch is to make optimization
+ # transparent
else: # kept (added back)
subscriptions.append(sub)
del clean_self._subscribers[subscriber_index]
- clean_self._registry=clean_self._registry #trigger persistence
+ clean_self._p_changed = 1
- unsubscribe=ContextMethod(unsubscribe)
+ unsubscribe = ContextMethod(unsubscribe)