pyfingerd.server – Server definition#

class pyfingerd.server.FingerBaseServer(binds: str = 'localhost:79', /, *, debug: bool = False)#

Bases: ABC

Base finger server class.

Parameters:
  • binds – The hosts and ports on which the server should listen to and answer finger requests.

  • debug – Whether the tracebacks should be transmitted back to the client or not.

abstract async handle_malformed_request(*, exc: MalformedRequestError, src: IPv4Address | IPv6Address) str#

Handle an invalid request.

Parameters:
  • exc – Raised exception describing the request parsing error.

  • src – Source from which the request has been emitted.

Returns:

ASCII-compatible result.

abstract async handle_request(request: FingerRequest, /, *, src: IPv4Address | IPv6Address) str#

Handle a valid request.

Parameters:
  • request – Decoded request.

  • src – Source from which the request has been emitted.

Returns:

ASCII-compatible result.

prepare_auxiliary_coroutines() Iterable[Coroutine]#

Get the general coroutines for the server, excluding binds.

This can be used by the child server to run coroutines aside the server coroutines, e.g. workers to update the state.

By default, this method does not yield any auxiliary coroutine.

Returns:

Coroutine iterator.

async start_async() None#

Start the servers.

start_sync() None#

Start the coroutines to run the server and background tasks.

start() None#

Start all underlying server processes and bind all ports.

stop() None#

Stop all underlying server processes and unbind all ports.

serve_forever() None#

Start all servers and serve in a synchronous fashion.

It starts all servers FingerServer.start(), waits for an interrupt signal, and stops all servers using FingerServer.stop().

shutdown() None#

Shutdown the server, alias to .stop().

class pyfingerd.server.FingerRequest(*, host: str | None = None, query: str | None = None, verbose: bool = False, line: str)#

Bases: BaseModel

A finger query.

ALLOWED_CHARS: _ClassVar[str] = '\t !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'#
host: str | None#

Host of the query, if the client wants the server to transmit it.

query: str | None#

Username query, if provided by the client.

verbose: bool#

Whether the client has provided the ‘/W’ or not.

line: str#

The raw query line provided by the client.

classmethod decode(raw: bytes, /) _FingerRequestType#

Decode a raw finger query.

There are three types of requests recognized by RFC 1288:

  • {C} is a request for a list of all online users.

  • {Q1} is a request for a local user.

  • {Q2} is a request for a distant user (with hostname).

/W means the RUIP (program answering the query) should be more verbose (this token can be ignored).

Parameters:

line – The line to decode.

Returns:

The query.

class pyfingerd.server.FingerServer(binds: str = 'localhost:79', /, *, hostname: str = 'LOCALHOST', interface: FingerInterface | None = None, formatter: FingerFormatter | None = None, debug: bool = False)#

Bases: FingerBaseServer

Finger server making use of an interface and a formatter.

Parameters:
  • binds – The hosts and ports on which the server should listen to and answer finger requests.

  • hostname – The hostname to be included in answers sent to clients.

  • interface – The interface to use for querying users and sessions.

  • formatter – The formatter to use for formatting answers sent to clients.

  • debug – Whether the tracebacks should be transmitted back to the client or not.

property hostname: str#

Get the hostname configured for this server.

property interface: FingerInterface#

Get the interface configured for this server.

property formatter: FingerFormatter#

Get the formatter configured for this server.

prepare_auxiliary_coroutines() Iterable[Coroutine]#

Get the general coroutines for the server, excluding binds.

We override this method to instanciate a cron per special method present in the interface, to allow e.g. updating the interface state regularly.

Returns:

Coroutine iterator.

async handle_malformed_request(*, exc: MalformedRequestError, src: IPv4Address | IPv6Address) str#

Handle an invalid request.

Parameters:
  • exc – Raised exception describing the request parsing error.

  • src – Source from which the request has been emitted.

Returns:

ASCII-compatible result.

async handle_request(request: FingerRequest, /, *, src: IPv4Address | IPv6Address) str#

Handle a valid request.

Parameters:
  • request – Decoded request.

  • src – Source from which the request has been emitted.

Returns:

ASCII-compatible result.