31
31
class LongPollEvent:
32
32
"""Base-class for event adapters.
34
Sub-classes need to declare something along the lines of:
36
adapts(Interface, Interface)
37
implements(ILongPollEvent)
34
Sub-classes need to define the `event_key` property and declare something
37
class LongPollAwesomeThingEvent(LongPollEvent):
39
implements(ILongPollEvent)
41
Alternatively, use the `long_poll_event` class decorator::
43
@long_poll_event(IAwesomeThing)
44
class LongPollAwesomeThingEvent(LongPollEvent):
47
In both cases the adapter should be registered in a `configure.zcml`
50
<adapter factory=".adapters.LongPollAwesomeThingEvent" />
41
def __init__(self, source, event):
54
def __init__(self, source):
42
55
self.source = source
46
58
def event_key(self):
47
59
"""See `ILongPollEvent`."""
48
60
raise NotImplementedError(self.__class__.event_key)
51
"""See `ILongPollEvent`."""
52
payload = {"event_key": self.event_key, "event_data": data}
53
router = router_factory(self.event_key)
62
def emit(self, **data):
63
"""See `ILongPollEvent`.
65
The data will be updated with `event_key`, a copy of `self.event_key`.
67
event_key = self.event_key
68
data.update(event_key=event_key)
69
router = router_factory(event_key)