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