Generic Servers
Low-level asynchronous servers module.
Stream Servers
Low-level asynchronous stream servers module.
- class easynetwork.lowlevel.api_async.servers.stream.AsyncStreamServer
Bases:
AsyncBaseTransport,Generic[_T_Request,_T_Response]Stream listener interface.
- __init__(listener: AsyncListener[AsyncStreamTransport], protocol: StreamProtocol[_T_Response, _T_Request] | BufferedStreamProtocol[_T_Response, _T_Request, Any], max_recv_size: int) None
- Parameters:
listener (AsyncListener[AsyncStreamTransport]) – the transport implementation to wrap.
protocol (StreamProtocol[_T_Response, _T_Request] | BufferedStreamProtocol[_T_Response, _T_Request, Any]) – The protocol object to use.
max_recv_size (int) – Read buffer size.
- backend() AsyncBackend
- Returns:
The backend implementation linked to this transport.
- Return type:
- async serve(client_connected_cb: Callable[[ConnectedStreamClient[_T_Response]], AsyncGenerator[float | RecvParams | None, _T_Request]], task_group: TaskGroup | None = None, *, disconnect_error_filter: Callable[[Exception], bool] | None = None, ancillary_bufsize: int | None = None) NoReturn
Accept incoming connections as they come in and start tasks to handle them.
Changed in version 1.2: Added ancillary_bufsize parameter.
Changed in version 1.2: The async generator returned by client_connected_cb may yield a
RecvParamsobject.Deprecated since version 1.2: If the async generator returned by client_connected_cb yields a number, a
DeprecationWarningwill be emitted. UseRecvParamsinstead.- Parameters:
client_connected_cb (Callable[[ConnectedStreamClient[_T_Response]], AsyncGenerator[float | RecvParams | None, _T_Request]]) – 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.
disconnect_error_filter (Callable[[Exception], bool] | None) – a callable that returns
Trueif the exception is the result of a pipe disconnect.ancillary_bufsize (int | None) – the maximum buffer size for ancillary data. If
None, usingRecvAncillaryDataParamswill raiseUnsupportedOperation.
- 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.servers.stream.ConnectedStreamClient
Bases:
AsyncBaseTransport,Generic[_T_Response]Write-end of the connected client.
- async aclose() None
Closes the endpoint.
Warning
aclose()performs a graceful close, waiting for the transport to close.If
aclose()is cancelled, the transport is closed abruptly.
- async send_packet(packet: _T_Response) None
Sends packet to the remote endpoint.
Warning
In the case of a cancellation, it is impossible to know if all the packet data has been sent. This would leave the connection in an inconsistent state.
- Parameters:
packet (_T_Response) – the Python object to send.
- async send_packet_with_ancillary(packet: _T_Response, ancillary_data: Any) None
Sends packet to the remote endpoint with ancillary data.
Added in version 1.2.
Warning
In the case of a cancellation, it is impossible to know if all the packet data has been sent. This would leave the connection in an inconsistent state.
- Parameters:
packet (_T_Response) – the Python object to send.
ancillary_data (Any) – The ancillary data to send along with the message.
- Raises:
OSError – Data too big to be sent at once.
UnsupportedOperation – This transport does not have ancillary data support.
- 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.
Datagram Servers
Low-level asynchronous datagram servers module.
- class easynetwork.lowlevel.api_async.servers.datagram.AsyncDatagramServer
Bases:
AsyncBaseTransport,Generic[_T_Request,_T_Response,_T_Address]Datagram packet listener interface.
- __init__(listener: AsyncDatagramListener[_T_Address], protocol: DatagramProtocol[_T_Response, _T_Request]) None
- Parameters:
listener (AsyncDatagramListener[_T_Address]) – the transport implementation to wrap.
protocol (DatagramProtocol[_T_Response, _T_Request]) – The protocol object to use.
- backend() AsyncBackend
- Returns:
The backend implementation linked to this transport.
- Return type:
- async send_packet_to(packet: _T_Response, address: _T_Address) None
Sends packet to the remote endpoint address.
Warning
In the case of a cancellation, it is impossible to know if all the packet data has been sent.
- Parameters:
packet (_T_Response) – the Python object to send.
address (_T_Address) – the remote endpoint address.
- async send_packet_with_ancillary_to(packet: _T_Response, ancillary_data: Any, address: _T_Address) None
Sends packet to the remote endpoint address with ancillary data.
Added in version 1.2.
Warning
In the case of a cancellation, it is impossible to know if all the packet data has been sent.
- Parameters:
packet (_T_Response) – the Python object to send.
ancillary_data (Any) – The ancillary data to send along with the message.
address (_T_Address) – the remote endpoint address.
- async serve(datagram_received_cb: Callable[[DatagramClientContext[_T_Response, _T_Address]], AsyncGenerator[float | RecvParams | None, _T_Request]], task_group: TaskGroup | None = None) NoReturn
Receive incoming datagrams as they come in and start tasks to handle them.
Changed in version 1.2: The async generator returned by datagram_received_cb may yield a
RecvParamsobject.Deprecated since version 1.2: If the async generator returned by datagram_received_cb yields a number, a
DeprecationWarningwill be emitted. UseRecvParamsinstead.Important
There will always be only one active generator per client. All the pending datagrams received while the generator is running are queued.
This behavior is designed to act like a stream request handler.
Note
If the generator returns before the first
yieldstatement, the received datagram is discarded.This is useful when a client that you do not expect to see sends something; the datagrams are parsed only when the generator hits a
yieldstatement.- Parameters:
datagram_received_cb (Callable[[DatagramClientContext[_T_Response, _T_Address]], AsyncGenerator[float | RecvParams | None, _T_Request]]) – a callable that will be used to handle each received datagram.
task_group (TaskGroup | None) – the task group that will be used to start tasks for handling each received datagram.
- Return type:
- async serve_with_ancillary(datagram_received_cb: Callable[[DatagramClientContext[_T_Response, _T_Address]], AsyncGenerator[float | RecvParams | None, _T_Request]], ancillary_bufsize: int, ancillary_data_unused: Callable[[Any, _T_Address], object] | None = None, task_group: TaskGroup | None = None) NoReturn
Receive incoming datagrams with ancillary data as they come in and start tasks to handle them.
See
serve()methods for more information.Added in version 1.2.
Deprecated since version 1.2: If the async generator returned by datagram_received_cb yields a number, a
DeprecationWarningwill be emitted. UseRecvParamsinstead.- Parameters:
datagram_received_cb (Callable[[DatagramClientContext[_T_Response, _T_Address]], AsyncGenerator[float | RecvParams | None, _T_Request]]) – a callable that will be used to handle each received datagram.
ancillary_bufsize (int) – the maximum buffer size for ancillary data.
ancillary_data_unused (Callable[[Any, _T_Address], object] | None) – Action to perform if the request handler did not claim the received ancillary data.
task_group (TaskGroup | None) – the task group that will be used to start tasks for handling each received datagram.
- 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.servers.datagram.DatagramClientContext
Bases:
Generic[_T_Response,_T_Address]Contains information about the remote endpoint which sends a datagram.
- address: _T_Address
The client address.
- server: AsyncDatagramServer[Any, _T_Response, _T_Address]
The server which receives the datagram.
- backend() AsyncBackend
- Returns:
The backend implementation linked to this transport.
- Return type:
- easynetwork.lowlevel.api_async.servers.datagram._T_Address
Type:
TypeVarInvariant
TypeVarbound tocollections.abc.Hashable.