18
18
19
19
20
20
class Observable (object ):
21
- """
22
- Provide notification support for classes that maintain dynamic associations with multiple
23
- clients.
21
+ """Provide notification support for classes that maintain dynamic
22
+ associations with multiple clients.
24
23
25
24
Observers, i.e. clients of the observable, register event handlers that will be invoked to
26
25
notify them whenever something interesting happens to the observable. The nature of what is
@@ -41,9 +40,7 @@ class Observable(object):
41
40
42
41
43
42
def notify (self , other = ()):
44
- """
45
- Notify all observers
46
- """
43
+ """Notify all observers."""
47
44
# build a list before notification, just in case the observer's callback behavior
48
45
# involves removing itself from our callback set
49
46
semaphors = (self ,) + other
@@ -54,27 +51,21 @@ def notify(self, other=()):
54
51
55
52
# callback management
56
53
def addObserver (self , callable ):
57
- """
58
- Add callable to the set of observers
59
- """
54
+ """Add callable to the set of observers."""
60
55
f = weak_ref (callable , fallback = _fbRemoveObserver )
61
56
self ._observers .add (f )
62
57
return
63
58
64
59
65
60
def removeObserver (self , callable ):
66
- """
67
- Remove callable from the set of observers
68
- """
61
+ """Remove callable from the set of observers."""
69
62
f = weak_ref (callable )
70
63
self ._observers .remove (f )
71
64
return
72
65
73
66
74
67
def hasObserver (self , callable ):
75
- """
76
- True if `callable` is present in the set of observers.
77
- """
68
+ """True if `callable` is present in the set of observers."""
78
69
f = weak_ref (callable )
79
70
rv = f in self ._observers
80
71
return rv
0 commit comments