use ProtocolIfc class

This commit is contained in:
Stefan Allius
2024-10-05 21:11:42 +02:00
parent c7d0a91371
commit 9852f44dfa
7 changed files with 108 additions and 154 deletions

View File

@@ -1,14 +1,6 @@
from abc import ABCMeta
class IterRegistry(type):
def __iter__(cls):
for ref in cls._registry:
obj = ref()
if obj is not None:
yield obj
class AbstractIterMeta(ABCMeta):
def __iter__(cls):
for ref in cls._registry:

View File

@@ -5,11 +5,11 @@ from enum import Enum
if __name__ == "app.src.messages":
from app.src.iter_registry import IterRegistry
from app.src.protocol_ifc import ProtocolIfc
from app.src.infos import Infos, Register
from app.src.modbus import Modbus
else: # pragma: no cover
from iter_registry import IterRegistry
from protocol_ifc import ProtocolIfc
from infos import Infos, Register
from modbus import Modbus
@@ -82,8 +82,7 @@ class State(Enum):
'''connection closed'''
class Message(metaclass=IterRegistry):
_registry = []
class Message(ProtocolIfc):
MAX_START_TIME = 400
'''maximum time without a received msg in sec'''
MAX_INV_IDLE_TIME = 120

View File

@@ -1,5 +1,4 @@
from abc import abstractmethod
import weakref
if __name__ == "app.src.protocol_ifc":
from app.src.iter_registry import AbstractIterMeta
@@ -10,34 +9,13 @@ else: # pragma: no cover
class ProtocolIfc(metaclass=AbstractIterMeta):
@abstractmethod
def __init__(self, addr, ifc: "AsyncIfc", server_side: bool,
client_mode: bool = False, id_str=b''):
pass # pragma: no cover
@abstractmethod
def close(self):
pass # pragma: no cover
def __enter__(self):
return self
def __exit__(self, exc_type, exc, tb):
self.close()
class Test():
def test_method(self):
return self
class ProtocolIfcImpl(ProtocolIfc, Test):
_registry = []
@abstractmethod
def __init__(self, addr, ifc: "AsyncIfc", server_side: bool,
client_mode: bool = False, id_str=b''):
self._registry.append(weakref.ref(self))
pass # pragma: no cover
@abstractmethod
def close(self):
pass # pragma: no cover