Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d143209

Browse files
committed
Tulip issue 83: document more asyncio functions in docstrings
1 parent 54c4b8e commit d143209

3 files changed

Lines changed: 58 additions & 11 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,10 @@ Creating listening connections
311311

312312
.. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None)
313313

314-
A :ref:`coroutine <coroutine>` method which creates a TCP server bound to
315-
host and port.
314+
Create a TCP server bound to host and port. Return an
315+
:class:`AbstractServer` object which can be used to stop the service.
316316

317-
The return value is a :class:`AbstractServer` object which can be used to stop
318-
the service.
317+
This method is a :ref:`coroutine <coroutine>`.
319318

320319
If *host* is an empty string or None all interfaces are assumed
321320
and a list of multiple sockets will be returned (most likely

Lib/asyncio/base_events.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def _assert_is_current_event_loop(self):
320320
"than the current one")
321321

322322
def call_soon_threadsafe(self, callback, *args):
323-
"""XXX"""
323+
"""Like call_soon(), but thread safe."""
324324
handle = self._call_soon(callback, args, check_loop=False)
325325
self._write_to_self()
326326
return handle
@@ -358,7 +358,17 @@ def getnameinfo(self, sockaddr, flags=0):
358358
def create_connection(self, protocol_factory, host=None, port=None, *,
359359
ssl=None, family=0, proto=0, flags=0, sock=None,
360360
local_addr=None, server_hostname=None):
361-
"""XXX"""
361+
"""Connect to a TCP server.
362+
363+
Create a streaming transport connection to a given Internet host and
364+
port: socket family AF_INET or socket.AF_INET6 depending on host (or
365+
family if specified), socket type SOCK_STREAM. protocol_factory must be
366+
a callable returning a protocol instance.
367+
368+
This method is a coroutine which will try to establish the connection
369+
in the background. When successful, the coroutine returns a
370+
(transport, protocol) pair.
371+
"""
362372
if server_hostname is not None and not ssl:
363373
raise ValueError('server_hostname is only meaningful with ssl')
364374

@@ -557,7 +567,12 @@ def create_server(self, protocol_factory, host=None, port=None,
557567
backlog=100,
558568
ssl=None,
559569
reuse_address=None):
560-
"""XXX"""
570+
"""Create a TCP server bound to host and port.
571+
572+
Return an AbstractServer object which can be used to stop the service.
573+
574+
This method is a coroutine.
575+
"""
561576
if isinstance(ssl, bool):
562577
raise TypeError('ssl argument must be an SSLContext or None')
563578
if host is not None or port is not None:

Lib/asyncio/selector_events.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,14 @@ def remove_writer(self, fd):
226226
return False
227227

228228
def sock_recv(self, sock, n):
229-
"""XXX"""
229+
"""Receive data from the socket.
230+
231+
The return value is a bytes object representing the data received.
232+
The maximum amount of data to be received at once is specified by
233+
nbytes.
234+
235+
This method is a coroutine.
236+
"""
230237
fut = futures.Future(loop=self)
231238
self._sock_recv(fut, False, sock, n)
232239
return fut
@@ -253,7 +260,16 @@ def _sock_recv(self, fut, registered, sock, n):
253260
fut.set_result(data)
254261

255262
def sock_sendall(self, sock, data):
256-
"""XXX"""
263+
"""Send data to the socket.
264+
265+
The socket must be connected to a remote socket. This method continues
266+
to send data from data until either all data has been sent or an
267+
error occurs. None is returned on success. On error, an exception is
268+
raised, and there is no way to determine how much data, if any, was
269+
successfully processed by the receiving end of the connection.
270+
271+
This method is a coroutine.
272+
"""
257273
fut = futures.Future(loop=self)
258274
if data:
259275
self._sock_sendall(fut, False, sock, data)
@@ -285,7 +301,16 @@ def _sock_sendall(self, fut, registered, sock, data):
285301
self.add_writer(fd, self._sock_sendall, fut, True, sock, data)
286302

287303
def sock_connect(self, sock, address):
288-
"""XXX"""
304+
"""Connect to a remote socket at address.
305+
306+
The address must be already resolved to avoid the trap of hanging the
307+
entire event loop when the address requires doing a DNS lookup. For
308+
example, it must be an IP address, not an hostname, for AF_INET and
309+
AF_INET6 address families. Use getaddrinfo() to resolve the hostname
310+
asynchronously.
311+
312+
This method is a coroutine.
313+
"""
289314
fut = futures.Future(loop=self)
290315
try:
291316
base_events._check_resolved_address(sock, address)
@@ -318,7 +343,15 @@ def _sock_connect(self, fut, registered, sock, address):
318343
fut.set_result(None)
319344

320345
def sock_accept(self, sock):
321-
"""XXX"""
346+
"""Accept a connection.
347+
348+
The socket must be bound to an address and listening for connections.
349+
The return value is a pair (conn, address) where conn is a new socket
350+
object usable to send and receive data on the connection, and address
351+
is the address bound to the socket on the other end of the connection.
352+
353+
This method is a coroutine.
354+
"""
322355
fut = futures.Future(loop=self)
323356
self._sock_accept(fut, False, sock)
324357
return fut

0 commit comments

Comments
 (0)