Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src_py/hat/syslog/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,28 @@ def __init__(self,
reconnect_delay: float = 5):
super().__init__()

# Choose the matching CommType member from a string
if isinstance(comm_type, str):
needle = comm_type
haystack = frozenset(common.CommType.__members__)
vary = lambda x: {
x, x.upper(),
x.casefold(), x.casefold().upper(),
x.lower(), x.lower().upper(),
}
found = vary(needle).intersection(haystack)
if found:
member = tuple(found)[0]
comm_type = common.CommType[member]
else:
raise ValueError(f'Specify a valid comm_type from this list: {list(haystack)}')
if not isinstance(comm_type, common.CommType):
raise ValueError('Invalid comm_type argument')

self.__state = _ThreadState(
host=host,
port=port,
comm_type=(common.CommType[comm_type]
if not isinstance(comm_type, common.CommType)
else comm_type),
comm_type=comm_type,
queue=collections.deque(),
queue_size=queue_size,
reconnect_delay=reconnect_delay,
Expand Down Expand Up @@ -107,7 +123,7 @@ class _ThreadState(typing.NamedTuple):
"""Hostname"""
port: int
"""TCP port"""
comm_type: common.CommType | str
comm_type: common.CommType
"""Communication type"""
queue: collections.deque
"""Message queue"""
Expand Down