massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / asyncio / events.pyi
1 import ssl
2 import sys
3 from _typeshed import FileDescriptorLike, Self
4 from abc import ABCMeta, abstractmethod
5 from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
6 from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, Union, overload
7 from typing_extensions import Literal
8
9 from .base_events import Server
10 from .futures import Future
11 from .protocols import BaseProtocol
12 from .tasks import Task
13 from .transports import BaseTransport
14 from .unix_events import AbstractChildWatcher
15
16 if sys.version_info >= (3, 7):
17     from contextvars import Context
18
19 _T = TypeVar("_T")
20 _Context = Dict[str, Any]
21 _ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any]
22 _ProtocolFactory = Callable[[], BaseProtocol]
23 _SSLContext = Union[bool, None, ssl.SSLContext]
24 _TransProtPair = Tuple[BaseTransport, BaseProtocol]
25
26 class Handle:
27     _cancelled = False
28     _args: Sequence[Any]
29     if sys.version_info >= (3, 7):
30         def __init__(
31             self, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ...
32         ) -> None: ...
33     else:
34         def __init__(self, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop) -> None: ...
35     def __repr__(self) -> str: ...
36     def cancel(self) -> None: ...
37     def _run(self) -> None: ...
38     if sys.version_info >= (3, 7):
39         def cancelled(self) -> bool: ...
40
41 class TimerHandle(Handle):
42     if sys.version_info >= (3, 7):
43         def __init__(
44             self,
45             when: float,
46             callback: Callable[..., Any],
47             args: Sequence[Any],
48             loop: AbstractEventLoop,
49             context: Context | None = ...,
50         ) -> None: ...
51     else:
52         def __init__(self, when: float, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop) -> None: ...
53     def __hash__(self) -> int: ...
54     if sys.version_info >= (3, 7):
55         def when(self) -> float: ...
56
57 class AbstractServer:
58     def close(self) -> None: ...
59     if sys.version_info >= (3, 7):
60         async def __aenter__(self: Self) -> Self: ...
61         async def __aexit__(self, *exc: Any) -> None: ...
62         def get_loop(self) -> AbstractEventLoop: ...
63         def is_serving(self) -> bool: ...
64         async def start_serving(self) -> None: ...
65         async def serve_forever(self) -> None: ...
66     async def wait_closed(self) -> None: ...
67
68 class AbstractEventLoop(metaclass=ABCMeta):
69     slow_callback_duration: float
70     @abstractmethod
71     def run_forever(self) -> None: ...
72     # Can't use a union, see mypy issue  # 1873.
73     @overload
74     @abstractmethod
75     def run_until_complete(self, future: Generator[Any, None, _T]) -> _T: ...
76     @overload
77     @abstractmethod
78     def run_until_complete(self, future: Awaitable[_T]) -> _T: ...
79     @abstractmethod
80     def stop(self) -> None: ...
81     @abstractmethod
82     def is_running(self) -> bool: ...
83     @abstractmethod
84     def is_closed(self) -> bool: ...
85     @abstractmethod
86     def close(self) -> None: ...
87     @abstractmethod
88     async def shutdown_asyncgens(self) -> None: ...
89     # Methods scheduling callbacks.  All these return Handles.
90     @abstractmethod
91     def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ...
92     @abstractmethod
93     def call_later(self, delay: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ...
94     @abstractmethod
95     def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ...
96     @abstractmethod
97     def time(self) -> float: ...
98     # Future methods
99     @abstractmethod
100     def create_future(self) -> Future[Any]: ...
101     # Tasks methods
102     if sys.version_info >= (3, 8):
103         @abstractmethod
104         def create_task(self, coro: Awaitable[_T] | Generator[Any, None, _T], *, name: str | None = ...) -> Task[_T]: ...
105     else:
106         @abstractmethod
107         def create_task(self, coro: Awaitable[_T] | Generator[Any, None, _T]) -> Task[_T]: ...
108     @abstractmethod
109     def set_task_factory(self, factory: Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]] | None) -> None: ...
110     @abstractmethod
111     def get_task_factory(self) -> Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]] | None: ...
112     # Methods for interacting with threads
113     @abstractmethod
114     def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any) -> Handle: ...
115     @abstractmethod
116     def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
117     @abstractmethod
118     def set_default_executor(self, executor: Any) -> None: ...
119     # Network I/O methods returning Futures.
120     @abstractmethod
121     async def getaddrinfo(
122         self, host: str | None, port: str | int | None, *, family: int = ..., type: int = ..., proto: int = ..., flags: int = ...
123     ) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...
124     @abstractmethod
125     async def getnameinfo(self, sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int = ...) -> tuple[str, str]: ...
126     if sys.version_info >= (3, 8):
127         @overload
128         @abstractmethod
129         async def create_connection(
130             self,
131             protocol_factory: _ProtocolFactory,
132             host: str = ...,
133             port: int = ...,
134             *,
135             ssl: _SSLContext = ...,
136             family: int = ...,
137             proto: int = ...,
138             flags: int = ...,
139             sock: None = ...,
140             local_addr: tuple[str, int] | None = ...,
141             server_hostname: str | None = ...,
142             ssl_handshake_timeout: float | None = ...,
143             happy_eyeballs_delay: float | None = ...,
144             interleave: int | None = ...,
145         ) -> _TransProtPair: ...
146         @overload
147         @abstractmethod
148         async def create_connection(
149             self,
150             protocol_factory: _ProtocolFactory,
151             host: None = ...,
152             port: None = ...,
153             *,
154             ssl: _SSLContext = ...,
155             family: int = ...,
156             proto: int = ...,
157             flags: int = ...,
158             sock: socket,
159             local_addr: None = ...,
160             server_hostname: str | None = ...,
161             ssl_handshake_timeout: float | None = ...,
162             happy_eyeballs_delay: float | None = ...,
163             interleave: int | None = ...,
164         ) -> _TransProtPair: ...
165     elif sys.version_info >= (3, 7):
166         @overload
167         @abstractmethod
168         async def create_connection(
169             self,
170             protocol_factory: _ProtocolFactory,
171             host: str = ...,
172             port: int = ...,
173             *,
174             ssl: _SSLContext = ...,
175             family: int = ...,
176             proto: int = ...,
177             flags: int = ...,
178             sock: None = ...,
179             local_addr: tuple[str, int] | None = ...,
180             server_hostname: str | None = ...,
181             ssl_handshake_timeout: float | None = ...,
182         ) -> _TransProtPair: ...
183         @overload
184         @abstractmethod
185         async def create_connection(
186             self,
187             protocol_factory: _ProtocolFactory,
188             host: None = ...,
189             port: None = ...,
190             *,
191             ssl: _SSLContext = ...,
192             family: int = ...,
193             proto: int = ...,
194             flags: int = ...,
195             sock: socket,
196             local_addr: None = ...,
197             server_hostname: str | None = ...,
198             ssl_handshake_timeout: float | None = ...,
199         ) -> _TransProtPair: ...
200     else:
201         @overload
202         @abstractmethod
203         async def create_connection(
204             self,
205             protocol_factory: _ProtocolFactory,
206             host: str = ...,
207             port: int = ...,
208             *,
209             ssl: _SSLContext = ...,
210             family: int = ...,
211             proto: int = ...,
212             flags: int = ...,
213             sock: None = ...,
214             local_addr: tuple[str, int] | None = ...,
215             server_hostname: str | None = ...,
216         ) -> _TransProtPair: ...
217         @overload
218         @abstractmethod
219         async def create_connection(
220             self,
221             protocol_factory: _ProtocolFactory,
222             host: None = ...,
223             port: None = ...,
224             *,
225             ssl: _SSLContext = ...,
226             family: int = ...,
227             proto: int = ...,
228             flags: int = ...,
229             sock: socket,
230             local_addr: None = ...,
231             server_hostname: str | None = ...,
232         ) -> _TransProtPair: ...
233     if sys.version_info >= (3, 7):
234         @abstractmethod
235         async def sock_sendfile(
236             self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ...
237         ) -> int: ...
238         @overload
239         @abstractmethod
240         async def create_server(
241             self,
242             protocol_factory: _ProtocolFactory,
243             host: str | Sequence[str] | None = ...,
244             port: int = ...,
245             *,
246             family: int = ...,
247             flags: int = ...,
248             sock: None = ...,
249             backlog: int = ...,
250             ssl: _SSLContext = ...,
251             reuse_address: bool | None = ...,
252             reuse_port: bool | None = ...,
253             ssl_handshake_timeout: float | None = ...,
254             start_serving: bool = ...,
255         ) -> Server: ...
256         @overload
257         @abstractmethod
258         async def create_server(
259             self,
260             protocol_factory: _ProtocolFactory,
261             host: None = ...,
262             port: None = ...,
263             *,
264             family: int = ...,
265             flags: int = ...,
266             sock: socket = ...,
267             backlog: int = ...,
268             ssl: _SSLContext = ...,
269             reuse_address: bool | None = ...,
270             reuse_port: bool | None = ...,
271             ssl_handshake_timeout: float | None = ...,
272             start_serving: bool = ...,
273         ) -> Server: ...
274         async def create_unix_connection(
275             self,
276             protocol_factory: _ProtocolFactory,
277             path: str | None = ...,
278             *,
279             ssl: _SSLContext = ...,
280             sock: socket | None = ...,
281             server_hostname: str | None = ...,
282             ssl_handshake_timeout: float | None = ...,
283         ) -> _TransProtPair: ...
284         async def create_unix_server(
285             self,
286             protocol_factory: _ProtocolFactory,
287             path: str | None = ...,
288             *,
289             sock: socket | None = ...,
290             backlog: int = ...,
291             ssl: _SSLContext = ...,
292             ssl_handshake_timeout: float | None = ...,
293             start_serving: bool = ...,
294         ) -> Server: ...
295         @abstractmethod
296         async def sendfile(
297             self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ...
298         ) -> int: ...
299         @abstractmethod
300         async def start_tls(
301             self,
302             transport: BaseTransport,
303             protocol: BaseProtocol,
304             sslcontext: ssl.SSLContext,
305             *,
306             server_side: bool = ...,
307             server_hostname: str | None = ...,
308             ssl_handshake_timeout: float | None = ...,
309         ) -> BaseTransport: ...
310     else:
311         @overload
312         @abstractmethod
313         async def create_server(
314             self,
315             protocol_factory: _ProtocolFactory,
316             host: str | Sequence[str] | None = ...,
317             port: int = ...,
318             *,
319             family: int = ...,
320             flags: int = ...,
321             sock: None = ...,
322             backlog: int = ...,
323             ssl: _SSLContext = ...,
324             reuse_address: bool | None = ...,
325             reuse_port: bool | None = ...,
326         ) -> Server: ...
327         @overload
328         @abstractmethod
329         async def create_server(
330             self,
331             protocol_factory: _ProtocolFactory,
332             host: None = ...,
333             port: None = ...,
334             *,
335             family: int = ...,
336             flags: int = ...,
337             sock: socket,
338             backlog: int = ...,
339             ssl: _SSLContext = ...,
340             reuse_address: bool | None = ...,
341             reuse_port: bool | None = ...,
342         ) -> Server: ...
343         async def create_unix_connection(
344             self,
345             protocol_factory: _ProtocolFactory,
346             path: str,
347             *,
348             ssl: _SSLContext = ...,
349             sock: socket | None = ...,
350             server_hostname: str | None = ...,
351         ) -> _TransProtPair: ...
352         async def create_unix_server(
353             self,
354             protocol_factory: _ProtocolFactory,
355             path: str,
356             *,
357             sock: socket | None = ...,
358             backlog: int = ...,
359             ssl: _SSLContext = ...,
360         ) -> Server: ...
361     @abstractmethod
362     async def create_datagram_endpoint(
363         self,
364         protocol_factory: _ProtocolFactory,
365         local_addr: tuple[str, int] | None = ...,
366         remote_addr: tuple[str, int] | None = ...,
367         *,
368         family: int = ...,
369         proto: int = ...,
370         flags: int = ...,
371         reuse_address: bool | None = ...,
372         reuse_port: bool | None = ...,
373         allow_broadcast: bool | None = ...,
374         sock: socket | None = ...,
375     ) -> _TransProtPair: ...
376     # Pipes and subprocesses.
377     @abstractmethod
378     async def connect_read_pipe(self, protocol_factory: _ProtocolFactory, pipe: Any) -> _TransProtPair: ...
379     @abstractmethod
380     async def connect_write_pipe(self, protocol_factory: _ProtocolFactory, pipe: Any) -> _TransProtPair: ...
381     @abstractmethod
382     async def subprocess_shell(
383         self,
384         protocol_factory: _ProtocolFactory,
385         cmd: bytes | str,
386         *,
387         stdin: int | IO[Any] | None = ...,
388         stdout: int | IO[Any] | None = ...,
389         stderr: int | IO[Any] | None = ...,
390         universal_newlines: Literal[False] = ...,
391         shell: Literal[True] = ...,
392         bufsize: Literal[0] = ...,
393         encoding: None = ...,
394         errors: None = ...,
395         text: Literal[False, None] = ...,
396         **kwargs: Any,
397     ) -> _TransProtPair: ...
398     @abstractmethod
399     async def subprocess_exec(
400         self,
401         protocol_factory: _ProtocolFactory,
402         program: Any,
403         *args: Any,
404         stdin: int | IO[Any] | None = ...,
405         stdout: int | IO[Any] | None = ...,
406         stderr: int | IO[Any] | None = ...,
407         universal_newlines: Literal[False] = ...,
408         shell: Literal[True] = ...,
409         bufsize: Literal[0] = ...,
410         encoding: None = ...,
411         errors: None = ...,
412         **kwargs: Any,
413     ) -> _TransProtPair: ...
414     @abstractmethod
415     def add_reader(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ...
416     @abstractmethod
417     def remove_reader(self, fd: FileDescriptorLike) -> None: ...
418     @abstractmethod
419     def add_writer(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ...
420     @abstractmethod
421     def remove_writer(self, fd: FileDescriptorLike) -> None: ...
422     # Completion based I/O methods returning Futures prior to 3.7
423     if sys.version_info >= (3, 7):
424         @abstractmethod
425         async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ...
426         @abstractmethod
427         async def sock_recv_into(self, sock: socket, buf: bytearray) -> int: ...
428         @abstractmethod
429         async def sock_sendall(self, sock: socket, data: bytes) -> None: ...
430         @abstractmethod
431         async def sock_connect(self, sock: socket, address: _Address) -> None: ...
432         @abstractmethod
433         async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ...
434     else:
435         @abstractmethod
436         def sock_recv(self, sock: socket, nbytes: int) -> Future[bytes]: ...
437         @abstractmethod
438         def sock_sendall(self, sock: socket, data: bytes) -> Future[None]: ...
439         @abstractmethod
440         def sock_connect(self, sock: socket, address: _Address) -> Future[None]: ...
441         @abstractmethod
442         def sock_accept(self, sock: socket) -> Future[tuple[socket, _RetAddress]]: ...
443     # Signal handling.
444     @abstractmethod
445     def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ...
446     @abstractmethod
447     def remove_signal_handler(self, sig: int) -> bool: ...
448     # Error handlers.
449     @abstractmethod
450     def set_exception_handler(self, handler: _ExceptionHandler | None) -> None: ...
451     @abstractmethod
452     def get_exception_handler(self) -> _ExceptionHandler | None: ...
453     @abstractmethod
454     def default_exception_handler(self, context: _Context) -> None: ...
455     @abstractmethod
456     def call_exception_handler(self, context: _Context) -> None: ...
457     # Debug flag management.
458     @abstractmethod
459     def get_debug(self) -> bool: ...
460     @abstractmethod
461     def set_debug(self, enabled: bool) -> None: ...
462     if sys.version_info >= (3, 9):
463         @abstractmethod
464         async def shutdown_default_executor(self) -> None: ...
465
466 class AbstractEventLoopPolicy(metaclass=ABCMeta):
467     @abstractmethod
468     def get_event_loop(self) -> AbstractEventLoop: ...
469     @abstractmethod
470     def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
471     @abstractmethod
472     def new_event_loop(self) -> AbstractEventLoop: ...
473     # Child processes handling (Unix only).
474     @abstractmethod
475     def get_child_watcher(self) -> AbstractChildWatcher: ...
476     @abstractmethod
477     def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
478
479 class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy, metaclass=ABCMeta):
480     def __init__(self) -> None: ...
481     def get_event_loop(self) -> AbstractEventLoop: ...
482     def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
483     def new_event_loop(self) -> AbstractEventLoop: ...
484
485 def get_event_loop_policy() -> AbstractEventLoopPolicy: ...
486 def set_event_loop_policy(policy: AbstractEventLoopPolicy | None) -> None: ...
487 def get_event_loop() -> AbstractEventLoop: ...
488 def set_event_loop(loop: AbstractEventLoop | None) -> None: ...
489 def new_event_loop() -> AbstractEventLoop: ...
490 def get_child_watcher() -> AbstractChildWatcher: ...
491 def set_child_watcher(watcher: AbstractChildWatcher) -> None: ...
492 def _set_running_loop(__loop: AbstractEventLoop | None) -> None: ...
493 def _get_running_loop() -> AbstractEventLoop: ...
494
495 if sys.version_info >= (3, 7):
496     def get_running_loop() -> AbstractEventLoop: ...
497     if sys.version_info < (3, 8):
498         class SendfileNotAvailableError(RuntimeError): ...