winloop 0.4.2__cp313-cp313-win32.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.
- winloop/__init__.py +221 -0
- winloop/_noop.py +3 -0
- winloop/_testbase.py +558 -0
- winloop/_version.py +13 -0
- winloop/cbhandles.pxd +39 -0
- winloop/cbhandles.pyx +434 -0
- winloop/dns.pyx +496 -0
- winloop/errors.pyx +89 -0
- winloop/handles/async_.pxd +11 -0
- winloop/handles/async_.pyx +56 -0
- winloop/handles/basetransport.pxd +54 -0
- winloop/handles/basetransport.pyx +293 -0
- winloop/handles/check.pxd +14 -0
- winloop/handles/check.pyx +72 -0
- winloop/handles/fsevent.pxd +12 -0
- winloop/handles/fsevent.pyx +116 -0
- winloop/handles/handle.pxd +60 -0
- winloop/handles/handle.pyx +423 -0
- winloop/handles/idle.pxd +14 -0
- winloop/handles/idle.pyx +72 -0
- winloop/handles/pipe.pxd +33 -0
- winloop/handles/pipe.pyx +249 -0
- winloop/handles/poll.pxd +25 -0
- winloop/handles/poll.pyx +237 -0
- winloop/handles/process.pxd +80 -0
- winloop/handles/process.pyx +850 -0
- winloop/handles/stream.pxd +50 -0
- winloop/handles/stream.pyx +1047 -0
- winloop/handles/streamserver.pxd +26 -0
- winloop/handles/streamserver.pyx +150 -0
- winloop/handles/tcp.pxd +26 -0
- winloop/handles/tcp.pyx +228 -0
- winloop/handles/timer.pxd +18 -0
- winloop/handles/timer.pyx +89 -0
- winloop/handles/udp.pxd +22 -0
- winloop/handles/udp.pyx +408 -0
- winloop/includes/__init__.py +23 -0
- winloop/includes/consts.pxi +34 -0
- winloop/includes/debug.pxd +3 -0
- winloop/includes/flowcontrol.pxd +23 -0
- winloop/includes/python.pxd +43 -0
- winloop/includes/stdlib.pxi +202 -0
- winloop/includes/system.pxd +83 -0
- winloop/includes/uv.pxd +520 -0
- winloop/loop.cp313-win32.pyd +0 -0
- winloop/loop.pxd +233 -0
- winloop/loop.pyi +301 -0
- winloop/loop.pyx +3564 -0
- winloop/lru.pyx +181 -0
- winloop/pseudosock.pyx +209 -0
- winloop/py.typed +0 -0
- winloop/request.pxd +8 -0
- winloop/request.pyx +65 -0
- winloop/server.pxd +19 -0
- winloop/server.pyx +136 -0
- winloop/shlex.pxd +38 -0
- winloop/shlex.pyx +346 -0
- winloop/sslproto.pxd +138 -0
- winloop/sslproto.pyx +950 -0
- winloop-0.4.2.dist-info/METADATA +326 -0
- winloop-0.4.2.dist-info/RECORD +65 -0
- winloop-0.4.2.dist-info/WHEEL +5 -0
- winloop-0.4.2.dist-info/licenses/LICENSE-APACHE +203 -0
- winloop-0.4.2.dist-info/licenses/LICENSE-MIT +21 -0
- winloop-0.4.2.dist-info/top_level.txt +1 -0
winloop/__init__.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import asyncio as __asyncio
|
|
2
|
+
import collections.abc as _collections_abc
|
|
3
|
+
import typing as _typing
|
|
4
|
+
import sys as _sys
|
|
5
|
+
import warnings as _warnings
|
|
6
|
+
|
|
7
|
+
from . import includes as __includes # NOQA
|
|
8
|
+
from .loop import Loop as __BaseLoop # NOQA
|
|
9
|
+
from ._version import __version__ # NOQA
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__: tuple[str, ...] = ("new_event_loop", "run")
|
|
13
|
+
_AbstractEventLoop = __asyncio.AbstractEventLoop
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
_T = _typing.TypeVar("_T")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Loop(__BaseLoop, _AbstractEventLoop): # type: ignore[misc]
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def new_event_loop() -> Loop:
|
|
24
|
+
"""Return a new event loop."""
|
|
25
|
+
return Loop()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if _typing.TYPE_CHECKING:
|
|
29
|
+
|
|
30
|
+
def run(
|
|
31
|
+
main: _collections_abc.Coroutine[_typing.Any, _typing.Any, _T],
|
|
32
|
+
*,
|
|
33
|
+
loop_factory: _collections_abc.Callable[[], Loop] | None = new_event_loop,
|
|
34
|
+
debug: bool | None = None,
|
|
35
|
+
) -> _T:
|
|
36
|
+
"""The preferred way of running a coroutine with winloop."""
|
|
37
|
+
else:
|
|
38
|
+
|
|
39
|
+
def run(main, *, loop_factory=new_event_loop, debug=None, **run_kwargs):
|
|
40
|
+
"""The preferred way of running a coroutine with winloop."""
|
|
41
|
+
|
|
42
|
+
async def wrapper():
|
|
43
|
+
# If `loop_factory` is provided we want it to return
|
|
44
|
+
# either winloop.Loop or a subtype of it, assuming the user
|
|
45
|
+
# is using `winloop.run()` intentionally.
|
|
46
|
+
loop = __asyncio._get_running_loop()
|
|
47
|
+
if not isinstance(loop, Loop):
|
|
48
|
+
raise TypeError("winloop.run() uses a non-winloop event loop")
|
|
49
|
+
return await main
|
|
50
|
+
|
|
51
|
+
vi = _sys.version_info[:2]
|
|
52
|
+
|
|
53
|
+
if vi <= (3, 10):
|
|
54
|
+
# Copied from python/cpython
|
|
55
|
+
|
|
56
|
+
if __asyncio._get_running_loop() is not None:
|
|
57
|
+
raise RuntimeError(
|
|
58
|
+
"asyncio.run() cannot be called from a running event loop"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
if not __asyncio.iscoroutine(main):
|
|
62
|
+
raise ValueError("a coroutine was expected, got {!r}".format(main))
|
|
63
|
+
|
|
64
|
+
loop = loop_factory()
|
|
65
|
+
try:
|
|
66
|
+
__asyncio.set_event_loop(loop)
|
|
67
|
+
if debug is not None:
|
|
68
|
+
loop.set_debug(debug)
|
|
69
|
+
return loop.run_until_complete(wrapper())
|
|
70
|
+
finally:
|
|
71
|
+
try:
|
|
72
|
+
_cancel_all_tasks(loop)
|
|
73
|
+
loop.run_until_complete(loop.shutdown_asyncgens())
|
|
74
|
+
if hasattr(loop, "shutdown_default_executor"):
|
|
75
|
+
loop.run_until_complete(loop.shutdown_default_executor())
|
|
76
|
+
finally:
|
|
77
|
+
__asyncio.set_event_loop(None)
|
|
78
|
+
loop.close()
|
|
79
|
+
|
|
80
|
+
elif vi == (3, 11):
|
|
81
|
+
if __asyncio._get_running_loop() is not None:
|
|
82
|
+
raise RuntimeError(
|
|
83
|
+
"asyncio.run() cannot be called from a running event loop"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
with __asyncio.Runner(
|
|
87
|
+
loop_factory=loop_factory, debug=debug, **run_kwargs
|
|
88
|
+
) as runner:
|
|
89
|
+
return runner.run(wrapper())
|
|
90
|
+
|
|
91
|
+
else:
|
|
92
|
+
assert vi >= (3, 12)
|
|
93
|
+
return __asyncio.run(
|
|
94
|
+
wrapper(), loop_factory=loop_factory, debug=debug, **run_kwargs
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _cancel_all_tasks(loop: _AbstractEventLoop) -> None:
|
|
99
|
+
# Copied from python/cpython
|
|
100
|
+
|
|
101
|
+
to_cancel = __asyncio.all_tasks(loop)
|
|
102
|
+
if not to_cancel:
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
for task in to_cancel:
|
|
106
|
+
task.cancel()
|
|
107
|
+
|
|
108
|
+
loop.run_until_complete(__asyncio.gather(*to_cancel, return_exceptions=True))
|
|
109
|
+
|
|
110
|
+
for task in to_cancel:
|
|
111
|
+
if task.cancelled():
|
|
112
|
+
continue
|
|
113
|
+
if task.exception() is not None:
|
|
114
|
+
loop.call_exception_handler(
|
|
115
|
+
{
|
|
116
|
+
"message": "unhandled exception during asyncio.run() shutdown",
|
|
117
|
+
"exception": task.exception(),
|
|
118
|
+
"task": task,
|
|
119
|
+
}
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
_deprecated_names = ("install", "EventLoopPolicy")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if _sys.version_info[:2] < (3, 16):
|
|
127
|
+
__all__ += _deprecated_names
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def __getattr__(name: str) -> _typing.Any:
|
|
131
|
+
if name not in _deprecated_names:
|
|
132
|
+
raise AttributeError(f"module 'winloop' has no attribute '{name}'")
|
|
133
|
+
elif _sys.version_info[:2] >= (3, 16):
|
|
134
|
+
raise AttributeError(
|
|
135
|
+
f"module 'winloop' has no attribute '{name}' "
|
|
136
|
+
f"(it was removed in Python 3.16, use winloop.run() instead)"
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
import threading
|
|
140
|
+
|
|
141
|
+
def install() -> None:
|
|
142
|
+
"""A helper function to install winloop policy.
|
|
143
|
+
|
|
144
|
+
This function is deprecated and will be removed in Python 3.16.
|
|
145
|
+
Use `winloop.run()` instead.
|
|
146
|
+
"""
|
|
147
|
+
if _sys.version_info[:2] >= (3, 12):
|
|
148
|
+
_warnings.warn(
|
|
149
|
+
"winloop.install() is deprecated in favor of winloop.run() "
|
|
150
|
+
"starting with Python 3.12.",
|
|
151
|
+
DeprecationWarning,
|
|
152
|
+
stacklevel=1,
|
|
153
|
+
)
|
|
154
|
+
__asyncio.set_event_loop_policy(EventLoopPolicy())
|
|
155
|
+
|
|
156
|
+
class EventLoopPolicy(
|
|
157
|
+
# This is to avoid a mypy error about AbstractEventLoopPolicy
|
|
158
|
+
getattr(__asyncio, "AbstractEventLoopPolicy") # type: ignore[misc]
|
|
159
|
+
):
|
|
160
|
+
"""Event loop policy for winloop.
|
|
161
|
+
|
|
162
|
+
This class is deprecated and will be removed in Python 3.16.
|
|
163
|
+
Use `winloop.run()` instead.
|
|
164
|
+
|
|
165
|
+
>>> import asyncio
|
|
166
|
+
>>> import winloop
|
|
167
|
+
>>> asyncio.set_event_loop_policy(winloop.EventLoopPolicy())
|
|
168
|
+
>>> asyncio.get_event_loop()
|
|
169
|
+
<winloop.Loop running=False closed=False debug=False>
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
def _loop_factory(self) -> Loop:
|
|
173
|
+
return new_event_loop()
|
|
174
|
+
|
|
175
|
+
if _typing.TYPE_CHECKING:
|
|
176
|
+
# EventLoopPolicy doesn't implement these, but since they are
|
|
177
|
+
# marked as abstract in typeshed, we have to put them in so mypy
|
|
178
|
+
# thinks the base methods are overridden. This is the same approach
|
|
179
|
+
# taken for the Windows event loop policy classes in typeshed.
|
|
180
|
+
def get_child_watcher(self) -> _typing.NoReturn: ...
|
|
181
|
+
|
|
182
|
+
def set_child_watcher(self, watcher: _typing.Any) -> _typing.NoReturn: ...
|
|
183
|
+
|
|
184
|
+
class _Local(threading.local):
|
|
185
|
+
_loop: _AbstractEventLoop | None = None
|
|
186
|
+
|
|
187
|
+
def __init__(self) -> None:
|
|
188
|
+
self._local = self._Local()
|
|
189
|
+
|
|
190
|
+
def get_event_loop(self) -> _AbstractEventLoop:
|
|
191
|
+
"""Get the event loop for the current context.
|
|
192
|
+
|
|
193
|
+
Returns an instance of EventLoop or raises an exception.
|
|
194
|
+
"""
|
|
195
|
+
if self._local._loop is None:
|
|
196
|
+
raise RuntimeError(
|
|
197
|
+
"There is no current event loop in thread %r."
|
|
198
|
+
% threading.current_thread().name
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
return self._local._loop
|
|
202
|
+
|
|
203
|
+
def set_event_loop(self, loop: _AbstractEventLoop | None) -> None:
|
|
204
|
+
"""Set the event loop."""
|
|
205
|
+
if loop is not None and not isinstance(loop, _AbstractEventLoop):
|
|
206
|
+
raise TypeError(
|
|
207
|
+
f"loop must be an instance of AbstractEventLoop or None, "
|
|
208
|
+
f"not '{type(loop).__name__}'"
|
|
209
|
+
)
|
|
210
|
+
self._local._loop = loop
|
|
211
|
+
|
|
212
|
+
def new_event_loop(self) -> Loop:
|
|
213
|
+
"""Create a new event loop.
|
|
214
|
+
|
|
215
|
+
You must call set_event_loop() to make this the current event loop.
|
|
216
|
+
"""
|
|
217
|
+
return self._loop_factory()
|
|
218
|
+
|
|
219
|
+
globals()["install"] = install
|
|
220
|
+
globals()["EventLoopPolicy"] = EventLoopPolicy
|
|
221
|
+
return globals()[name]
|
winloop/_noop.py
ADDED