~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-20 10:31:42 UTC
  • mfrom: (13333.11.5 longpoll-event-decorator)
  • Revision ID: launchpad@pqm.canonical.com-20110920103142-uajrh8zg13215msf
[r=jtv, rvb][no-qa] New class decorator to make declaration of an
 ILongPollEvent simpler and less error prone.

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",
10
11
    ]
11
12
 
12
 
 
 
13
from zope.component import adapter
13
14
from zope.interface import (
14
15
    Attribute,
 
16
    classImplements,
15
17
    Interface,
16
18
    )
17
19
 
49
51
 
50
52
        :type event: ILongPollEvent
51
53
        """
 
54
 
 
55
 
 
56
def long_poll_event(source_spec, event_spec=basestring):
 
57
    """Class decorator to declare an `ILongPollEvent`.
 
58
 
 
59
    :param source_spec: An interface or other specification understood by
 
60
        `zope.component` (a plain class can be passed too) that defines the
 
61
        source of an event. `IJob` or `storm.base.Storm` for example.
 
62
    :param source_event: An interface or other specification understood by
 
63
        `zope.component`. The exact use here is left to implementers. By
 
64
        default it is `basestring` so that terms like "modified" or
 
65
        "lifecycle" can be used when looking up the event, but it could also
 
66
        be `IObjectModifiedEvent`. The dominant use case is evolving.
 
67
    """
 
68
    declare_adapter = adapter(source_spec, event_spec)
 
69
 
 
70
    def declare_event(cls):
 
71
        classImplements(cls, ILongPollEvent)
 
72
        declare_adapter(cls)
 
73
        return cls
 
74
 
 
75
    return declare_event