python-dispatch 0.2.2__py3-none-any.whl → 0.2.41__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pydispatch/aioutils.py +21 -3
- pydispatch/decorators.py +8 -9
- pydispatch/dispatch.py +10 -8
- pydispatch/properties.py +6 -2
- pydispatch/utils.py +10 -3
- {python_dispatch-0.2.2.dist-info → python_dispatch-0.2.41.dist-info}/METADATA +21 -25
- python_dispatch-0.2.41.dist-info/RECORD +9 -0
- {python_dispatch-0.2.2.dist-info → python_dispatch-0.2.41.dist-info}/WHEEL +1 -2
- python_dispatch-0.2.2.dist-info/LICENSE.txt +0 -21
- python_dispatch-0.2.2.dist-info/RECORD +0 -11
- python_dispatch-0.2.2.dist-info/top_level.txt +0 -1
pydispatch/aioutils.py
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
import sys
|
|
1
2
|
import asyncio
|
|
2
3
|
import threading
|
|
3
|
-
from
|
|
4
|
-
from
|
|
4
|
+
from weakref import ref
|
|
5
|
+
from _weakref import _remove_dead_weakref # type: ignore[import]
|
|
6
|
+
if sys.version_info < (3, 14):
|
|
7
|
+
from _weakrefset import _IterationGuard
|
|
8
|
+
else:
|
|
9
|
+
# _IterationGuard was removed in Python 3.14. We define a no-op version here
|
|
10
|
+
class _IterationGuard:
|
|
11
|
+
def __init__(self, obj):
|
|
12
|
+
pass
|
|
13
|
+
def __enter__(self):
|
|
14
|
+
pass
|
|
15
|
+
def __exit__(self, *args):
|
|
16
|
+
pass
|
|
17
|
+
|
|
5
18
|
|
|
6
19
|
from pydispatch.utils import (
|
|
7
20
|
WeakMethodContainer,
|
|
8
21
|
isfunction,
|
|
9
22
|
get_method_vars,
|
|
10
|
-
_remove_dead_weakref,
|
|
11
23
|
)
|
|
12
24
|
|
|
13
25
|
|
|
@@ -192,6 +204,12 @@ class AioWeakMethodContainer(WeakMethodContainer):
|
|
|
192
204
|
_remove_dead_weakref(self.data, wr.key)
|
|
193
205
|
self._on_weakref_fin(wr.key)
|
|
194
206
|
self._remove = remove
|
|
207
|
+
|
|
208
|
+
# `_pending_removals` and `_iterating` were removed in Python 3.14.
|
|
209
|
+
# To maintain compatibility with earlier versions, we reintroduce them here.
|
|
210
|
+
self._pending_removals = []
|
|
211
|
+
self._iterating = set()
|
|
212
|
+
|
|
195
213
|
self.event_loop_map = {}
|
|
196
214
|
def add_method(self, loop, callback):
|
|
197
215
|
"""Add a coroutine function
|
pydispatch/decorators.py
CHANGED
|
@@ -124,12 +124,11 @@ def _post_register_hook(*names):
|
|
|
124
124
|
"""Called in :func:`pydispatch.register_event` to search for cached callbacks
|
|
125
125
|
"""
|
|
126
126
|
for name in names:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
pydispatch.bind(**bind_kwargs)
|
|
127
|
+
loop = None
|
|
128
|
+
for callback in _CACHED_CALLBACKS.get(name):
|
|
129
|
+
if iscoroutinefunction(callback):
|
|
130
|
+
if loop is None:
|
|
131
|
+
loop = asyncio.get_event_loop()
|
|
132
|
+
pydispatch.bind_async(loop, **{name: callback})
|
|
133
|
+
else:
|
|
134
|
+
pydispatch.bind(**{name: callback})
|
pydispatch/dispatch.py
CHANGED
|
@@ -209,14 +209,16 @@ class Dispatcher(object):
|
|
|
209
209
|
... async def on_foo_test_event(self, *args, **kwargs):
|
|
210
210
|
... self.got_foo_event.set()
|
|
211
211
|
|
|
212
|
-
>>>
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
212
|
+
>>> async def main():
|
|
213
|
+
... loop = asyncio.get_running_loop()
|
|
214
|
+
... foo = Foo()
|
|
215
|
+
... bar = Bar()
|
|
216
|
+
... foo.bind(test_event=bar.on_foo_test_event, __aio_loop__=loop)
|
|
217
|
+
... fut = asyncio.create_task(bar.wait_for_foo())
|
|
218
|
+
... foo.emit('test_event')
|
|
219
|
+
... await fut
|
|
220
|
+
|
|
221
|
+
>>> asyncio.run(main())
|
|
220
222
|
got foo!
|
|
221
223
|
|
|
222
224
|
This can also be done using :meth:`bind_async`.
|
pydispatch/properties.py
CHANGED
|
@@ -331,10 +331,14 @@ class ObservableDict(dict, Observable):
|
|
|
331
331
|
super(ObservableDict, self).clear()
|
|
332
332
|
self._emit_change(old=old)
|
|
333
333
|
def pop(self, *args):
|
|
334
|
+
"""Return the removed value or default after emitting a change event."""
|
|
334
335
|
old = self._get_copy_or_none()
|
|
335
|
-
super(ObservableDict, self).pop(*args)
|
|
336
|
+
value = super(ObservableDict, self).pop(*args)
|
|
336
337
|
self._emit_change(old=old)
|
|
338
|
+
return value
|
|
337
339
|
def setdefault(self, *args):
|
|
340
|
+
"""Return the existing or inserted value and notify on successful calls."""
|
|
338
341
|
old = self._get_copy_or_none()
|
|
339
|
-
super(ObservableDict, self).setdefault(*args)
|
|
342
|
+
value = super(ObservableDict, self).setdefault(*args)
|
|
340
343
|
self._emit_change(old=old)
|
|
344
|
+
return value
|
pydispatch/utils.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import weakref
|
|
2
|
-
from weakref import ref
|
|
3
|
-
from _weakref import
|
|
2
|
+
from weakref import ref
|
|
3
|
+
from _weakref import _remove_dead_weakref # type: ignore[import]
|
|
4
4
|
import types
|
|
5
5
|
import asyncio
|
|
6
|
+
import inspect
|
|
6
7
|
|
|
7
8
|
def get_method_vars(m):
|
|
8
9
|
f = m.__func__
|
|
@@ -13,7 +14,7 @@ def isfunction(m):
|
|
|
13
14
|
return isinstance(m, types.FunctionType)
|
|
14
15
|
|
|
15
16
|
def iscoroutinefunction(obj):
|
|
16
|
-
return
|
|
17
|
+
return inspect.iscoroutinefunction(obj)
|
|
17
18
|
|
|
18
19
|
class WeakMethodContainer(weakref.WeakValueDictionary):
|
|
19
20
|
"""Container to store weak references to callbacks
|
|
@@ -114,6 +115,12 @@ class InformativeWVDict(weakref.WeakValueDictionary):
|
|
|
114
115
|
_remove_dead_weakref(self.data, wr.key)
|
|
115
116
|
self._data_del_callback(wr.key)
|
|
116
117
|
self._remove = remove
|
|
118
|
+
|
|
119
|
+
# `_pending_removals` and `_iterating` were removed in Python 3.14.
|
|
120
|
+
# To maintain compatibility with earlier versions, we reintroduce them here.
|
|
121
|
+
self._pending_removals = []
|
|
122
|
+
self._iterating = set()
|
|
123
|
+
|
|
117
124
|
self.data = InformativeDict()
|
|
118
125
|
self.data.del_callback = self._data_del_callback
|
|
119
126
|
def _data_del_callback(self, key):
|
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: python-dispatch
|
|
3
|
-
Version: 0.2.
|
|
4
|
-
Summary: Lightweight Event Handling
|
|
5
|
-
|
|
3
|
+
Version: 0.2.41
|
|
4
|
+
Summary: Lightweight Event Handling Library for Python
|
|
5
|
+
Keywords: event,properties,dispatch
|
|
6
6
|
Author: Matthew Reid
|
|
7
|
-
Author-email: matt@nomadic-recording.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Project-URL: Documentation, https://python-dispatch.readthedocs.io
|
|
10
|
-
Project-URL: Source, https://github.com/nocarryr/python-dispatch
|
|
11
|
-
Project-URL: Tracker, https://github.com/nocarryr/python-dispatch/issues
|
|
12
|
-
Keywords: event properties dispatch
|
|
13
|
-
Platform: any
|
|
7
|
+
Author-email: Matthew Reid <matt@nomadic-recording.com>
|
|
8
|
+
License-Expression: MIT
|
|
14
9
|
Classifier: Development Status :: 3 - Alpha
|
|
15
10
|
Classifier: Intended Audience :: Developers
|
|
16
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
17
11
|
Classifier: Operating System :: OS Independent
|
|
18
12
|
Classifier: Programming Language :: Python
|
|
19
13
|
Classifier: Topic :: Software Development
|
|
20
14
|
Classifier: Programming Language :: Python :: 3
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
24
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
25
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
26
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
27
19
|
Classifier: Topic :: Software Development :: Libraries
|
|
28
20
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Project-URL: Documentation, https://python-dispatch.readthedocs.io/
|
|
23
|
+
Project-URL: Source, https://github.com/nocarryr/python-dispatch
|
|
24
|
+
Project-URL: Download, https://pypi.org/project/python-dispatch/
|
|
25
|
+
Project-URL: Tracker, https://github.com/nocarryr/python-dispatch/issues
|
|
29
26
|
Description-Content-Type: text/markdown
|
|
30
|
-
License-File: LICENSE.txt
|
|
31
27
|
|
|
32
28
|
# python-dispatch
|
|
33
29
|
Lightweight event handling for Python
|
|
34
30
|
|
|
35
|
-
[](https://github.com/astral-sh/uv)[](https://coveralls.io/github/nocarryr/python-dispatch?branch=master)[](https://badge.fury.io/py/python-dispatch)[](https://raw.githubusercontent.com/nocarryr/python-dispatch/master/LICENSE.txt)
|
|
36
32
|
|
|
37
33
|
## Description
|
|
38
34
|
This is an implementation of the "Observer Pattern" with inspiration from the
|
|
39
|
-
[Kivy](kivy.org) framework. Many of the features though are intentionally
|
|
35
|
+
[Kivy](https://kivy.org) framework. Many of the features though are intentionally
|
|
40
36
|
stripped down and more generalized. The goal is to have a simple drop-in
|
|
41
37
|
library with no dependencies that stays out of the programmer's way.
|
|
42
38
|
|
|
@@ -68,9 +64,9 @@ pip install python-dispatch<0.2
|
|
|
68
64
|
|
|
69
65
|
| | |
|
|
70
66
|
| -------------:|:-------------------------------------------- |
|
|
71
|
-
| Project Home | https://github.com/nocarryr/python-dispatch
|
|
72
|
-
| PyPI | https://pypi.python.org/pypi/python-dispatch |
|
|
73
|
-
| Documentation | https://python-dispatch.readthedocs.io
|
|
67
|
+
| Project Home | [https://github.com/nocarryr/python-dispatch](https://github.com/nocarryr/python-dispatch) |
|
|
68
|
+
| PyPI | [https://pypi.python.org/pypi/python-dispatch](https://pypi.python.org/pypi/python-dispatch) |
|
|
69
|
+
| Documentation | [https://python-dispatch.readthedocs.io](https://python-dispatch.readthedocs.io) |
|
|
74
70
|
|
|
75
71
|
|
|
76
72
|
## Usage
|
|
@@ -149,9 +145,9 @@ emitter value is 42
|
|
|
149
145
|
Contributions are welcome!
|
|
150
146
|
|
|
151
147
|
If you want to contribute through code or documentation, please see the
|
|
152
|
-
[Contributing Guide](CONTRIBUTING.md) for information.
|
|
148
|
+
[Contributing Guide](https://github.com/nocarryr/python-dispatch/blob/master/CONTRIBUTING.md) for information.
|
|
153
149
|
|
|
154
150
|
## License
|
|
155
151
|
|
|
156
|
-
This project is released under the MIT License. See the [LICENSE](LICENSE.txt) file
|
|
152
|
+
This project is released under the MIT License. See the [LICENSE](https://github.com/nocarryr/python-dispatch/blob/master/LICENSE.txt) file
|
|
157
153
|
for more information.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pydispatch/__init__.py,sha256=qt4QDOYq_QGq0bMZizAvnhhzLr7LkZe9PBHilTjc74Y,2190
|
|
2
|
+
pydispatch/aioutils.py,sha256=tv-ddi8tMwqtOJGNqONYb2Y-PKXyOJG4wsX3EzmgBsw,9848
|
|
3
|
+
pydispatch/decorators.py,sha256=MJaRKu3lziYSMLAIpFAgsAcLoSLlbRyWHoioSDKgRKM,4160
|
|
4
|
+
pydispatch/dispatch.py,sha256=Jbb7bl7kdsXlfQsCM8Jehui7qpSH1GhawEgPLk-lyAo,13508
|
|
5
|
+
pydispatch/properties.py,sha256=15krCVGV17lUi9VG2ZyEZvz3AxoQ385IBoLqHmBKPSM,13361
|
|
6
|
+
pydispatch/utils.py,sha256=S50sMdx32YYthvCRRwV1ivdwtw7xXmopozy3aLDypa0,6550
|
|
7
|
+
python_dispatch-0.2.41.dist-info/WHEEL,sha256=MWx7psoF7KNST9G72pGtiBYuaXRXQXBk9pw5R6FzYko,80
|
|
8
|
+
python_dispatch-0.2.41.dist-info/METADATA,sha256=CE9c463Vl195iRe52nu2MVUUH_7Nc6vkb9Ee3T0HFFI,5839
|
|
9
|
+
python_dispatch-0.2.41.dist-info/RECORD,,
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2016 Matthew Reid
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
pydispatch/__init__.py,sha256=qt4QDOYq_QGq0bMZizAvnhhzLr7LkZe9PBHilTjc74Y,2190
|
|
2
|
-
pydispatch/aioutils.py,sha256=aDva5oh_VV5Rkfc-NWI8cR5ut-91t0engnv781z9zsk,9270
|
|
3
|
-
pydispatch/decorators.py,sha256=FFts0T9wvTVAgC9KGZSkpn_Nneecl1gAzufgP6nI4iQ,4213
|
|
4
|
-
pydispatch/dispatch.py,sha256=lkBvZVbUmFppvEiCO2n-_61TmJ-awHA4tRsq_-p6alA,13429
|
|
5
|
-
pydispatch/properties.py,sha256=Pt4J32bqz3xT5BwmIO3Idl8vmkNbei2R0g_Vqwi7RH0,13138
|
|
6
|
-
pydispatch/utils.py,sha256=BtsIfRJxweCRDJHnXiR8YTXLF9c7DJy7tVF3isL4n3A,6286
|
|
7
|
-
python_dispatch-0.2.2.dist-info/LICENSE.txt,sha256=muuSBeZ0K6AotNoWadQaHzGO9CtXBFBemAsXRL170tA,1069
|
|
8
|
-
python_dispatch-0.2.2.dist-info/METADATA,sha256=XOQqOwQ1KYMsnlgSXMdZShaWOlv1fAI-hbbZCXxjGTE,5558
|
|
9
|
-
python_dispatch-0.2.2.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
|
10
|
-
python_dispatch-0.2.2.dist-info/top_level.txt,sha256=BW69gM2IyIPfFk8J13eRwxzVlic046roE3WH5bya5BI,11
|
|
11
|
-
python_dispatch-0.2.2.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pydispatch
|