IrcMessage, PORT_SSL)
ClientsDb = dict[str, 'Client']
+ClientDbType = int | str | list[str]
_NAMES_DESIRED_SERVER_CAPS = ('server-time', 'account-tag', 'sasl')
# NB: in below numerics accounting, tuples define inclusive ranges
'Optimized for dealing with variable confirmation of values.'
def __init__(self) -> None:
- self._dict: dict[str, int | str | list[str]] = {}
+ self._dict: dict[str, ClientDbType] = {}
self._confirmeds: list[str] = []
def __getattr__(self, key: str) -> Any:
return self._dict[key]
return None
- def set(self,
- key: str,
- value: Optional[int | str | list[str]],
- confirm=False
+ def set(self, key: str, value: Optional[ClientDbType], confirm=False
) -> tuple[bool, bool]:
'Ensures setting, returns if changed value or confirmation.'
old_value, was_confirmed = self.get_force(key)
else:
raise CrashingException('called on non-list entry')
- def get_force(self, key: str) -> tuple[Optional[int | str | list[str]],
- bool]:
+ def get_force(self, key: str) -> tuple[Optional[ClientDbType], bool]:
'Get even if only stored unconfirmed, tell if confirmed..'
return (self._dict.get(key, None), key in self._confirmeds)
self._log(to_log, scope=log_target)
self._log(msg.raw, scope=LogScope.RAW, out=True)
- def _update_db(self,
- key: str,
- value: Optional[int | str | list[str]],
- confirm: bool
+ def _update_db(self, key: str, value: Optional[ClientDbType], confirm: bool
) -> tuple[bool, bool]:
'Wrap ._db.set into something accessible to subclass extension.'
return self._db.set(key, value, confirm)
from ircplom.tui_base import (BaseTui, PromptWidget, TuiEvent, Window,
CMD_SHORTCUTS)
from ircplom.irc_conn import IrcMessage
-from ircplom.client import (IrcConnSetup, Client, ClientDb, ClientQueueMixin,
- LogScope, NewClientEvent)
+from ircplom.client import (IrcConnSetup, Client, ClientDb, ClientDbType,
+ ClientQueueMixin, LogScope, NewClientEvent)
CMD_SHORTCUTS['disconnect'] = 'window.disconnect'
CMD_SHORTCUTS['join'] = 'window.join'
def update(self,
key: str,
- value: Optional[str],
+ value: Optional[ClientDbType],
confirmed: bool,
scope: LogScope
) -> bool:
with open(f'{self.client_id}.log', 'a', encoding='utf8') as f:
f.write(('>' if kwargs['out'] else '<') + f' {msg}\n')
- def _update_db(self,
- key: str,
- value: Optional[int | str | list[str]],
- confirm: bool
+ def _update_db(self, key: str, value: Optional[ClientDbType], confirm: bool
) -> tuple[bool, bool]:
value_changed, conf_changed = super()._update_db(key, value, confirm)
if value is None and not value_changed: # local ._db may have fallback