1
+ from socket import socket
2
+ import ssl
1
3
import sys
2
4
from typing import Any , Awaitable , Callable , Dict , Generator , List , Optional , Tuple , TypeVar , Union , overload
3
5
from abc import ABCMeta , abstractmethod
4
6
from asyncio .futures import Future
5
7
from asyncio .coroutines import coroutine
8
+ from asyncio .protocols import BaseProtocol
6
9
from asyncio .tasks import Task
10
+ from asyncio .transports import BaseTransport
7
11
8
12
__all__ = ... # type: str
9
13
10
14
_T = TypeVar ('_T' )
11
15
_Context = Dict [str , Any ]
16
+ _ExceptionHandler = Callable [[AbstractEventLoop , _Context ], Any ]
17
+ _ProtocolFactory = Callable [[], BaseProtocol ]
18
+ _SSLContext = Union [bool , None , ssl .SSLContext ]
19
+ _TransProtPair = Tuple [BaseTransport , BaseProtocol ]
12
20
13
21
PIPE = ... # type: Any # from subprocess.PIPE
14
22
@@ -27,7 +35,7 @@ class Handle:
27
35
class AbstractServer :
28
36
def close (self ) -> None : ...
29
37
@coroutine
30
- def wait_closed (self ) -> Generator [Any , Any , None ]: ...
38
+ def wait_closed (self ) -> Generator [Any , None , None ]: ...
31
39
32
40
class AbstractEventLoop (metaclass = ABCMeta ):
33
41
@abstractmethod
@@ -36,7 +44,7 @@ class AbstractEventLoop(metaclass=ABCMeta):
36
44
# Can't use a union, see mypy issue # 1873.
37
45
@overload
38
46
@abstractmethod
39
- def run_until_complete (self , future : Generator [Any , Any , _T ]) -> _T : ...
47
+ def run_until_complete (self , future : Generator [Any , None , _T ]) -> _T : ...
40
48
@overload
41
49
@abstractmethod
42
50
def run_until_complete (self , future : Awaitable [_T ]) -> _T : ...
@@ -46,7 +54,13 @@ class AbstractEventLoop(metaclass=ABCMeta):
46
54
@abstractmethod
47
55
def is_running (self ) -> bool : ...
48
56
@abstractmethod
57
+ def is_closed (self ) -> bool : ...
58
+ @abstractmethod
49
59
def close (self ) -> None : ...
60
+ if sys .version_info >= (3 , 6 ):
61
+ @abstractmethod
62
+ @coroutine
63
+ def shutdown_asyncgens (self ) -> Generator [Any , None , None ]: ...
50
64
# Methods scheduling callbacks. All these return Handles.
51
65
@abstractmethod
52
66
def call_soon (self , callback : Callable [..., Any ], * args : Any ) -> Handle : ...
@@ -71,48 +85,63 @@ class AbstractEventLoop(metaclass=ABCMeta):
71
85
@abstractmethod
72
86
def call_soon_threadsafe (self , callback : Callable [..., Any ], * args : Any ) -> Handle : ...
73
87
@abstractmethod
88
+ @coroutine
74
89
def run_in_executor (self , executor : Any ,
75
- callback : Callable [..., Any ], * args : Any ) -> Future [Any ]: ...
90
+ callback : Callable [..., _T ], * args : Any ) -> Generator [Any , None , _T ]: ...
76
91
@abstractmethod
77
92
def set_default_executor (self , executor : Any ) -> None : ...
78
93
# Network I/O methods returning Futures.
79
94
@abstractmethod
95
+ @coroutine
80
96
def getaddrinfo (self , host : str , port : int , * ,
81
- family : int = ..., type : int = ..., proto : int = ..., flags : int = ...) -> Future [ List [Tuple [int , int , int , str , tuple ]]]: ...
97
+ family : int = ..., type : int = ..., proto : int = ..., flags : int = ...) -> Generator [ Any , None , List [Tuple [int , int , int , str , Union [ Tuple [ str , int ], Tuple [ str , int , int , int ]] ]]]: ...
82
98
@abstractmethod
83
- def getnameinfo (self , sockaddr : tuple , flags : int = ...) -> Future [Tuple [str , int ]]: ...
99
+ @coroutine
100
+ def getnameinfo (self , sockaddr : tuple , flags : int = ...) -> Generator [Any , None , Tuple [str , int ]]: ...
84
101
@abstractmethod
85
- def create_connection (self , protocol_factory : Any , host : str = ..., port : int = ..., * ,
86
- ssl : Any = ..., family : int = ..., proto : int = ..., flags : int = ..., sock : Any = ...,
87
- local_addr : str = ..., server_hostname : str = ...) -> tuple : ...
102
+ @coroutine
103
+ def create_connection (self , protocol_factory : _ProtocolFactory , host : str = ..., port : int = ..., * ,
104
+ ssl : _SSLContext = ..., family : int = ..., proto : int = ..., flags : int = ..., sock : socket = ...,
105
+ local_addr : str = ..., server_hostname : str = ...) -> Generator [Any , None , _TransProtPair ]: ...
88
106
@abstractmethod
89
- def create_server (self , protocol_factory : Any , host : str = ..., port : int = ..., * ,
107
+ @coroutine
108
+ def create_server (self , protocol_factory : _ProtocolFactory , host : str = ..., port : int = ..., * ,
90
109
family : int = ..., flags : int = ...,
91
- sock : Any = ..., backlog : int = ..., ssl : Any = ..., reuse_address : Any = ...) -> Any : ...
110
+ sock : socket = ..., backlog : int = ..., ssl : _SSLContext = ..., reuse_address : Optional [ bool ] = ...) -> Generator [ Any , None , AbstractServer ] : ...
92
111
@abstractmethod
93
- def create_unix_connection (self , protocol_factory : Any , path : str , * ,
94
- ssl : Any = ..., sock : Any = ...,
95
- server_hostname : str = ...) -> tuple : ...
112
+ @coroutine
113
+ def create_unix_connection (self , protocol_factory : _ProtocolFactory , path : str , * ,
114
+ ssl : _SSLContext = ..., sock : socket = ...,
115
+ server_hostname : str = ...) -> Generator [Any , None , _TransProtPair ]: ...
96
116
@abstractmethod
97
- def create_unix_server (self , protocol_factory : Any , path : str , * ,
98
- sock : Any = ..., backlog : int = ..., ssl : Any = ...) -> Any : ...
117
+ @coroutine
118
+ def create_unix_server (self , protocol_factory : _ProtocolFactory , path : str , * ,
119
+ sock : socket = ..., backlog : int = ..., ssl : _SSLContext = ...) -> Generator [Any , None , AbstractServer ]: ...
99
120
@abstractmethod
100
- def create_datagram_endpoint (self , protocol_factory : Any ,
121
+ @coroutine
122
+ def create_datagram_endpoint (self , protocol_factory : _ProtocolFactory ,
101
123
local_addr : str = ..., remote_addr : str = ..., * ,
102
- family : int = ..., proto : int = ..., flags : int = ...) -> tuple : ...
124
+ family : int = ..., proto : int = ..., flags : int = ...) -> Generator [Any , None , _TransProtPair ]: ...
125
+ @abstractmethod
126
+ @coroutine
127
+ def connect_accepted_socket (self , protocol_factory : _ProtocolFactory , sock : socket , * , ssl : _SSLContext = ...) -> Generator [Any , None , _TransProtPair ]: ...
103
128
# Pipes and subprocesses.
104
129
@abstractmethod
105
- def connect_read_pipe (self , protocol_factory : Any , pipe : Any ) -> tuple : ...
130
+ @coroutine
131
+ def connect_read_pipe (self , protocol_factory : _ProtocolFactory , pipe : Any ) -> Generator [Any , None , _TransProtPair ]: ...
106
132
@abstractmethod
107
- def connect_write_pipe (self , protocol_factory : Any , pipe : Any ) -> tuple : ...
133
+ @coroutine
134
+ def connect_write_pipe (self , protocol_factory : _ProtocolFactory , pipe : Any ) -> Generator [Any , None , _TransProtPair ]: ...
108
135
@abstractmethod
109
- def subprocess_shell (self , protocol_factory : Any , cmd : Union [bytes , str ], * , stdin : Any = ...,
136
+ @coroutine
137
+ def subprocess_shell (self , protocol_factory : _ProtocolFactory , cmd : Union [bytes , str ], * , stdin : Any = ...,
110
138
stdout : Any = ..., stderr : Any = ...,
111
- ** kwargs : Any ) -> tuple : ...
139
+ ** kwargs : Any ) -> Generator [ Any , None , _TransProtPair ] : ...
112
140
@abstractmethod
113
- def subprocess_exec (self , protocol_factory : Any , * args : List [Any ], stdin : Any = ...,
141
+ @coroutine
142
+ def subprocess_exec (self , protocol_factory : _ProtocolFactory , * args : List [Any ], stdin : Any = ...,
114
143
stdout : Any = ..., stderr : Any = ...,
115
- ** kwargs : Any ) -> tuple : ...
144
+ ** kwargs : Any ) -> Generator [ Any , None , _TransProtPair ] : ...
116
145
@abstractmethod
117
146
def add_reader (self , fd : int , callback : Callable [..., Any ], * args : List [Any ]) -> None : ...
118
147
@abstractmethod
@@ -123,21 +152,27 @@ class AbstractEventLoop(metaclass=ABCMeta):
123
152
def remove_writer (self , fd : int ) -> None : ...
124
153
# Completion based I/O methods returning Futures.
125
154
@abstractmethod
126
- def sock_recv (self , sock : Any , nbytes : int ) -> Any : ... # TODO
155
+ @coroutine
156
+ def sock_recv (self , sock : socket , nbytes : int ) -> Generator [Any , None , bytes ]: ...
127
157
@abstractmethod
128
- def sock_sendall (self , sock : Any , data : bytes ) -> None : ... # TODO
158
+ @coroutine
159
+ def sock_sendall (self , sock : socket , data : bytes ) -> Generator [Any , None , None ]: ...
129
160
@abstractmethod
130
- def sock_connect (self , sock : Any , address : str ) -> Any : ... # TODO
161
+ @coroutine
162
+ def sock_connect (self , sock : socket , address : str ) -> Generator [Any , None , None ]: ...
131
163
@abstractmethod
132
- def sock_accept (self , sock : Any ) -> Any : ...
164
+ @coroutine
165
+ def sock_accept (self , sock : socket ) -> Generator [Any , None , Tuple [socket , Any ]]: ...
133
166
# Signal handling.
134
167
@abstractmethod
135
168
def add_signal_handler (self , sig : int , callback : Callable [..., Any ], * args : List [Any ]) -> None : ...
136
169
@abstractmethod
137
170
def remove_signal_handler (self , sig : int ) -> None : ...
138
171
# Error handlers.
139
172
@abstractmethod
140
- def set_exception_handler (self , handler : Callable [[AbstractEventLoop , _Context ], Any ]) -> None : ...
173
+ def set_exception_handler (self , handler : _ExceptionHandler ) -> None : ...
174
+ @abstractmethod
175
+ def get_exception_handler (self ) -> _ExceptionHandler : ...
141
176
@abstractmethod
142
177
def default_exception_handler (self , context : _Context ) -> None : ...
143
178
@abstractmethod
0 commit comments