winloop 0.1.8__cp38-cp38-win_amd64.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 +170 -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-win_amd64.pyd +0 -0
- winloop/loop.pxd +230 -0
- winloop/loop.pyi +297 -0
- winloop/loop.pyx +3441 -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.8.dist-info/LICENSE-APACHE +203 -0
- winloop-0.1.8.dist-info/LICENSE-MIT +21 -0
- winloop-0.1.8.dist-info/METADATA +316 -0
- winloop-0.1.8.dist-info/RECORD +63 -0
- winloop-0.1.8.dist-info/WHEEL +5 -0
- winloop-0.1.8.dist-info/top_level.txt +1 -0
winloop/__init__.py
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import asyncio as __asyncio
|
|
2
|
+
import typing as _typing
|
|
3
|
+
import sys as _sys
|
|
4
|
+
import warnings as _warnings
|
|
5
|
+
|
|
6
|
+
from asyncio.events import BaseDefaultEventLoopPolicy as __BasePolicy
|
|
7
|
+
|
|
8
|
+
# Winloop comment: next line commented out for now. Somehow winloop\includes
|
|
9
|
+
# is not included in the Winloop wheel, affecting version 0.1.6 on PyPI.
|
|
10
|
+
#from . import includes as __includes # NOQA
|
|
11
|
+
from .loop import Loop as __BaseLoop # NOQA
|
|
12
|
+
from ._version import __version__ # NOQA
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
__all__ = ('new_event_loop', 'install', 'EventLoopPolicy')
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_T = _typing.TypeVar("_T")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Loop(__BaseLoop, __asyncio.AbstractEventLoop): # type: ignore[misc]
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def new_event_loop() -> Loop:
|
|
26
|
+
"""Return a new event loop."""
|
|
27
|
+
return Loop()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def install() -> None:
|
|
31
|
+
"""A helper function to install winloop policy."""
|
|
32
|
+
if _sys.version_info[:2] >= (3, 12):
|
|
33
|
+
_warnings.warn(
|
|
34
|
+
'winloop.install() is deprecated in favor of winloop.run()'
|
|
35
|
+
'starting with Python 3.12.',
|
|
36
|
+
DeprecationWarning,
|
|
37
|
+
stacklevel=1,
|
|
38
|
+
)
|
|
39
|
+
__asyncio.set_event_loop_policy(EventLoopPolicy())
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if _typing.TYPE_CHECKING:
|
|
43
|
+
def run(
|
|
44
|
+
main: _typing.Coroutine[_typing.Any, _typing.Any, _T],
|
|
45
|
+
*,
|
|
46
|
+
loop_factory: _typing.Optional[
|
|
47
|
+
_typing.Callable[[], Loop]
|
|
48
|
+
] = new_event_loop,
|
|
49
|
+
debug: _typing.Optional[bool]=None,
|
|
50
|
+
) -> _T:
|
|
51
|
+
"""The preferred way of running a coroutine with winloop."""
|
|
52
|
+
else:
|
|
53
|
+
def run(main, *, loop_factory=new_event_loop, debug=None, **run_kwargs):
|
|
54
|
+
"""The preferred way of running a coroutine with winloop."""
|
|
55
|
+
|
|
56
|
+
async def wrapper():
|
|
57
|
+
# If `loop_factory` is provided we want it to return
|
|
58
|
+
# either winloop.Loop or a subtype of it, assuming the user
|
|
59
|
+
# is using `winloop.run()` intentionally.
|
|
60
|
+
loop = __asyncio._get_running_loop()
|
|
61
|
+
if not isinstance(loop, Loop):
|
|
62
|
+
raise TypeError('winloop.run() uses a non-uvloop event loop')
|
|
63
|
+
return await main
|
|
64
|
+
|
|
65
|
+
vi = _sys.version_info[:2]
|
|
66
|
+
|
|
67
|
+
if vi <= (3, 10):
|
|
68
|
+
# Copied from python/cpython
|
|
69
|
+
|
|
70
|
+
if __asyncio._get_running_loop() is not None:
|
|
71
|
+
raise RuntimeError(
|
|
72
|
+
"asyncio.run() cannot be called from a running event loop")
|
|
73
|
+
|
|
74
|
+
if not __asyncio.iscoroutine(main):
|
|
75
|
+
raise ValueError(
|
|
76
|
+
"a coroutine was expected, got {!r}".format(main)
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
loop = loop_factory()
|
|
80
|
+
try:
|
|
81
|
+
__asyncio.set_event_loop(loop)
|
|
82
|
+
if debug is not None:
|
|
83
|
+
loop.set_debug(debug)
|
|
84
|
+
return loop.run_until_complete(wrapper())
|
|
85
|
+
finally:
|
|
86
|
+
try:
|
|
87
|
+
_cancel_all_tasks(loop)
|
|
88
|
+
loop.run_until_complete(loop.shutdown_asyncgens())
|
|
89
|
+
if hasattr(loop, 'shutdown_default_executor'):
|
|
90
|
+
loop.run_until_complete(
|
|
91
|
+
loop.shutdown_default_executor()
|
|
92
|
+
)
|
|
93
|
+
finally:
|
|
94
|
+
__asyncio.set_event_loop(None)
|
|
95
|
+
loop.close()
|
|
96
|
+
|
|
97
|
+
elif vi == (3, 11):
|
|
98
|
+
if __asyncio._get_running_loop() is not None:
|
|
99
|
+
raise RuntimeError(
|
|
100
|
+
"asyncio.run() cannot be called from a running event loop")
|
|
101
|
+
|
|
102
|
+
with __asyncio.Runner(
|
|
103
|
+
loop_factory=loop_factory,
|
|
104
|
+
debug=debug,
|
|
105
|
+
**run_kwargs
|
|
106
|
+
) as runner:
|
|
107
|
+
return runner.run(wrapper())
|
|
108
|
+
|
|
109
|
+
else:
|
|
110
|
+
assert vi >= (3, 12)
|
|
111
|
+
return __asyncio.run(
|
|
112
|
+
wrapper(),
|
|
113
|
+
loop_factory=loop_factory,
|
|
114
|
+
debug=debug,
|
|
115
|
+
**run_kwargs
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _cancel_all_tasks(loop: __asyncio.AbstractEventLoop) -> None:
|
|
120
|
+
# Copied from python/cpython
|
|
121
|
+
|
|
122
|
+
to_cancel = __asyncio.all_tasks(loop)
|
|
123
|
+
if not to_cancel:
|
|
124
|
+
return
|
|
125
|
+
|
|
126
|
+
for task in to_cancel:
|
|
127
|
+
task.cancel()
|
|
128
|
+
|
|
129
|
+
loop.run_until_complete(
|
|
130
|
+
__asyncio.gather(*to_cancel, return_exceptions=True)
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
for task in to_cancel:
|
|
134
|
+
if task.cancelled():
|
|
135
|
+
continue
|
|
136
|
+
if task.exception() is not None:
|
|
137
|
+
loop.call_exception_handler({
|
|
138
|
+
'message': 'unhandled exception during asyncio.run() shutdown',
|
|
139
|
+
'exception': task.exception(),
|
|
140
|
+
'task': task,
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class EventLoopPolicy(__BasePolicy):
|
|
145
|
+
"""Event loop policy.
|
|
146
|
+
|
|
147
|
+
The preferred way to make your application use winloop:
|
|
148
|
+
|
|
149
|
+
>>> import asyncio
|
|
150
|
+
>>> import winloop
|
|
151
|
+
>>> asyncio.set_event_loop_policy(winloop.EventLoopPolicy())
|
|
152
|
+
>>> asyncio.get_event_loop()
|
|
153
|
+
<winloop.Loop running=False closed=False debug=False>
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
def _loop_factory(self) -> Loop:
|
|
157
|
+
return new_event_loop()
|
|
158
|
+
|
|
159
|
+
if _typing.TYPE_CHECKING:
|
|
160
|
+
# EventLoopPolicy doesn't implement these, but since they are marked
|
|
161
|
+
# as abstract in typeshed, we have to put them in so mypy thinks
|
|
162
|
+
# the base methods are overridden. This is the same approach taken
|
|
163
|
+
# for the Windows event loop policy classes in typeshed.
|
|
164
|
+
def get_child_watcher(self) -> _typing.NoReturn:
|
|
165
|
+
...
|
|
166
|
+
|
|
167
|
+
def set_child_watcher(
|
|
168
|
+
self, watcher: _typing.Any
|
|
169
|
+
) -> _typing.NoReturn:
|
|
170
|
+
...
|
winloop/_noop.py
ADDED