winloop 0.4.0__cp312-cp312-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 (65) hide show
  1. winloop/__init__.py +221 -0
  2. winloop/_noop.py +3 -0
  3. winloop/_testbase.py +558 -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 +850 -0
  27. winloop/handles/stream.pxd +50 -0
  28. winloop/handles/stream.pyx +1047 -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.cp312-win_arm64.pyd +0 -0
  46. winloop/loop.pxd +234 -0
  47. winloop/loop.pyi +301 -0
  48. winloop/loop.pyx +3558 -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/shlex.pxd +38 -0
  57. winloop/shlex.pyx +346 -0
  58. winloop/sslproto.pxd +138 -0
  59. winloop/sslproto.pyx +950 -0
  60. winloop-0.4.0.dist-info/METADATA +326 -0
  61. winloop-0.4.0.dist-info/RECORD +65 -0
  62. winloop-0.4.0.dist-info/WHEEL +5 -0
  63. winloop-0.4.0.dist-info/licenses/LICENSE-APACHE +203 -0
  64. winloop-0.4.0.dist-info/licenses/LICENSE-MIT +21 -0
  65. winloop-0.4.0.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
@@ -0,0 +1,3 @@
1
+ def noop() -> None:
2
+ """Empty function to invoke CPython ceval loop."""
3
+ return