💾 Archived View for tris.fyi › pydoc › asyncio.streams captured on 2022-04-28 at 17:42:09. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-03-01)

➡️ Next capture (2022-07-16)

🚧 View Differences

-=-=-=-=-=-=-

Back to module index

Go to module by name

asyncio

asyncio.streams

This module has no docstring.

Classes

FlowControlMixin

Reusable flow control logic for StreamWriter.drain().

    This implements the protocol methods pause_writing(),
    resume_writing() and connection_lost().  If the subclass overrides
    these it must call the super methods.

    StreamWriter.drain() must wait for _drain_helper() coroutine.
    
connection_lost(self, exc)
connection_made(self, transport)

  Called when a connection is made.

          The argument is the transport representing the pipe connection.
          To receive data, wait for data_received() calls.
          When the connection is closed, connection_lost() is called.
        
data_received(self, data)

  Called when some data is received.

          The argument is a bytes object.
        
eof_received(self)

  Called when the other end calls write_eof() or equivalent.

          If this returns a false value (including None), the transport
          will close itself.  If it returns a true value, closing the
          transport is up to the protocol.
        
pause_writing(self)
resume_writing(self)

StreamReader

at_eof(self)

  Return True if the buffer is empty and 'feed_eof' was called.
exception(self)
feed_data(self, data)
feed_eof(self)
read(self, n=-1)

  Read up to `n` bytes from the stream.

          If n is not provided, or set to -1, read until EOF and return all read
          bytes. If the EOF was received and the internal buffer is empty, return
          an empty bytes object.

          If n is zero, return empty bytes object immediately.

          If n is positive, this function try to read `n` bytes, and may return
          less or equal bytes than requested, but at least one byte. If EOF was
          received before any byte is read, this function returns empty byte
          object.

          Returned value is not limited with limit, configured at stream
          creation.

          If stream was paused, this function will automatically resume it if
          needed.
        
readexactly(self, n)

  Read exactly `n` bytes.

          Raise an IncompleteReadError if EOF is reached before `n` bytes can be
          read. The IncompleteReadError.partial attribute of the exception will
          contain the partial read bytes.

          if n is zero, return empty bytes object.

          Returned value is not limited with limit, configured at stream
          creation.

          If stream was paused, this function will automatically resume it if
          needed.
        
readline(self)

  Read chunk of data from the stream until newline (b'
  ') is found.

          On success, return chunk that ends with newline. If only partial
          line can be read due to EOF, return incomplete line without
          terminating newline. When EOF was reached while no bytes read, empty
          bytes object is returned.

          If limit is reached, ValueError will be raised. In that case, if
          newline was found, complete line including newline will be removed
          from internal buffer. Else, internal buffer will be cleared. Limit is
          compared against part of the line without newline.

          If stream was paused, this function will automatically resume it if
          needed.
        
readuntil(self, separator=b'\n')

  Read data from the stream until ``separator`` is found.

          On success, the data and separator will be removed from the
          internal buffer (consumed). Returned data will include the
          separator at the end.

          Configured stream limit is used to check result. Limit sets the
          maximal length of data that can be returned, not counting the
          separator.

          If an EOF occurs and the complete separator is still not found,
          an IncompleteReadError exception will be raised, and the internal
          buffer will be reset.  The IncompleteReadError.partial attribute
          may contain the separator partially.

          If the data cannot be read because of over limit, a
          LimitOverrunError exception  will be raised, and the data
          will be left in the internal buffer, so it can be read again.
        
set_exception(self, exc)
set_transport(self, transport)

StreamReaderProtocol

Helper class to adapt between Protocol and StreamReader.

    (This is a helper class instead of making StreamReader itself a
    Protocol subclass, because the StreamReader has other potential
    uses, and to prevent the user of the StreamReader to accidentally
    call inappropriate methods of the protocol.)
    
connection_lost(self, exc)
connection_made(self, transport)
data_received(self, data)
eof_received(self)
pause_writing(self)
resume_writing(self)

StreamWriter

Wraps a Transport.

    This exposes write(), writelines(), [can_]write_eof(),
    get_extra_info() and close().  It adds drain() which returns an
    optional Future on which you can wait for flow control.  It also
    adds a transport property which references the Transport
    directly.
    
can_write_eof(self)
close(self)
drain(self)

  Flush the write buffer.

          The intended use is to write

            w.write(data)
            await w.drain()
        
get_extra_info(self, name, default=None)
is_closing(self)
wait_closed(self)
write(self, data)
write_eof(self)
writelines(self, data)
transport = <property object at 0x7ff360041900>

Functions

open_connection

open_connection(host=None, port=None, *, loop=None, limit=65536, **kwds)

  A wrapper for create_connection() returning a (reader, writer) pair.

      The reader returned is a StreamReader instance; the writer is a
      StreamWriter instance.

      The arguments are all the usual arguments to create_connection()
      except protocol_factory; most common are positional host and port,
      with various optional keyword arguments following.

      Additional optional keyword arguments are loop (to set the event loop
      instance to use) and limit (to set the buffer limit passed to the
      StreamReader).

      (If you want to customize the StreamReader and/or
      StreamReaderProtocol classes, just copy the code -- there's
      really nothing special here except some convenience.)
    

open_unix_connection

open_unix_connection(path=None, *, loop=None, limit=65536, **kwds)

  Similar to `open_connection` but works with UNIX Domain Sockets.

sleep

sleep(delay, result=None, *, loop=None)

  Coroutine that completes after a given time (in seconds).

start_server

start_server(client_connected_cb, host=None, port=None, *, loop=None, limit=65536, **kwds)

  Start a socket server, call back for each client connected.

      The first parameter, `client_connected_cb`, takes two parameters:
      client_reader, client_writer.  client_reader is a StreamReader
      object, while client_writer is a StreamWriter object.  This
      parameter can either be a plain callback function or a coroutine;
      if it is a coroutine, it will be automatically converted into a
      Task.

      The rest of the arguments are all the usual arguments to
      loop.create_server() except protocol_factory; most common are
      positional host and port, with various optional keyword arguments
      following.  The return value is the same as loop.create_server().

      Additional optional keyword arguments are loop (to set the event loop
      instance to use) and limit (to set the buffer limit passed to the
      StreamReader).

      The return value is the same as loop.create_server(), i.e. a
      Server object which can be used to stop the service.
    

start_unix_server

start_unix_server(client_connected_cb, path=None, *, loop=None, limit=65536, **kwds)

  Similar to `start_server` but works with UNIX Domain Sockets.

Other members

logger = <Logger asyncio (INFO)>

Modules

coroutines

events

exceptions

format_helpers

protocols

socket

sys

warnings

weakref