winloop 0.1.7__cp313-cp313-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 (63) hide show
  1. winloop/__init__.py +170 -0
  2. winloop/_noop.py +3 -0
  3. winloop/_testbase.py +555 -0
  4. winloop/_version.py +13 -0
  5. winloop/cbhandles.pxd +39 -0
  6. winloop/cbhandles.pyx +434 -0
  7. winloop/dns.pyx +491 -0
  8. winloop/errors.pyx +83 -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 +48 -0
  18. winloop/handles/handle.pyx +395 -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 +247 -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 +844 -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 +32 -0
  39. winloop/includes/debug.pxd +3 -0
  40. winloop/includes/flowcontrol.pxd +23 -0
  41. winloop/includes/python.pxd +31 -0
  42. winloop/includes/stdlib.pxi +179 -0
  43. winloop/includes/system.pxd +82 -0
  44. winloop/includes/uv.pxd +517 -0
  45. winloop/loop.cp313-win_amd64.pyd +0 -0
  46. winloop/loop.pxd +230 -0
  47. winloop/loop.pyi +297 -0
  48. winloop/loop.pyx +3441 -0
  49. winloop/lru.pyx +79 -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.1.7.dist-info/LICENSE-APACHE +203 -0
  59. winloop-0.1.7.dist-info/LICENSE-MIT +21 -0
  60. winloop-0.1.7.dist-info/METADATA +316 -0
  61. winloop-0.1.7.dist-info/RECORD +63 -0
  62. winloop-0.1.7.dist-info/WHEEL +5 -0
  63. winloop-0.1.7.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
@@ -0,0 +1,3 @@
1
+ def noop() -> None:
2
+ """Empty function to invoke CPython ceval loop."""
3
+ return