1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import inspect
16 from weakref import WeakKeyDictionary
17
18 try:
19 from weakref import WeakSet
20 except ImportError:
21 from weakrefset import WeakSet
22
23
26 self._functions = WeakSet()
27 self._methods = WeakKeyDictionary()
28
30 for f in self._functions:
31 f(*args, **kargs)
32
33 for obj, functions in self._methods.items():
34 for f in functions:
35 f(obj, *args, **kargs)
36
38 if inspect.ismethod(slot):
39 if not slot.__self__ in self._methods:
40 self._methods[slot.__self__] = set()
41 self._methods[slot.__self__].add(slot.__func__)
42 else:
43 self._functions.add(slot)
44
46 if inspect.ismethod(slot):
47 if slot.__self__ in self._methods:
48 self._methods[slot.__self__].remove(slot.__func__)
49 else:
50 if slot in self._functions:
51 self._functions.remove(slot)
52