titanfe.connection module

Encapsulate asyncio connections by wrapping them into a Connection

class titanfe.connection.Connection(reader, writer, log=None, encoding='UJO')[source]

Bases: object

Wrap an asyncio StreamReader/Writer combination into a connection object.

Parameters:
  • reader (asyncio.StreamReader) – the stream reader

  • writer (asyncio.StreamWriter) – the stream writer

  • log (logging.logger) – a parent logger

  • encoding – “PICKLE” or “UJO”

async close()[source]

close the connection by closing it’s reader and writer

async classmethod open(address: titanfe.connection.NetworkAddress, log: Optional[logging.Logger] = None)titanfe.connection.Connection[source]

open an asyncio connection to the given address (host, port)

async receive()[source]

wait until a message comes through and return it’s content after decoding

Returns:

a message or None if the connection was closed remotely

Return type:

Message

async send(message)[source]

encode and send the content as a message

class titanfe.connection.NetworkAddress(host, port)

Bases: tuple

property host

Alias for field number 0

property port

Alias for field number 1

titanfe.connection.decode_ujo_message(ujo_bytes)[source]

Decode ujo bytes into a corresponding python object, but keep an existing “Payload” as Ujo.