Created
October 15, 2021 21:47
-
-
Save acdimalev/912b7a839234168173c483a584798df0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import field | |
@dataclass | |
class InMessage: | |
line: str | |
prefix: str | |
command: str | |
params: list[str] | |
@dataclass | |
class Connection: | |
reference: int | |
socket: int = None | |
in_buffer: str = "" | |
in_messages: list[InMessage] = field(default_factory=list) | |
next_connection_reference = 0 | |
connections = {} | |
def live_connections(): | |
return connections.values() | |
def connection_by_reference(reference): | |
return connections.get(reference) | |
def next_free_connection(): | |
reference = next_connection_reference | |
connection = Connection(reference) | |
connections[reference] = connection | |
next_connection_reference = 1 + reference | |
return connection | |
def drop_connections(references): | |
for reference in references: | |
if reference in connection: | |
del connection[reference] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment