Skip to content

Connectors¤

connectors ¤

Provide the abstract classes for server and content, that need to be implemented for each protocol.

Filters and actions are applied by the Server by looping over each Content object and executing the user-defined functions.

The core of the framework knows only these abstract classes.

© 2022-2023 - Aurélien Pierre

Classes¤

Content ¤

Content(raw_content, server: Server)

Bases: ABC

The Content class manages the decoding and parsing of individual data objects (such as posts, emails, contacts, events, etc.), as well as the data representation to be used in filters. It provides proxy methods to the Server class that can be used to perform server-side actions on the current Content object.

PARAMETER DESCRIPTION
raw_content

data dump from server that should be decoded, parsed and split into properties.

TYPE: any

server

back-reference to the connectors.Server instance to which this Content belongs.

TYPE: Server

Attributes¤
server instance-attribute ¤
server: Server = server

Back-reference to the Server object to which the current Content belongs. In filters, users only access the Content object, so the Content.server reference is their only entry-point to the server. Use that with care and preferably wrap relevant server-side operations as Content methods, with proper arguments mapping.

Server ¤

Server(logfile, secretary: 'secretary.Secretary')

Bases: ABC, ServerType

The Server class manages the connection to a distant host with URL, port, login and password. Then it loads a list of individual objects, like emails or contacts, as Content type.

Attributes¤
nlp class-attribute instance-attribute ¤
nlp = nlp

Reference the natural language processing module for reuse in filters without imports.

utils class-attribute instance-attribute ¤
utils = utils

Reference the utility module for reuse in filters without imports.

secretary instance-attribute ¤
secretary = secretary

Back-reference to the main [secretary.Secretary][] handler

connection_inited instance-attribute ¤
connection_inited: bool = False

Set to True in server implementation when a connection to the server has been inited, that is the DNS/IP has been resolved, server has been contacted and responded, credentials have been sent, and valid login session is active.

std_out instance-attribute ¤
std_out: list = []

Cast status/success messages under the form ["OK", "details/data"]

objects instance-attribute ¤
objects: list[ContentType] = []

The iterable list of connectors.Content object fetched at runtime, upon which filters will be run in sequence.

connection_timestamp instance-attribute ¤
connection_timestamp = 0

Timestamp of the last successful login, useful to keep connections alive.

Todo

implement it

Functions¤
calling_file ¤
calling_file() -> str

Output the name of the calling filter from the stack. Allows to find the path of the folder containing filter, to perform actions like writing logs.

It needs to be called from filter script through object proxy method, pointing to the server method, otherwise the index 2 will be wrong.

init_connection abstractmethod ¤
init_connection(params: dict) -> None

Init a connection with the server and login.

This should set self.connection_inited = True on success.

close_connection abstractmethod ¤
close_connection() -> None

Close the server connection

run_filters abstractmethod ¤
run_filters(
    filter: typing.Callable, action: typing.Callable, runs: int = 1, **kwargs
) -> None

Loop over self.objects to execute filter() and action() on each.