Merge lp:~cjwatson/storm/docstring-event into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 564
Proposed branch: lp:~cjwatson/storm/docstring-event
Merge into: lp:storm
Diff against target: 67 lines (+39/-0)
1 file modified
storm/event.py (+39/-0)
To merge this branch: bzr merge lp:~cjwatson/storm/docstring-event
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Storm Developers Pending
Review via email: mp+384860@code.launchpad.net

Commit message

Add docstrings for storm.event.EventSystem.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'storm/event.py'
--- storm/event.py 2019-06-05 11:41:07 +0000
+++ storm/event.py 2020-05-29 22:16:29 +0000
@@ -29,12 +29,35 @@
2929
3030
31class EventSystem(object):31class EventSystem(object):
32 """A system for managing hooks that are called when events are emitted.
33
34 Hooks are callables that take the event system C{owner} as their first
35 argument, followed by the arguments passed when emitting the event,
36 followed by any additional C{data} arguments given when registering the
37 hook.
38
39 Hooks registered for a given event C{name} are stored without ordering:
40 no particular call order may be assumed when an event is emitted.
41 """
3242
33 def __init__(self, owner):43 def __init__(self, owner):
44 """
45 @param owner: The object that owns this event system. It is passed
46 as the first argument to each hook function.
47 """
34 self._owner_ref = weakref.ref(owner)48 self._owner_ref = weakref.ref(owner)
35 self._hooks = {}49 self._hooks = {}
3650
37 def hook(self, name, callback, *data):51 def hook(self, name, callback, *data):
52 """Register a hook.
53
54 @param name: The name of the event for which this hook should be
55 called.
56 @param callback: A callable which should be called when the event is
57 emitted.
58 @param data: Additional arguments to pass to the callable, after the
59 C{owner} and any arguments passed when emitting the event.
60 """
38 callbacks = self._hooks.get(name)61 callbacks = self._hooks.get(name)
39 if callbacks is None:62 if callbacks is None:
40 self._hooks.setdefault(name, set()).add((callback, data))63 self._hooks.setdefault(name, set()).add((callback, data))
@@ -42,11 +65,27 @@
42 callbacks.add((callback, data))65 callbacks.add((callback, data))
4366
44 def unhook(self, name, callback, *data):67 def unhook(self, name, callback, *data):
68 """Unregister a hook.
69
70 This ignores attempts to unregister hooks that were not already
71 registered.
72
73 @param name: The name of the event for which this hook should no
74 longer be called.
75 @param callback: The callable to unregister.
76 @param data: Additional arguments that were passed when registering
77 the callable.
78 """
45 callbacks = self._hooks.get(name)79 callbacks = self._hooks.get(name)
46 if callbacks is not None:80 if callbacks is not None:
47 callbacks.discard((callback, data))81 callbacks.discard((callback, data))
4882
49 def emit(self, name, *args):83 def emit(self, name, *args):
84 """Emit an event, calling any registered hooks.
85
86 @param name: The name of the event.
87 @param args: Additional arguments to pass to hooks.
88 """
50 owner = self._owner_ref()89 owner = self._owner_ref()
51 if owner is not None:90 if owner is not None:
52 callbacks = self._hooks.get(name)91 callbacks = self._hooks.get(name)

Subscribers

People subscribed via source and target branches

to status/vote changes: