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:
is_closing() bool

Checks if the server is closed or in the process of being closed.

Returns:

True if the server is closed.

Return type:

bool

async aclose() None

Closes the server.

backend() AsyncBackend
Returns:

The backend implementation linked to this transport.

Return type:

AsyncBackend

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 RecvParams object.

Deprecated since version 1.2: If the async generator returned by client_connected_cb yields a number, a DeprecationWarning will be emitted. Use RecvParams instead.

Parameters:
Return type:

NoReturn

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 TypedAttributeLookupError if 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.

is_closing() bool

Checks if the endpoint is closed or in the process of being closed.

Returns:

True if the endpoint is closed.

Return type:

bool

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:
backend() AsyncBackend
Returns:

The backend implementation linked to this transport.

Return type:

AsyncBackend

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 TypedAttributeLookupError if 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:
is_closing() bool

Checks if the server is closed or in the process of being closed.

Returns:

True if the server is closed.

Return type:

bool

async aclose() None

Closes the server.

backend() AsyncBackend
Returns:

The backend implementation linked to this transport.

Return type:

AsyncBackend

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 RecvParams object.

Deprecated since version 1.2: If the async generator returned by datagram_received_cb yields a number, a DeprecationWarning will be emitted. Use RecvParams instead.

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 yield statement, 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 yield statement.

Parameters:
Return type:

NoReturn

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 DeprecationWarning will be emitted. Use RecvParams instead.

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:

NoReturn

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 TypedAttributeLookupError if 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:

AsyncBackend

easynetwork.lowlevel.api_async.servers.datagram._T_Address

Type:    TypeVar

Invariant TypeVar bound to collections.abc.Hashable.