Skip to content

Commit c0d062f

Browse files
elprans1st1
authored andcommitted
bpo-33736: Improve the documentation of asyncio stream APIs (GH-7326)
1 parent 6860629 commit c0d062f

File tree

4 files changed

+75
-35
lines changed

4 files changed

+75
-35
lines changed

Doc/library/asyncio-eventloop.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ Creating connections
445445

446446
.. versionchanged:: 3.7
447447

448-
The *path* parameter can now be a :class:`~pathlib.Path` object.
448+
The *path* parameter can now be a :term:`path-like object`.
449449

450450

451451
Creating listening connections
@@ -536,7 +536,7 @@ Creating listening connections
536536

537537
.. versionadded:: 3.7
538538

539-
The *ssl_handshake_timeout* parameter.
539+
The *ssl_handshake_timeout* and *start_serving* parameters.
540540

541541
.. versionchanged:: 3.7
542542

Doc/library/asyncio-stream.rst

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,72 +18,110 @@ Stream functions
1818
exactly what you want, feel free to copy their code.
1919

2020

21-
.. coroutinefunction:: open_connection(host=None, port=None, \*, loop=None, limit=None, \*\*kwds)
21+
.. coroutinefunction:: open_connection(host=None, port=None, \*, loop=None, limit=None, ssl=None, family=0, proto=0, flags=0, sock=None, local_addr=None, server_hostname=None, ssl_handshake_timeout=None)
2222

2323
A wrapper for :meth:`~AbstractEventLoop.create_connection()` returning a (reader,
2424
writer) pair.
2525

2626
The reader returned is a :class:`StreamReader` instance; the writer is
2727
a :class:`StreamWriter` instance.
2828

29-
The arguments are all the usual arguments to
30-
:meth:`AbstractEventLoop.create_connection` except *protocol_factory*; most
31-
common are positional host and port, with various optional keyword arguments
32-
following.
29+
When specified, the *loop* argument determines which event loop to use,
30+
and the *limit* argument determines the buffer size limit used by the
31+
returned :class:`StreamReader` instance.
3332

34-
Additional optional keyword arguments are *loop* (to set the event loop
35-
instance to use) and *limit* (to set the buffer limit passed to the
36-
:class:`StreamReader`).
33+
The rest of the arguments are passed directly to
34+
:meth:`AbstractEventLoop.create_connection`.
3735

3836
This function is a :ref:`coroutine <coroutine>`.
3937

40-
.. coroutinefunction:: start_server(client_connected_cb, host=None, port=None, \*, loop=None, limit=None, \*\*kwds)
38+
.. versionadded:: 3.7
39+
40+
The *ssl_handshake_timeout* parameter.
41+
42+
.. coroutinefunction:: start_server(client_connected_cb, host=None, port=None, \*, loop=None, limit=None, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None, reuse_port=None, ssl_handshake_timeout=None, start_serving=True)
4143

4244
Start a socket server, with a callback for each client connected. The return
4345
value is the same as :meth:`~AbstractEventLoop.create_server()`.
4446

45-
The *client_connected_cb* parameter is called with two parameters:
46-
*client_reader*, *client_writer*. *client_reader* is a
47-
:class:`StreamReader` object, while *client_writer* is a
48-
:class:`StreamWriter` object. The *client_connected_cb* parameter can
49-
either be a plain callback function or a :ref:`coroutine function
50-
<coroutine>`; if it is a coroutine function, it will be automatically
51-
converted into a :class:`Task`.
47+
The *client_connected_cb* callback is called whenever a new client
48+
connection is established. It receives a reader/writer pair as two
49+
arguments, the first is a :class:`StreamReader` instance,
50+
and the second is a :class:`StreamWriter` instance.
51+
52+
*client_connected_cb* accepts a plain callable or a
53+
:ref:`coroutine function <coroutine>`; if it is a coroutine function,
54+
it will be automatically converted into a :class:`Task`.
5255

53-
The rest of the arguments are all the usual arguments to
54-
:meth:`~AbstractEventLoop.create_server()` except *protocol_factory*; most
55-
common are positional *host* and *port*, with various optional keyword
56-
arguments following.
56+
When specified, the *loop* argument determines which event loop to use,
57+
and the *limit* argument determines the buffer size limit used by the
58+
:class:`StreamReader` instance passed to *client_connected_cb*.
5759

58-
Additional optional keyword arguments are *loop* (to set the event loop
59-
instance to use) and *limit* (to set the buffer limit passed to the
60-
:class:`StreamReader`).
60+
The rest of the arguments are passed directly to
61+
:meth:`~AbstractEventLoop.create_server()`.
6162

