~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/longpoll/interfaces.py

  • Committer: Steve Kowalik
  • Date: 2011-08-07 04:05:52 UTC
  • mto: This revision was merged to the branch mainline in revision 13626.
  • Revision ID: stevenk@ubuntu.com-20110807040552-mwnxo0flmhvl35e8
Correct the notification based on review comments, and remove request{,ed}
from the function names, switching to create{,d}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
__all__ = [
8
8
    "ILongPollEvent",
9
9
    "ILongPollSubscriber",
10
 
    "long_poll_event",
11
10
    ]
12
11
 
13
 
from zope.component import adapter
 
12
 
14
13
from zope.interface import (
15
14
    Attribute,
16
 
    classImplements,
17
15
    Interface,
18
16
    )
19
17
 
22
20
 
23
21
    source = Attribute("The event source.")
24
22
 
 
23
    event = Attribute("An object indicating the type of event.")
 
24
 
25
25
    event_key = Attribute(
26
26
        "The key with which events will be emitted. Should be predictable "
27
27
        "and stable.")
28
28
 
29
 
    def emit(**data):
 
29
    def emit(data):
30
30
        """Emit the given data to `event_key`.
31
31
 
32
 
        :param data: Any data structures that can be dumped as JSON.
 
32
        The data will be wrapped up into a `dict` with the keys `event_key`
 
33
        and `event_data`, where `event_key` is a copy of `self.event_key` and
 
34
        `event_data` is the `data` argument.
 
35
 
 
36
        :param data: Any data structure that can be dumped as JSON.
33
37
        """
34
38
 
35
39
 
45
49
 
46
50
        :type event: ILongPollEvent
47
51
        """
48
 
 
49
 
 
50
 
def long_poll_event(source_spec):
51
 
    """Class decorator to declare an `ILongPollEvent`.
52
 
 
53
 
    :param source_spec: An interface or other specification understood by
54
 
        `zope.component` (a plain class can be passed too) that defines the
55
 
        source of an event. `IJob` or `storm.base.Storm` for example.
56
 
    """
57
 
    declare_adapter = adapter(source_spec)
58
 
 
59
 
    def declare_event(cls):
60
 
        classImplements(cls, ILongPollEvent)
61
 
        declare_adapter(cls)
62
 
        return cls
63
 
 
64
 
    return declare_event