/usr/share/pyshared/nevow/events.py is in python-nevow 0.10.0-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # Copyright (c) 2004 Divmod.
# See LICENSE for details.
DEBUG = False
class EventNotification:
def __init__(self):
self._subscribers = {}
self._currentId = 0
def subscribe(self, identifier, subscriber):
"""Subscribe to events sent to the given identifier.
Returns a token which should be passed to unsubscribe when done.
"""
if DEBUG:
print "SUBSCRIBE", self, identifier, subscriber
self._subscribers.setdefault(identifier, []).append(subscriber)
return identifier, subscriber
def unsubscribe(self, token):
"""Unsubscribe the given token from events.
"""
if DEBUG:
print "UNSUBSCRIBE", token
identifier, reference = token
self._subscribers[identifier].remove(reference)
def publish(self, identifier, *args):
"""Notify the listeners on a given identifier that an event has occurred.
"""
if DEBUG:
print "PUBLISH", self, identifier,
subscribers = self._subscribers.get(identifier, [])
for sub in subscribers:
sub(*args)
if DEBUG:
print "NOTIFY SUBSCRIBER", sub
if DEBUG:
print "done"
def nextId(self):
self._currentId += 1
return str(self._currentId)
def __getstate__(self):
d = self.__dict__.copy()
d['_subscribers'] = {}
d['_currentId'] = 0
return d
|