6263
This function is a :ref:`coroutine <coroutine>`.
6364

64-
.. coroutinefunction:: open_unix_connection(path=None, \*, loop=None, limit=None, **kwds)
65+
.. versionadded:: 3.7
66+
67+
The *ssl_handshake_timeout* and *start_serving* parameters.
68+
69+
.. coroutinefunction:: open_unix_connection(path=None, \*, loop=None, limit=None, ssl=None, sock=None, server_hostname=None, ssl_handshake_timeout=None)
6570

6671
A wrapper for :meth:`~AbstractEventLoop.create_unix_connection()` returning
6772
a (reader, writer) pair.
6873

69-
See :func:`open_connection` for information about return value and other
70-
details.
74+
When specified, the *loop* argument determines which event loop to use,
75+
and the *limit* argument determines the buffer size limit used by the
76+
returned :class:`StreamReader` instance.
77+
78+
The rest of the arguments are passed directly to
79+
:meth:`~AbstractEventLoop.create_unix_connection()`.
7180

7281
This function is a :ref:`coroutine <coroutine>`.
7382

7483
Availability: UNIX.
7584

76-
.. coroutinefunction:: start_unix_server(client_connected_cb, path=None, \*, loop=None, limit=None, **kwds)
85+
.. versionadded:: 3.7
86+
87+
The *ssl_handshake_timeout* parameter.
88+
89+
.. versionchanged:: 3.7
90+
91+
The *path* parameter can now be a :term:`path-like object`
92+
93+
.. coroutinefunction:: start_unix_server(client_connected_cb, path=None, \*, loop=None, limit=None, sock=None, backlog=100, ssl=None, ssl_handshake_timeout=None, start_serving=True)
7794

7895
Start a UNIX Domain Socket server, with a callback for each client connected.
7996

80-
See :func:`start_server` for information about return value and other
81-
details.
97+
The *client_connected_cb* callback is called whenever a new client
98+
connection is established. It receives a reader/writer pair as two
99+
arguments, the first is a :class:`StreamReader` instance,
100+
and the second is a :class:`StreamWriter` instance.
101+
102+
*client_connected_cb* accepts a plain callable or a
103+
:ref:`coroutine function <coroutine>`; if it is a coroutine function,
104+
it will be automatically converted into a :class:`Task`.
105+
106+
When specified, the *loop* argument determines which event loop to use,
107+
and the *limit* argument determines the buffer size limit used by the
108+
:class:`StreamReader` instance passed to *client_connected_cb*.
109+
110+
The rest of the arguments are passed directly to
111+
:meth:`~AbstractEventLoop.create_unix_server()`.
82112

83113
This function is a :ref:`coroutine <coroutine>`.
84114

85115
Availability: UNIX.
86116

117+
.. versionadded:: 3.7
118+
119+
The *ssl_handshake_timeout* and *start_serving* parameters.
120+
121+
.. versionchanged:: 3.7
122+
123+
The *path* parameter can now be a :term:`path-like object`.
124+
87125

88126
StreamReader
89127
============
@@ -475,4 +513,3 @@ Coroutine waiting until a socket receives data using the
475513
<asyncio-watch-read-event>` example uses the low-level
476514
:meth:`AbstractEventLoop.add_reader` method to register the file descriptor of a
477515
socket.
478-

Doc/whatsnew/3.7.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,12 @@ include:
699699
gained support for Unix sockets.
700700
(Contributed by Quentin Dawans in :issue:`31245`.)
701701

702-
* The :meth:`loop.create_connection() <asyncio.AbstractEventLoop.create_connection>`,
702+
* The :func:`asyncio.open_connection`, :func:`asyncio.start_server` functions,
703+
:meth:`loop.create_connection() <asyncio.AbstractEventLoop.create_connection>`,
703704
:meth:`loop.create_server() <asyncio.AbstractEventLoop.create_server>`,
704-
:meth:`loop.create_unix_server() <asyncio.AbstractEventLoop.create_unix_server>`, and
705705
:meth:`loop.create_accepted_socket() <asyncio.BaseEventLoop.connect_accepted_socket>`
706-
now accept the *ssl_handshake_timeout* keyword argument.
706+
methods and their corresponding UNIX socket variants now accept the
707+
*ssl_handshake_timeout* keyword argument.
707708
(Contributed by Neil Aspinall in :issue:`29970`.)
708709

709710
* The new :meth:`Handle.cancelled() <asyncio.Handle.cancelled>` method returns
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve the documentation of :func:`asyncio.open_connection`,
2+
:func:`asyncio.start_server` and their UNIX socket counterparts.

0 commit comments

Comments
 (0)