winloop 0.1.91__cp38-cp38-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 +226 -0
- winloop/_noop.py +3 -0
- winloop/_testbase.py +555 -0
- winloop/_version.py +13 -0
- winloop/cbhandles.pxd +39 -0
- winloop/cbhandles.pyx +434 -0
- winloop/dns.pyx +496 -0
- winloop/errors.pyx +83 -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 +48 -0
- winloop/handles/handle.pyx +395 -0
- winloop/handles/idle.pxd +14 -0
- winloop/handles/idle.pyx +72 -0
- winloop/handles/pipe.pxd +33 -0
- winloop/handles/pipe.pyx +247 -0
- winloop/handles/poll.pxd +25 -0
- winloop/handles/poll.pyx +237 -0
- winloop/handles/process.pxd +80 -0
- winloop/handles/process.pyx +844 -0
- winloop/handles/stream.pxd +50 -0
- winloop/handles/stream.pyx +1038 -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 +33 -0
- winloop/includes/debug.pxd +3 -0
- winloop/includes/flowcontrol.pxd +23 -0
- winloop/includes/python.pxd +31 -0
- winloop/includes/stdlib.pxi +179 -0
- winloop/includes/system.pxd +82 -0
- winloop/includes/uv.pxd +517 -0
- winloop/loop.cp38-win32.pyd +0 -0
- winloop/loop.pxd +230 -0
- winloop/loop.pyi +297 -0
- winloop/loop.pyx +3451 -0
- winloop/lru.pyx +79 -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/sslproto.pxd +138 -0
- winloop/sslproto.pyx +950 -0
- winloop-0.1.91.dist-info/LICENSE-APACHE +203 -0
- winloop-0.1.91.dist-info/LICENSE-MIT +21 -0
- winloop-0.1.91.dist-info/METADATA +319 -0
- winloop-0.1.91.dist-info/RECORD +63 -0
- winloop-0.1.91.dist-info/WHEEL +5 -0
- winloop-0.1.91.dist-info/top_level.txt +1 -0
winloop/__init__.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import asyncio as __asyncio
|
|
2
|
+
import typing as _typing
|
|
3
|
+
import sys as _sys
|
|
4
|
+
import warnings as _warnings
|
|
5
|
+
import threading as _threading
|
|
6
|
+
|
|
7
|
+
if _sys.version_info < (3, 14):
|
|
8
|
+
from asyncio.events import BaseDefaultEventLoopPolicy as __BasePolicy
|
|
9
|
+
else:
|
|
10
|
+
# Python Deprecates EventLoopPolicy in 3.14
|
|
11
|
+
# SEE: https://github.com/python/cpython/issues/131148
|
|
12
|
+
# We will watch closely to determine what else we will do for supporting 3.14
|
|
13
|
+
from asyncio.events import _BaseDefaultEventLoopPolicy as __BasePolicy
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Winloop comment: next line commented out for now. Somehow winloop\includes
|
|
17
|
+
# is not included in the Winloop wheel, affecting version 0.1.6 on PyPI.
|
|
18
|
+
#from . import includes as __includes # NOQA
|
|
19
|
+
from .loop import Loop as __BaseLoop # NOQA
|
|
20
|
+
from ._version import __version__ # NOQA
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
__all__ = ('new_event_loop', 'install', 'EventLoopPolicy')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
_T = _typing.TypeVar("_T")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Loop(__BaseLoop, __asyncio.AbstractEventLoop): # type: ignore[misc]
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def new_event_loop() -> Loop:
|
|
34
|
+
"""Return a new event loop."""
|
|
35
|
+
return Loop()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def install() -> None:
|
|
39
|
+
"""A helper function to install winloop policy."""
|
|
40
|
+
if _sys.version_info[:2] >= (3, 12):
|
|
41
|
+
_warnings.warn(
|
|
42
|
+
'winloop.install() is deprecated in favor of winloop.run()'
|
|
43
|
+
'starting with Python 3.12.',
|
|
44
|
+
DeprecationWarning,
|
|
45
|
+
stacklevel=1,
|
|
46
|
+
)
|
|
47
|
+
__asyncio.set_event_loop_policy(EventLoopPolicy())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if _typing.TYPE_CHECKING:
|
|
51
|
+
def run(
|
|
52
|
+
main: _typing.Coroutine[_typing.Any, _typing.Any, _T],
|
|
53
|
+
*,
|
|
54
|
+
loop_factory: _typing.Optional[
|
|
55
|
+
_typing.Callable[[], Loop]
|
|
56
|
+
] = new_event_loop,
|
|
57
|
+
debug: _typing.Optional[bool]=None,
|
|
58
|
+
) -> _T:
|
|
59
|
+
"""The preferred way of running a coroutine with winloop."""
|
|
60
|
+
else:
|
|
61
|
+
def run(main, *, loop_factory=new_event_loop, debug=None, **run_kwargs):
|
|
62
|
+
"""The preferred way of running a coroutine with winloop."""
|
|
63
|
+
|
|
64
|
+
async def wrapper():
|
|
65
|
+
# If `loop_factory` is provided we want it to return
|
|
66
|
+
# either winloop.Loop or a subtype of it, assuming the user
|
|
67
|
+
# is using `winloop.run()` intentionally.
|
|
68
|
+
loop = __asyncio._get_running_loop()
|
|
69
|
+
if not isinstance(loop, Loop):
|
|
70
|
+
raise TypeError('winloop.run() uses a non-uvloop event loop')
|
|
71
|
+
return await main
|
|
72
|
+
|
|
73
|
+
vi = _sys.version_info[:2]
|
|
74
|
+
|
|
75
|
+
if vi <= (3, 10):
|
|
76
|
+
# Copied from python/cpython
|
|
77
|
+
|
|
78
|
+
if __asyncio._get_running_loop() is not None:
|
|
79
|
+
raise RuntimeError(
|
|
80
|
+
"asyncio.run() cannot be called from a running event loop")
|
|
81
|
+
|
|
82
|
+
if not __asyncio.iscoroutine(main):
|
|
83
|
+
raise ValueError(
|
|
84
|
+
"a coroutine was expected, got {!r}".format(main)
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
loop = loop_factory()
|
|
88
|
+
try:
|
|
89
|
+
__asyncio.set_event_loop(loop)
|
|
90
|
+
if debug is not None:
|
|
91
|
+
loop.set_debug(debug)
|
|
92
|
+
return loop.run_until_complete(wrapper())
|
|
93
|
+
finally:
|
|
94
|
+
try:
|
|
95
|
+
_cancel_all_tasks(loop)
|
|
96
|
+
loop.run_until_complete(loop.shutdown_asyncgens())
|
|
97
|
+
if hasattr(loop, 'shutdown_default_executor'):
|
|
98
|
+
loop.run_until_complete(
|
|
99
|
+
loop.shutdown_default_executor()
|
|
100
|
+
)
|
|
101
|
+
finally:
|
|
102
|
+
__asyncio.set_event_loop(None)
|
|
103
|
+
loop.close()
|
|
104
|
+
|
|
105
|
+
elif vi == (3, 11):
|
|
106
|
+
if __asyncio._get_running_loop() is not None:
|
|
107
|
+
raise RuntimeError(
|
|
108
|
+
"asyncio.run() cannot be called from a running event loop")
|
|
109
|
+
|
|
110
|
+
with __asyncio.Runner(
|
|
111
|
+
loop_factory=loop_factory,
|
|
112
|
+
debug=debug,
|
|
113
|
+
**run_kwargs
|
|
114
|
+
) as runner:
|
|
115
|
+
return runner.run(wrapper())
|
|
116
|
+
|
|
117
|
+
else:
|
|
118
|
+
assert vi >= (3, 12)
|
|
119
|
+
return __asyncio.run(
|
|
120
|
+
wrapper(),
|
|
121
|
+
loop_factory=loop_factory,
|
|
122
|
+
debug=debug,
|
|
123
|
+
**run_kwargs
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _cancel_all_tasks(loop: __asyncio.AbstractEventLoop) -> None:
|
|
128
|
+
# Copied from python/cpython
|
|
129
|
+
|
|
130
|
+
to_cancel = __asyncio.all_tasks(loop)
|
|
131
|
+
if not to_cancel:
|
|
132
|
+
return
|
|
133
|
+
|
|
134
|
+
for task in to_cancel:
|
|
135
|
+
task.cancel()
|
|
136
|
+
|
|
137
|
+
loop.run_until_complete(
|
|
138
|
+
__asyncio.gather(*to_cancel, return_exceptions=True)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
for task in to_cancel:
|
|
142
|
+
if task.cancelled():
|
|
143
|
+
continue
|
|
144
|
+
if task.exception() is not None:
|
|
145
|
+
loop.call_exception_handler({
|
|
146
|
+
'message': 'unhandled exception during asyncio.run() shutdown',
|
|
147
|
+
'exception': task.exception(),
|
|
148
|
+
'task': task,
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class EventLoopPolicy(__BasePolicy):
|
|
153
|
+
"""Event loop policy.
|
|
154
|
+
|
|
155
|
+
The preferred way to make your application use winloop:
|
|
156
|
+
|
|
157
|
+
>>> import asyncio
|
|
158
|
+
>>> import winloop
|
|
159
|
+
>>> asyncio.set_event_loop_policy(winloop.EventLoopPolicy())
|
|
160
|
+
>>> asyncio.get_event_loop()
|
|
161
|
+
<winloop.Loop running=False closed=False debug=False>
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
# XXX: To bypass Problems of future Deprecation in 3.16 of different
|
|
166
|
+
# Eventloop Policies moving it's code to here for right now makes sense...
|
|
167
|
+
|
|
168
|
+
# Have fun trying to stop me because I put that code all right here :)
|
|
169
|
+
# SEE: https://github.com/MagicStack/uvloop/issues/637
|
|
170
|
+
|
|
171
|
+
if _sys.version_info > (3, 14):
|
|
172
|
+
|
|
173
|
+
_loop_factory = None
|
|
174
|
+
|
|
175
|
+
class _Local(_threading.local):
|
|
176
|
+
_loop = None
|
|
177
|
+
_set_called = False
|
|
178
|
+
|
|
179
|
+
def __init__(self):
|
|
180
|
+
self._local = self._Local()
|
|
181
|
+
|
|
182
|
+
def get_event_loop(self):
|
|
183
|
+
"""Get the event loop for the current context.
|
|
184
|
+
|
|
185
|
+
Returns an instance of EventLoop or raises an exception.
|
|
186
|
+
"""
|
|
187
|
+
if (self._local._loop is None and
|
|
188
|
+
not self._local._set_called and
|
|
189
|
+
_threading.current_thread() is _threading.main_thread()):
|
|
190
|
+
self.set_event_loop(self.new_event_loop())
|
|
191
|
+
|
|
192
|
+
if self._local._loop is None:
|
|
193
|
+
raise RuntimeError('There is no current event loop in thread %r.'
|
|
194
|
+
% _threading.current_thread().name)
|
|
195
|
+
|
|
196
|
+
return self._local._loop
|
|
197
|
+
|
|
198
|
+
def set_event_loop(self, loop):
|
|
199
|
+
"""Set the event loop."""
|
|
200
|
+
self._local._set_called = True
|
|
201
|
+
assert loop is None or isinstance(loop, __BasePolicy)
|
|
202
|
+
self._local._loop = loop
|
|
203
|
+
|
|
204
|
+
def new_event_loop(self):
|
|
205
|
+
"""Create a new event loop.
|
|
206
|
+
|
|
207
|
+
You must call set_event_loop() to make this the current event
|
|
208
|
+
loop.
|
|
209
|
+
"""
|
|
210
|
+
return self._loop_factory()
|
|
211
|
+
|
|
212
|
+
def _loop_factory(self) -> Loop:
|
|
213
|
+
return new_event_loop()
|
|
214
|
+
|
|
215
|
+
if _typing.TYPE_CHECKING:
|
|
216
|
+
# EventLoopPolicy doesn't implement these, but since they are marked
|
|
217
|
+
# as abstract in typeshed, we have to put them in so mypy thinks
|
|
218
|
+
# the base methods are overridden. This is the same approach taken
|
|
219
|
+
# for the Windows event loop policy classes in typeshed.
|
|
220
|
+
def get_child_watcher(self) -> _typing.NoReturn:
|
|
221
|
+
...
|
|
222
|
+
|
|
223
|
+
def set_child_watcher(
|
|
224
|
+
self, watcher: _typing.Any
|
|
225
|
+
) -> _typing.NoReturn:
|
|
226
|
+
...
|
winloop/_noop.py
ADDED