You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

298 line
10 KiB

  1. import asyncio
  2. import ssl
  3. import sys
  4. from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
  5. from typing import (
  6. IO,
  7. Any,
  8. Awaitable,
  9. Callable,
  10. Dict,
  11. Generator,
  12. List,
  13. Optional,
  14. Sequence,
  15. Tuple,
  16. TypeVar,
  17. Union,
  18. overload,
  19. )
  20. _T = TypeVar('_T')
  21. _Context = Dict[str, Any]
  22. _ExceptionHandler = Callable[[asyncio.AbstractEventLoop, _Context], Any]
  23. _SSLContext = Union[bool, None, ssl.SSLContext]
  24. _ProtocolT = TypeVar("_ProtocolT", bound=asyncio.BaseProtocol)
  25. class Loop:
  26. def call_soon(
  27. self, callback: Callable[..., Any], *args: Any, context: Optional[Any] = ...
  28. ) -> asyncio.Handle: ...
  29. def call_soon_threadsafe(
  30. self, callback: Callable[..., Any], *args: Any, context: Optional[Any] = ...
  31. ) -> asyncio.Handle: ...
  32. def call_later(
  33. self, delay: float, callback: Callable[..., Any], *args: Any, context: Optional[Any] = ...
  34. ) -> asyncio.TimerHandle: ...
  35. def call_at(
  36. self, when: float, callback: Callable[..., Any], *args: Any, context: Optional[Any] = ...
  37. ) -> asyncio.TimerHandle: ...
  38. def time(self) -> float: ...
  39. def stop(self) -> None: ...
  40. def run_forever(self) -> None: ...
  41. def close(self) -> None: ...
  42. def get_debug(self) -> bool: ...
  43. def set_debug(self, enabled: bool) -> None: ...
  44. def is_running(self) -> bool: ...
  45. def is_closed(self) -> bool: ...
  46. def create_future(self) -> asyncio.Future[Any]: ...
  47. def create_task(
  48. self,
  49. coro: Union[Awaitable[_T], Generator[Any, None, _T]],
  50. *,
  51. name: Optional[str] = ...,
  52. ) -> asyncio.Task[_T]: ...
  53. def set_task_factory(
  54. self,
  55. factory: Optional[
  56. Callable[[asyncio.AbstractEventLoop, Generator[Any, None, _T]], asyncio.Future[_T]]
  57. ],
  58. ) -> None: ...
  59. def get_task_factory(
  60. self,
  61. ) -> Optional[
  62. Callable[[asyncio.AbstractEventLoop, Generator[Any, None, _T]], asyncio.Future[_T]]
  63. ]: ...
  64. @overload
  65. def run_until_complete(self, future: Generator[Any, None, _T]) -> _T: ...
  66. @overload
  67. def run_until_complete(self, future: Awaitable[_T]) -> _T: ...
  68. async def getaddrinfo(
  69. self,
  70. host: Optional[Union[str, bytes]],
  71. port: Optional[Union[str, bytes, int]],
  72. *,
  73. family: int = ...,
  74. type: int = ...,
  75. proto: int = ...,
  76. flags: int = ...,
  77. ) -> List[
  78. Tuple[
  79. AddressFamily,
  80. SocketKind,
  81. int,
  82. str,
  83. Union[Tuple[str, int], Tuple[str, int, int, int]],
  84. ]
  85. ]: ...
  86. async def getnameinfo(
  87. self,
  88. sockaddr: Union[
  89. Tuple[str, int],
  90. Tuple[str, int, int],
  91. Tuple[str, int, int, int]
  92. ],
  93. flags: int = ...,
  94. ) -> Tuple[str, str]: ...
  95. async def start_tls(
  96. self,
  97. transport: asyncio.BaseTransport,
  98. protocol: asyncio.BaseProtocol,
  99. sslcontext: ssl.SSLContext,
  100. *,
  101. server_side: bool = ...,
  102. server_hostname: Optional[str] = ...,
  103. ssl_handshake_timeout: Optional[float] = ...,
  104. ssl_shutdown_timeout: Optional[float] = ...,
  105. ) -> asyncio.BaseTransport: ...
  106. @overload
  107. async def create_server(
  108. self,
  109. protocol_factory: asyncio.events._ProtocolFactory,
  110. host: Optional[Union[str, Sequence[str]]] = ...,
  111. port: int = ...,
  112. *,
  113. family: int = ...,
  114. flags: int = ...,
  115. sock: None = ...,
  116. backlog: int = ...,
  117. ssl: _SSLContext = ...,
  118. reuse_address: Optional[bool] = ...,
  119. reuse_port: Optional[bool] = ...,
  120. ssl_handshake_timeout: Optional[float] = ...,
  121. ssl_shutdown_timeout: Optional[float] = ...,
  122. start_serving: bool = ...,
  123. ) -> asyncio.AbstractServer: ...
  124. @overload
  125. async def create_server(
  126. self,
  127. protocol_factory: asyncio.events._ProtocolFactory,
  128. host: None = ...,
  129. port: None = ...,
  130. *,
  131. family: int = ...,
  132. flags: int = ...,
  133. sock: socket = ...,
  134. backlog: int = ...,
  135. ssl: _SSLContext = ...,
  136. reuse_address: Optional[bool] = ...,
  137. reuse_port: Optional[bool] = ...,
  138. ssl_handshake_timeout: Optional[float] = ...,
  139. ssl_shutdown_timeout: Optional[float] = ...,
  140. start_serving: bool = ...,
  141. ) -> asyncio.AbstractServer: ...
  142. @overload
  143. async def create_connection(
  144. self,
  145. protocol_factory: Callable[[], _ProtocolT],
  146. host: str = ...,
  147. port: int = ...,
  148. *,
  149. ssl: _SSLContext = ...,
  150. family: int = ...,
  151. proto: int = ...,
  152. flags: int = ...,
  153. sock: None = ...,
  154. local_addr: Optional[Tuple[str, int]] = ...,
  155. server_hostname: Optional[str] = ...,
  156. ssl_handshake_timeout: Optional[float] = ...,
  157. ssl_shutdown_timeout: Optional[float] = ...,
  158. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  159. @overload
  160. async def create_connection(
  161. self,
  162. protocol_factory: Callable[[], _ProtocolT],
  163. host: None = ...,
  164. port: None = ...,
  165. *,
  166. ssl: _SSLContext = ...,
  167. family: int = ...,
  168. proto: int = ...,
  169. flags: int = ...,
  170. sock: socket,
  171. local_addr: None = ...,
  172. server_hostname: Optional[str] = ...,
  173. ssl_handshake_timeout: Optional[float] = ...,
  174. ssl_shutdown_timeout: Optional[float] = ...,
  175. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  176. async def create_unix_server(
  177. self,
  178. protocol_factory: asyncio.events._ProtocolFactory,
  179. path: Optional[str] = ...,
  180. *,
  181. backlog: int = ...,
  182. sock: Optional[socket] = ...,
  183. ssl: _SSLContext = ...,
  184. ssl_handshake_timeout: Optional[float] = ...,
  185. ssl_shutdown_timeout: Optional[float] = ...,
  186. start_serving: bool = ...,
  187. ) -> asyncio.AbstractServer: ...
  188. async def create_unix_connection(
  189. self,
  190. protocol_factory: Callable[[], _ProtocolT],
  191. path: Optional[str] = ...,
  192. *,
  193. ssl: _SSLContext = ...,
  194. sock: Optional[socket] = ...,
  195. server_hostname: Optional[str] = ...,
  196. ssl_handshake_timeout: Optional[float] = ...,
  197. ssl_shutdown_timeout: Optional[float] = ...,
  198. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  199. def default_exception_handler(self, context: _Context) -> None: ...
  200. def get_exception_handler(self) -> Optional[_ExceptionHandler]: ...
  201. def set_exception_handler(self, handler: Optional[_ExceptionHandler]) -> None: ...
  202. def call_exception_handler(self, context: _Context) -> None: ...
  203. def add_reader(self, fd: Any, callback: Callable[..., Any], *args: Any) -> None: ...
  204. def remove_reader(self, fd: Any) -> None: ...
  205. def add_writer(self, fd: Any, callback: Callable[..., Any], *args: Any) -> None: ...
  206. def remove_writer(self, fd: Any) -> None: ...
  207. async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ...
  208. async def sock_recv_into(self, sock: socket, buf: bytearray) -> int: ...
  209. async def sock_sendall(self, sock: socket, data: bytes) -> None: ...
  210. async def sock_accept(self, sock: socket) -> Tuple[socket, _RetAddress]: ...
  211. async def sock_connect(self, sock: socket, address: _Address) -> None: ...
  212. async def sock_recvfrom(self, sock: socket, bufsize: int) -> bytes: ...
  213. async def sock_recvfrom_into(self, sock: socket, buf: bytearray, nbytes: int = ...) -> int: ...
  214. async def sock_sendto(self, sock: socket, data: bytes, address: _Address) -> None: ...
  215. async def connect_accepted_socket(
  216. self,
  217. protocol_factory: Callable[[], _ProtocolT],
  218. sock: socket,
  219. *,
  220. ssl: _SSLContext = ...,
  221. ssl_handshake_timeout: Optional[float] = ...,
  222. ssl_shutdown_timeout: Optional[float] = ...,
  223. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  224. async def run_in_executor(
  225. self, executor: Any, func: Callable[..., _T], *args: Any
  226. ) -> _T: ...
  227. def set_default_executor(self, executor: Any) -> None: ...
  228. async def subprocess_shell(
  229. self,
  230. protocol_factory: Callable[[], _ProtocolT],
  231. cmd: Union[bytes, str],
  232. *,
  233. stdin: Any = ...,
  234. stdout: Any = ...,
  235. stderr: Any = ...,
  236. **kwargs: Any,
  237. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  238. async def subprocess_exec(
  239. self,
  240. protocol_factory: Callable[[], _ProtocolT],
  241. *args: Any,
  242. stdin: Any = ...,
  243. stdout: Any = ...,
  244. stderr: Any = ...,
  245. **kwargs: Any,
  246. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  247. async def connect_read_pipe(
  248. self, protocol_factory: Callable[[], _ProtocolT], pipe: Any
  249. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  250. async def connect_write_pipe(
  251. self, protocol_factory: Callable[[], _ProtocolT], pipe: Any
  252. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  253. def add_signal_handler(
  254. self, sig: int, callback: Callable[..., Any], *args: Any
  255. ) -> None: ...
  256. def remove_signal_handler(self, sig: int) -> bool: ...
  257. async def create_datagram_endpoint(
  258. self,
  259. protocol_factory: Callable[[], _ProtocolT],
  260. local_addr: Optional[Tuple[str, int]] = ...,
  261. remote_addr: Optional[Tuple[str, int]] = ...,
  262. *,
  263. family: int = ...,
  264. proto: int = ...,
  265. flags: int = ...,
  266. reuse_address: Optional[bool] = ...,
  267. reuse_port: Optional[bool] = ...,
  268. allow_broadcast: Optional[bool] = ...,
  269. sock: Optional[socket] = ...,
  270. ) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
  271. async def shutdown_asyncgens(self) -> None: ...
  272. async def shutdown_default_executor(
  273. self,
  274. timeout: Optional[float] = ...,
  275. ) -> None: ...
  276. # Loop doesn't implement these, but since they are marked as abstract in typeshed,
  277. # we have to put them in so mypy thinks the base methods are overridden
  278. async def sendfile(
  279. self,
  280. transport: asyncio.BaseTransport,
  281. file: IO[bytes],
  282. offset: int = ...,
  283. count: Optional[int] = ...,
  284. *,
  285. fallback: bool = ...,
  286. ) -> int: ...
  287. async def sock_sendfile(
  288. self,
  289. sock: socket,
  290. file: IO[bytes],
  291. offset: int = ...,
  292. count: Optional[int] = ...,
  293. *,
  294. fallback: bool = ...
  295. ) -> int: ...