Skip to content

Commit 24f8ebf

Browse files
committed
asyncio doc: Move streams to their own dedicated page
1 parent c8ea813 commit 24f8ebf

3 files changed

Lines changed: 211 additions & 209 deletions

File tree

Doc/library/asyncio-protocol.rst

Lines changed: 3 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. currentmodule:: asyncio
22

3-
+++++++++++++++++++++++++++++++++
4-
Transports, streams and protocols
5-
+++++++++++++++++++++++++++++++++
3+
+++++++++++++++++++++++++
4+
Transports and protocols
5+
+++++++++++++++++++++++++
66

77
.. _transport:
88

@@ -228,212 +228,6 @@ BaseSubprocessTransport
228228
stop the subprocess.
229229

230230

231-
Streams
232-
=======
233-
234-
Stream functions
235-
----------------
236-
237-
.. function:: open_connection(host=None, port=None, *, loop=None, limit=_DEFAULT_LIMIT, **kwds)
238-
239-
A wrapper for :meth:`~BaseEventLoop.create_connection()` returning a (reader,
240-
writer) pair.
241-
242-
The reader returned is a :class:`StreamReader` instance; the writer is
243-
a :class:`StreamWriter` instance.
244-
245-
The arguments are all the usual arguments to
246-
:meth:`BaseEventLoop.create_connection` except *protocol_factory*; most
247-
common are positional host and port, with various optional keyword arguments
248-
following.
249-
250-
Additional optional keyword arguments are *loop* (to set the event loop
251-
instance to use) and *limit* (to set the buffer limit passed to the
252-
:class:`StreamReader`).
253-
254-
(If you want to customize the :class:`StreamReader` and/or
255-
:class:`StreamReaderProtocol` classes, just copy the code -- there's really
256-
nothing special here except some convenience.)
257-
258-
This function returns a :ref:`coroutine object <coroutine>`.
259-
260-
.. function:: start_server(client_connected_cb, host=None, port=None, *, loop=None, limit=_DEFAULT_LIMIT, **kwds)
261-
262-
Start a socket server, call back for each client connected.
263-
264-
The first parameter, *client_connected_cb*, takes two parameters:
265-
*client_reader*, *client_writer*. *client_reader* is a
266-
:class:`StreamReader` object, while *client_writer* is a
267-
:class:`StreamWriter` object. This parameter can either be a plain callback
268-
function or a :ref:`coroutine function <coroutine>`; if it is a coroutine
269-
function, it will be automatically converted into a :class:`Task`.
270-
271-
The rest of the arguments are all the usual arguments to
272-
:meth:`~BaseEventLoop.create_server()` except *protocol_factory*; most
273-
common are positional host and port, with various optional keyword arguments
274-
following. The return value is the same as
275-
:meth:`~BaseEventLoop.create_server()`.
276-
277-
Additional optional keyword arguments are *loop* (to set the event loop
278-
instance to use) and *limit* (to set the buffer limit passed to the
279-
:class:`StreamReader`).
280-
281-
The return value is the same as :meth:`~BaseEventLoop.create_server()`, i.e.
282-
a :class:`AbstractServer` object which can be used to stop the service.
283-
284-
This function returns a :ref:`coroutine object <coroutine>`.
285-
286-
287-
StreamReader
288-
------------
289-
290-
.. class:: StreamReader(limit=_DEFAULT_LIMIT, loop=None)
291-
292-
.. method:: exception()
293-
294-
Get the exception.
295-
296-
.. method:: feed_eof()
297-
298-
XXX
299-
300-
.. method:: feed_data(data)
301-
302-
XXX
303-
304-
.. method:: set_exception(exc)
305-
306-
Set the exception.
307-
308-
.. method:: set_transport(transport)
309-
310-
Set the transport.
311-
312-
.. method:: read(n=-1)
313-
314-
XXX
315-
316-
This method returns a :ref:`coroutine object <coroutine>`.
317-
318-
.. method:: readline()
319-
320-
XXX
321-
322-
This method returns a :ref:`coroutine object <coroutine>`.
323-
324-
.. method:: readexactly(n)
325-
326-
XXX
327-
328-
This method returns a :ref:`coroutine object <coroutine>`.
329-
330-
331-
StreamWriter
332-
------------
333-
334-
.. class:: StreamWriter(transport, protocol, reader, loop)
335-
336-
Wraps a Transport.
337-
338-
This exposes :meth:`write`, :meth:`writelines`, :meth:`can_write_eof()`,
339-
:meth:`write_eof`, :meth:`get_extra_info` and :meth:`close`. It adds
340-
:meth:`drain` which returns an optional :class:`Future` on which you can
341-
wait for flow control. It also adds a transport attribute which references
342-
the :class:`Transport` directly.
343-
344-
.. attribute:: transport
345-
346-
Transport.
347-
348-
.. method:: close()
349-
350-
Close the transport: see :meth:`BaseTransport.close`.
351-
352-
.. method:: drain()
353-
354-
This method has an unusual return value.
355-
356-
The intended use is to write::
357-
358-
w.write(data)
359-
yield from w.drain()
360-
361-
When there's nothing to wait for, :meth:`drain()` returns ``()``, and the
362-
yield-from continues immediately. When the transport buffer is full (the
363-
protocol is paused), :meth:`drain` creates and returns a
364-
:class:`Future` and the yield-from will block until
365-
that Future is completed, which will happen when the buffer is
366-
(partially) drained and the protocol is resumed.
367-
368-
.. method:: get_extra_info(name, default=None)
369-
370-
Return optional transport information: see
371-
:meth:`BaseTransport.get_extra_info`.
372-
373-
.. method:: write(data)
374-
375-
Write some *data* bytes to the transport: see
376-
:meth:`WriteTransport.write`.
377-
378-
.. method:: writelines(data)
379-
380-
Write a list (or any iterable) of data bytes to the transport:
381-
see :meth:`WriteTransport.writelines`.
382-
383-
.. method:: can_write_eof()
384-
385-
Return :const:`True` if the transport supports :meth:`write_eof`,
386-
:const:`False` if not. See :meth:`WriteTransport.can_write_eof`.
387-
388-
.. method:: write_eof()
389-
390-
Close the write end of the transport after flushing buffered data:
391-
see :meth:`WriteTransport.write_eof`.
392-
393-
394-
StreamReaderProtocol
395-
--------------------
396-
397-
.. class:: StreamReaderProtocol(stream_reader, client_connected_cb=None, loop=None)
398-
399-
Trivial helper class to adapt between :class:`Protocol` and
400-
:class:`StreamReader`. Sublclass of :class:`Protocol`.
401-
402-
*stream_reader* is a :class:`StreamReader` instance, *client_connected_cb*
403-
is an optional function called with (stream_reader, stream_writer) when a
404-
connection is made, *loop* is the event loop instance to use.
405-
406-
(This is a helper class instead of making :class:`StreamReader` itself a
407-
:class:`Protocol` subclass, because the :class:`StreamReader` has other
408-
potential uses, and to prevent the user of the :class:`StreamReader` to
409-
accidentally call inappropriate methods of the protocol.)
410-
411-
.. method:: connection_made(transport)
412-
413-
XXX
414-
415-
.. method:: connection_lost(exc)
416-
417-
XXX
418-
419-
.. method:: data_received(data)
420-
421-
XXX
422-
423-
.. method:: eof_received()
424-
425-
XXX
426-
427-
.. method:: pause_writing()
428-
429-
XXX
430-
431-
.. method:: resume_writing()
432-
433-
XXX
434-
435-
436-
437231
.. _protocol:
438232

439233
Protocols

0 commit comments

Comments
 (0)