aiospamc.connections package

Submodules

aiospamc.connections.tcp_connection module

TCP socket connection and manager.

class aiospamc.connections.tcp_connection.TcpConnection(host, port, ssl, loop=None)

Bases: aiospamc.connections.Connection

Manages a TCP connection.

host

str – Hostname or IP address of server.

port

str – Port number

ssl

bool – Whether to use SSL/TLS.

loop

asyncio.AbstratEventLoop – The asyncio event loop.

__init__(host, port, ssl, loop=None)

Constructor for TcpConnection.

host

str – Hostname or IP address of server.

port

str – Port number

ssl

bool or optional – SSL/TLS enabled.

connection_string

String representation of the connection.

Returns:Hostname and port.
Return type:str
coroutine open()

Opens a connection.

Returns:
  • asyncio.StreamReader
  • asyncio.StreamWriter
Raises:aiospamc.exceptions.AIOSpamcConnectionFailed
class aiospamc.connections.tcp_connection.TcpConnectionManager(host, port, ssl=False, loop=None)

Bases: aiospamc.connections.ConnectionManager

Creates new connections based on host and port provided.

host

str – Hostname or IP address of server.

port

str – Port number.

ssl

bool – Whether to use SSL/TLS.

__init__(host, port, ssl=False, loop=None)

Constructor for TcpConnectionManager.

Parameters:
  • host (str) – Hostname or IP address of server.
  • port (str) – Port number
  • ssl (bool or optional) – SSL/TLS enabled.
  • loop (asyncio.AbstractEventLoop) – The asyncio event loop.
new_connection()

Creates a new TCP connection.

Raises:aiospamc.exceptions.AIOSpamcConnectionFailed

aiospamc.connections.unix_connection module

Unix domain socket connection and manager.

class aiospamc.connections.unix_connection.UnixConnection(path, loop=None)

Bases: aiospamc.connections.Connection

Manages a Unix domain socket connection.

path

str – Path of the socket.

loop

asyncio.AbstractEventLoop – The asyncio event loop.

__init__(path, loop=None)

Constructor for UnixConnection.

Parameters:
  • path (str) – Path of the socket.
  • loop (asyncio.AbstractEventLoop) – The asyncio event loop.
connection_string

String representation of the connection.

Returns:Path to the Unix domain socket.
Return type:str
coroutine open()

Opens a connection.

Returns:
  • asyncio.StreamReader
  • asyncio.StreamWriter
Raises:aiospamc.exceptions.AIOSpamcConnectionFailed
class aiospamc.connections.unix_connection.UnixConnectionManager(path, loop=None)

Bases: aiospamc.connections.ConnectionManager

Creates new connections based on Unix domain socket path provided.

path

str – Path of the socket.

__init__(path, loop=None)

Constructor for UnixConnectionManager.

Parameters:
  • path (str) – Path of the socket.
  • loop (asyncio.AbstractEventLoop) – The asyncio event loop.
new_connection()

Creates a new Unix domain socket connection.

Raises:AIOSpamcConnectionFailed

Module contents

Connection and ConnectionManager base classes.

class aiospamc.connections.Connection(loop=None)

Bases: object

Base class for connection objects.

connected

bool – Status on if the connection is established.

loop

asyncio.AbstratEventLoop – The asyncio event loop.

logger

logging.Logger – Logging instance. Logs to ‘aiospamc.connections’

__init__(loop=None)

Connection constructor.

Parameters:loop (asyncio.AbstractEventLoop) – The asyncio event loop.
close()

Closes the connection.

connection_string

String representation of the connection.

Returns:String of the connection address.
Return type:str
coroutine open()

Connect to a service.

Returns:
  • asyncio.StreamReader – Instance of stream reader.
  • asyncio.StreamWriter – Instance of stream writer.
Raises:aiospamc.exceptions.AIOSpamcConnectionFailed – If connection failed for some reason.
coroutine receive()

Receives data from the connection.

Returns:Data received.
Return type:bytes
coroutine send(data)

Sends data through the connection.

Parameters:data (bytes) – Data to send.
class aiospamc.connections.ConnectionManager(loop=None)

Bases: object

Stores connection parameters and creates connections.

loop

asyncio.AbstratEventLoop – The asyncio event loop.

new_connection()

Creates a connection object.

Returns:Instance of a Connection object.
Return type:Connection