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