Data Transport Adapters
Low-level asynchronous transports module.
Abstract Base Classes
Low-level asynchronous transports interfaces module.
- class easynetwork.lowlevel.api_async.transports.abc.AsyncBaseTransport
Bases:
TypedAttributeProviderBase class for an asynchronous data transport.
- async __aexit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) None
Calls
aclose().
- abstract async aclose() None
Closes the transport.
Warning
aclose()performs a graceful close, waiting for the transport to close.If
aclose()is cancelled, the transport is closed abruptly.
- abstract backend() AsyncBackend
- Returns:
The backend implementation linked to this transport.
- Return type:
- class easynetwork.lowlevel.api_async.transports.abc.AsyncDatagramListener
Bases:
AsyncBaseTransport,Generic[_T_Address]An interface specialized for objects that let you handle incoming datagrams from anywhere.
- abstract async serve(handler: Callable[[bytes, _T_Address], Coroutine[Any, Any, None]], task_group: TaskGroup | None = None) NoReturn
Receive incoming datagrams as they come in and start tasks to handle them.
Important
The implementation must ensure that datagrams are processed in the order in which they are received.
- abstract async send_to(data: bytes | bytearray | memoryview, address: _T_Address) None
Send the data bytes to the remote peer address.
Important
This method should be safe to call from multiple tasks.
- Parameters:
data (bytes | bytearray | memoryview) – the bytes to send.
address (_T_Address) – the remote peer.
- class easynetwork.lowlevel.api_async.transports.abc.AsyncDatagramReadTransport
Bases:
AsyncBaseTransportAn asynchronous reader transport of unreliable packets of data.
- class easynetwork.lowlevel.api_async.transports.abc.AsyncDatagramTransport
Bases:
AsyncDatagramWriteTransport,AsyncDatagramReadTransportAn asynchronous transport of unreliable packets of data.
- class easynetwork.lowlevel.api_async.transports.abc.AsyncDatagramWriteTransport
Bases:
AsyncBaseTransportAn asynchronous writer transport of unreliable packets of data.
- abstract async send(data: bytes | bytearray | memoryview) None
Send the data bytes to the remote peer.
- Parameters:
data (bytes | bytearray | memoryview) – the bytes to send.
- class easynetwork.lowlevel.api_async.transports.abc.AsyncListener
Bases:
AsyncBaseTransport,Generic[_T_co]An interface for objects that let you accept incoming connections.
- abstract async serve(handler: Callable[[_T_co], Coroutine[Any, Any, None]], task_group: TaskGroup | None = None) NoReturn
Accept incoming connections as they come in and start tasks to handle them.
- Parameters:
handler (Callable[[_T_co], Coroutine[Any, Any, None]]) – a callable that will be used to handle each accepted connection.
task_group (TaskGroup | None) – the task group that will be used to start tasks for handling each accepted connection.
- Return type:
NoReturn
- class easynetwork.lowlevel.api_async.transports.abc.AsyncStreamReadTransport
Bases:
AsyncBaseTransportAn asynchronous continuous stream data reader transport.
- async recv(bufsize: int) bytes
Read and return up to bufsize bytes.
- Parameters:
bufsize (int) – the maximum buffer size.
- Raises:
ValueError – Negative bufsize.
- Returns:
some
bytes.If bufsize is greater than zero and an empty byte buffer is returned, this indicates an EOF.
- Return type:
- abstract async recv_into(buffer: bytearray | memoryview | collections.abc.Buffer) int
Read into the given buffer.
- Parameters:
buffer (bytearray | memoryview | collections.abc.Buffer) – where to write the received bytes.
- Returns:
the number of bytes written.
Returning
0for a non-zero buffer indicates an EOF.- Return type:
- class easynetwork.lowlevel.api_async.transports.abc.AsyncStreamTransport
Bases:
AsyncStreamWriteTransport,AsyncStreamReadTransportAn asynchronous continuous stream data transport.
- class easynetwork.lowlevel.api_async.transports.abc.AsyncStreamWriteTransport
Bases:
AsyncBaseTransportAn asynchronous continuous stream data writer transport.
- abstract async send_all(data: bytes | bytearray | memoryview) None
Send the data bytes to the remote peer.
- Parameters:
data (bytes | bytearray | memoryview) – the bytes to send.
- async send_all_from_iterable(iterable_of_data: Iterable[bytes | bytearray | memoryview]) None
An efficient way to send a bunch of data via the transport.
Like
send_all(), this method continues to send data from bytes until either all data has been sent or an error occurs.Noneis returned on success. On error, an exception is raised, and there is no way to determine how much data, if any, was successfully sent.- Parameters:
iterable_of_data (Iterable[bytes | bytearray | memoryview]) – An iterable yielding the bytes to send.
SSL/TLS Support
Low-level asynchronous SSL transports module.
To use this module, the standard ssl module must be available.
- class easynetwork.lowlevel.api_async.transports.tls.AsyncTLSListener
Bases:
AsyncListener[AsyncTLSStreamTransport]Listener with SSL/TLS wrapper for a continuous stream transport.
- async aclose() None
Closes the transport.
Warning
aclose()performs a graceful close, waiting for the transport to close.If
aclose()is cancelled, the transport is closed abruptly.
- async serve(handler: Callable[[AsyncTLSStreamTransport], Coroutine[Any, Any, None]], task_group: TaskGroup | None = None) NoReturn
Accept incoming connections as they come in and start tasks to handle them.
- backend() AsyncBackend
- Returns:
The backend implementation linked to this transport.
- Return type:
- property extra_attributes: Mapping[Any, Callable[[], Any]]
A mapping of the extra attributes to callables that return the corresponding values.
If the provider wraps another provider, the attributes from that wrapper should also be included in the returned mapping (but the wrapper may override the callables from the wrapped instance).
The callables should raise
TypedAttributeLookupErrorif it is not possible to get the value.
- class easynetwork.lowlevel.api_async.transports.tls.AsyncTLSStreamTransport
Bases:
AsyncStreamTransportSSL/TLS wrapper for a continuous stream transport.
- async classmethod wrap(transport: AsyncStreamTransport, ssl_context: SSLContext, *, handshake_timeout: float | None = None, shutdown_timeout: float | None = None, server_side: bool | None = None, server_hostname: str | None = None, standard_compatible: bool = True, session: SSLSession | None = None) Self
- Parameters:
transport (AsyncStreamTransport) – The transport to wrap.
ssl_context (SSLContext) – a
ssl.SSLContextobject to use to create the transport.handshake_timeout (float | None) – The time in seconds to wait for the TLS handshake to complete before aborting the connection.
60.0seconds ifNone(default).shutdown_timeout (float | None) – The time in seconds to wait for the SSL shutdown to complete before aborting the connection.
30.0seconds ifNone(default).server_side (bool | None) – Indicates whether we are a client or a server for the handshake part. If it is set to
None, it is deduced according to server_hostname.server_hostname (str | None) – sets or overrides the hostname that the target server’s certificate will be matched against. If server_side is
True, you must pass a value for server_hostname.standard_compatible (bool) – If
False, skip the closing handshake when closing the connection, and don’t raise an exception if the peer does the same.session (SSLSession | None) – If an SSL session already exits, use it insead.
- Return type:
Self
- async aclose() None
Closes the transport.
Warning
aclose()performs a graceful close, waiting for the transport to close.If
aclose()is cancelled, the transport is closed abruptly.
- backend() AsyncBackend
- Returns:
The backend implementation linked to this transport.
- Return type:
- async recv(bufsize: int) bytes
Read and return up to bufsize bytes.
- Parameters:
bufsize (int) – the maximum buffer size.
- Raises:
ValueError – Negative bufsize.
- Returns:
some
bytes.If bufsize is greater than zero and an empty byte buffer is returned, this indicates an EOF.
- Return type:
- async recv_into(buffer: bytearray | memoryview | collections.abc.Buffer) int
Read into the given buffer.
- Parameters:
buffer (bytearray | memoryview | collections.abc.Buffer) – where to write the received bytes.
- Returns:
the number of bytes written.
Returning
0for a non-zero buffer indicates an EOF.- Return type:
- async send_all(data: bytes | bytearray | memoryview) None
Send the data bytes to the remote peer.
- Parameters:
data (bytes | bytearray | memoryview) – the bytes to send.
- async send_all_from_iterable(iterable_of_data: Iterable[bytes | bytearray | memoryview]) None
An efficient way to send a bunch of data via the transport.
Like
send_all(), this method continues to send data from bytes until either all data has been sent or an error occurs.Noneis returned on success. On error, an exception is raised, and there is no way to determine how much data, if any, was successfully sent.- Parameters:
iterable_of_data (Iterable[bytes | bytearray | memoryview]) – An iterable yielding the bytes to send.
- async send_eof() None
Closes the write end of the stream after the buffered write data is flushed.
- Raises:
UnsupportedOperation – SSL/TLS API does not support sending EOF (for now).
- property extra_attributes: Mapping[Any, Callable[[], Any]]
A mapping of the extra attributes to callables that return the corresponding values.
If the provider wraps another provider, the attributes from that wrapper should also be included in the returned mapping (but the wrapper may override the callables from the wrapped instance).
The callables should raise
TypedAttributeLookupErrorif it is not possible to get the value.
Miscellaneous
Low-level asynchronous transports tools module.
- async easynetwork.lowlevel.api_async.transports.utils.aclose_forcefully(transport: AsyncBaseTransport) None
Close an async resource or async generator immediately, without blocking to do any graceful cleanup.
- Parameters:
transport (AsyncBaseTransport) – the transport to close.