summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/selector_events.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2017-12-15 01:53:26 (GMT)
committerGitHub <noreply@github.com>2017-12-15 01:53:26 (GMT)
commit19a44f63c738388ef3c8515348b4ffc061dfd627 (patch)
tree6de5ddd62a1bdee7a90e5fe8fc59348fe7c4f4f8 /Lib/asyncio/selector_events.py
parent41264f1cd4d6066b2797ff07cae465c1e06ff3b2 (diff)
downloadcpython-19a44f63c738388ef3c8515348b4ffc061dfd627.zip
cpython-19a44f63c738388ef3c8515348b4ffc061dfd627.tar.gz
cpython-19a44f63c738388ef3c8515348b4ffc061dfd627.tar.bz2
bpo-32327: Convert asyncio functions documented as coroutines to coroutines. (#4872)
Diffstat (limited to 'Lib/asyncio/selector_events.py')
-rw-r--r--Lib/asyncio/selector_events.py30
1 files changed, 10 insertions, 20 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 2467e23..78ebf3e 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -336,20 +336,18 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
self._ensure_fd_no_transport(fd)
return self._remove_writer(fd)
- def sock_recv(self, sock, n):
+ async def sock_recv(self, sock, n):
"""Receive data from the socket.
The return value is a bytes object representing the data received.
The maximum amount of data to be received at once is specified by
nbytes.
-
- This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
self._sock_recv(fut, None, sock, n)
- return fut
+ return await fut
def _sock_recv(self, fut, registered_fd, sock, n):
# _sock_recv() can add itself as an I/O callback if the operation can't
@@ -372,19 +370,17 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
else:
fut.set_result(data)
- def sock_recv_into(self, sock, buf):
+ async def sock_recv_into(self, sock, buf):
"""Receive data from the socket.
The received data is written into *buf* (a writable buffer).
The return value is the number of bytes written.
-
- This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
self._sock_recv_into(fut, None, sock, buf)
- return fut
+ return await fut
def _sock_recv_into(self, fut, registered_fd, sock, buf):
# _sock_recv_into() can add itself as an I/O callback if the operation
@@ -408,7 +404,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
else:
fut.set_result(nbytes)
- def sock_sendall(self, sock, data):
+ async def sock_sendall(self, sock, data):
"""Send data to the socket.
The socket must be connected to a remote socket. This method continues
@@ -416,8 +412,6 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
error occurs. None is returned on success. On error, an exception is
raised, and there is no way to determine how much data, if any, was
successfully processed by the receiving end of the connection.
-
- This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
@@ -426,7 +420,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
self._sock_sendall(fut, None, sock, data)
else:
fut.set_result(None)
- return fut
+ return await fut
def _sock_sendall(self, fut, registered_fd, sock, data):
if registered_fd is not None:
@@ -459,11 +453,9 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
raise ValueError("the socket must be non-blocking")
if not hasattr(socket, 'AF_UNIX') or sock.family != socket.AF_UNIX:
- resolved = base_events._ensure_resolved(
+ resolved = await self._ensure_resolved(
address, family=sock.family, proto=sock.proto, loop=self)
- if not resolved.done():
- await resolved
- _, _, _, _, address = resolved.result()[0]
+ _, _, _, _, address = resolved[0]
fut = self.create_future()
self._sock_connect(fut, sock, address)
@@ -506,21 +498,19 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
else:
fut.set_result(None)
- def sock_accept(self, sock):
+ async def sock_accept(self, sock):
"""Accept a connection.
The socket must be bound to an address and listening for connections.
The return value is a pair (conn, address) where conn is a new socket
object usable to send and receive data on the connection, and address
is the address bound to the socket on the other end of the connection.
-
- This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
self._sock_accept(fut, False, sock)
- return fut
+ return await fut
def _sock_accept(self, fut, registered, sock):
fd = sock.fileno()