-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-36889: Document Stream and StreamServer. #14203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Clarifications :
Thanks |
asvetlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
I have several comments/suggestions.
- There are
connect_read_pipe()andconnect_write_pipe()functions. Please document them. - All public
StreamServer/UnixStreamServerfunctions should be documented:bind(),is_bound(),abort().
Doc/library/asyncio-stream.rst
Outdated
|
|
||
| This function internally uses :meth:`loop.create_connection` to return a | ||
| :class:`Stream` object of the mode ``READWRITE`` that can be used as a reader | ||
| and a writer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reflect the fact that async with connect() can be used as well as just await connect().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a note that connect returns a stream object which is awaitable and also about using it as context manager. Let me know if it needs to be reworded that connect itself is awaitable.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
…write_pipe and other StreamServer methods
Doc/library/asyncio-stream.rst
Outdated
|
|
||
| writer.write(query.encode('latin-1')) | ||
| stream.write(query.encode('latin-1')) | ||
| while True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some PEP 572 related example.
while True:
line = await stream.readline()
if not line:
break
line = line.decode('latin1').rstrip()
if line:
print(f'HTTP header> {line}')while (line := await stream.readline()):
line = line.decode('latin1').rstrip()
if line:
print(f'HTTP header> {line}')There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Agree, := provides better readable code. Please apply.
|
I have made the requested changes; please review again
Clarifications :
|
|
Thanks for making the requested changes! @asvetlov: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good step forward!
I left some comments, please fix/discuss
Doc/library/asyncio-stream.rst
Outdated
|
|
||
| print('Close the connection') | ||
| await writer.close() | ||
| print('Close the connection') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is confusing, it is not followed by an actual closing code.
Maybe better to drop it, async with provides enough implication that the stream is closed on exit from the block I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the message about closing is not needed. Removed. Thanks.
Doc/library/asyncio-stream.rst
Outdated
|
|
||
|
|
||
| .. coroutinefunction:: connect(host=None, port=None, \*, \ | ||
| loop=None, limit=2**16, ssl=None, family=0, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loop parameter is not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, removed.
Doc/library/asyncio-stream.rst
Outdated
|
|
||
| This function internally uses :meth:`loop.create_connection` to return an awaitable | ||
| :class:`Stream` object of the mode ``READWRITE`` that can be used as a reader | ||
| and a writer. The function can also be used as an async context manager where it's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just The function can also be used as an async context manager,
drop where it's automatically awaited.
Technically it's not correct: connect returns an internal undocumented object that can be awaited or used by async with. I don't want to document this object but want to provide a clear vision of how to use connect call.
Maybe two short usage examples can help?
E.g.
Connect to TCP socket on *host* : *port* address, return a read-write :class:`Stream` object.
The function can be used with ``await`` to get a connected stream::
stream = await asyncio.connect('127.0.0.1', 8888)
Also, ``async with`` form is supported, the stream is closed on exit from the block::
async with asyncio.connect('127.0.0.1', 8888) as stream:
...
*limit* determines the buffer size limit used by the returned :class:`Stream` instance. By default the limit is set to 64 KiB.
The rest of the arguments are passed directly to :meth:`loop.create_connection`.
I'm not sure about the exact text but I hope you've got my idea. Documentation is hard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed it's hard :) I have adopted your suggestion and formatted it. Did the same for connect_unix too.
Doc/library/asyncio-stream.rst
Outdated
|
|
||
| .. coroutinefunction:: connect_read_pipe(pipe, *, limit=2**16) | ||
|
|
||
| Takes a :term:`file-like object <file object>` to return a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Takes a :term:`file-like object <file object>` to return a | |
| Takes a :term:`file-like object <file object>` *pipe* to return a |
Doc/library/asyncio-stream.rst
Outdated
|
|
||
| .. coroutinefunction:: connect_write_pipe(pipe, *, limit=2**16) | ||
|
|
||
| Takes a a :term:`file-like object <file object>` to return a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Takes a a :term:`file-like object <file object>` to return a | |
| Takes a a :term:`file-like object <file object>` *pipe* to return a |
Doc/library/asyncio-stream.rst
Outdated
| .. deprecated-removed:: 3.8 3.10 | ||
|
|
||
| `open_unix_connection()` is deprecated if favor of `connect_unix()`. | ||
| `open_unix_connection()` is deprecated if favor of :func:`connect_unix`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `open_unix_connection()` is deprecated if favor of :func:`connect_unix`. | |
| ``open_unix_connection()`` is deprecated if favor of :func:`connect_unix`. |
Doc/library/asyncio-stream.rst
Outdated
| .. deprecated-removed:: 3.8 3.10 | ||
|
|
||
| `start_unix_server()` is deprecated in favor of `UnixStreamServer()`. | ||
| `start_unix_server()` is deprecated in favor of :class:`UnixStreamServer`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `start_unix_server()` is deprecated in favor of :class:`UnixStreamServer`. | |
| ``start_unix_server()`` is deprecated in favor of :class:`UnixStreamServer`. |
| limit=2**16, family=socket.AF_UNSPEC, \ | ||
| flags=socket.AI_PASSIVE, sock=None, backlog=100, \ | ||
| ssl=None, reuse_address=None, reuse_port=None, \ | ||
| ssl_handshake_timeout=None, shutdown_timeout=60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguments should be described here. A link to loop.create_server() can be used to don't repeat family, flags etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added doc for client_connected_cb and limit. I have added a note that rest of the arguments are passed to loop.create_server.
|
|
||
| .. class:: UnixStreamServer(client_connected_cb, /, path=None, *, \ | ||
| limit=2**16, sock=None, backlog=100, \ | ||
| ssl=None, ssl_handshake_timeout=None, shutdown_timeout=60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe constructor arguments please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added doc for client_connected_cb and limit. I have added a note that rest of the arguments are passed to loop.create_unix_server.
Doc/library/asyncio-stream.rst
Outdated
|
|
||
| writer.write(query.encode('latin-1')) | ||
| stream.write(query.encode('latin-1')) | ||
| while True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Agree, := provides better readable code. Please apply.
I don't know. I don't want to make their base class public, so duplication is probably ok. We keep references is a good shape at least.
Yes, please do. |
|
Changes made :
Please review the changes. Thanks. |
asvetlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
|
Thanks @tirkarthi for the PR, and @asvetlov for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
(cherry picked from commit 6793cce) Co-authored-by: Xtreak <[email protected]>
|
GH-14349 is a backport of this pull request to the 3.8 branch. |
|
Thank you very much for the guidance Andrew :) |
(cherry picked from commit 6793cce) Co-authored-by: Xtreak <[email protected]>
Stream,StreamServer,UnixStreamServer,connectandconnect_unix.Streamto avoid DeprecationWarning.https://bugs.python.org/issue36889