asyncutils.networking¶
Some asyncio protocols and a transport. See the asyncio documentation page.
Classes¶
Carriage Return + Line Feed protocol for Windows. |
|
Carriage Return protocol. For legacy systems no longer officially supported by python, such as Mac OS 9, such that this will never be chosen as the default. |
|
Line Feed protocol for Unix-like systems. |
|
A thread-unsafe transport that connects |
Module Contents¶
- class asyncutils.networking.CRLFProtocol[source]¶
Bases:
LineProtocolCarriage Return + Line Feed protocol for Windows.
- class asyncutils.networking.CRProtocol[source]¶
Bases:
LineProtocolCarriage Return protocol. For legacy systems no longer officially supported by python, such as Mac OS 9, such that this will never be chosen as the default.
- class asyncutils.networking.LFProtocol[source]¶
Bases:
LineProtocolLine Feed protocol for Unix-like systems.
- class asyncutils.networking.LineProtocol[source]¶
Bases:
asyncio.Protocol,asyncutils._internal.helpers.LoopMixinBaseAn implementation ofProtocolproviding line-based buffering and writing. Not thread-safe.The idea was originally introduced in PEP 3153, but did not see eventual adaptation in the standard library.This particular implementation is designed to be used withSocketTransport, though other transports can enforce it too.- connection_made(transport: asyncio.WriteTransport) None[source]¶
Unlike the base class, this method does not take read-only transports.
- data_received(data: bytes, bufsize: int = ...) None[source]¶
Called when some data is received, with
databeing a non-empty bytes object containing it.
- async drain() None[source]¶
Wait until the transport is ready for more data to be written (i.e. the write buffer is flushed).
- eof_received() None[source]¶
Called when the other end signals it won’t send any more data, for example by calling
Transport.write_eof(), which closes the transport.
- async read_line() str | None[source]¶
Read a line from the internal buffer and return it, or
Noneif EOF is reached.
- write_line(line: str) None[source]¶
Write the string
lineto the transport, followed by the newline sequence.
- async write_line_with_backpressure(line: str) None[source]¶
Write the string
lineto the transport, followed by the newline sequence, after draining it.
- write_literal(data: bytes) None[source]¶
Write the given bytes into the transport without appending a newline.
- async write_literal_with_backpressure(data: bytes) None[source]¶
Write the given bytes into the transport without appending a newline, after draining it.
- property connected_transport: asyncio.WriteTransport¶
The transport associated with this protocol; raises
ConnectionErrorif not connected.
- property transport: asyncio.WriteTransport | None¶
The transport associated with this protocol, or None if not connected.
- class asyncutils.networking.SocketTransport(sock: socket.socket | None = ...)[source]¶
Bases:
asyncio.TransportA thread-unsafe transport that connects
LineProtocol’s to sockets.Initialize the transport, connecting the socket immediately if given.
- abort() None[source]¶
Close the transport immediately, without waiting for pending operations to complete.
- close(e: Exception | None = ...) None[source]¶
Close the transport and flush the outgoing data buffer. No more data will be received. After all buffered data is flushed, the protocol’s
connection_lost()method will be called withNoneas argument. The transport is not to be used once closed.
- connect_sock(sock: socket.socket = ...) None[source]¶
Connect the transport to the given socket.
- disconnect_sock() socket.socket | None[source]¶
Disconnect the transport from its socket and return it, or
Noneif not connected.
- get_protocol() LineProtocol[source]¶
Return the current protocol. For this class, it is expected to always be a
LineProtocolor one of its subclasses.
- get_write_buffer_limits() tuple[int, int][source]¶
Get the high and low watermarks for write flow control. Return a tuple
(low, high), wherelowandhighare positive number of bytes.
- get_write_buffer_size() int[source]¶
Return the current size of the output buffer used by the transport.
- static make_protocol() LineProtocol[source]¶
Return a new protocol compatible with this transport. The default implementation returns a
LineProtocol, so if overriding this in subclasses, remember to add# type: ignore[override]comments as appropriate.
- set_write_buffer_limits(high: int | None = ..., low: int | None = ...) None[source]¶
Set the high and low watermarks for write flow control in bytes.
- sock_context(sock: socket.socket) asyncutils._internal.types.DualContextManager[None][source]¶
Return a context manager, both sync and async, that connects the transport to the given socket on entry and disconnects it on exit.
- write(data: collections.abc.Iterable[int]) None[source]¶
Write the given iterable over integers in
range(256)interpreted as characters into the transport.
- write_eof() None[source]¶
Close the write end of the transport after flushing all buffered data. Data may still be received.
- property loop: asyncio.AbstractEventLoop¶
Override this if the type of the protocols this transport accepts is altered in subclasses.