plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:

- support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace
- maintains one identity across both versions of OMEMO
- migrates data from the old plugin
- includes more features for protocol stability
- uses SCE for modern OMEMO
- fully type-checked, linted and format-checked
- added type hints to various pieces of backend code used by the plugin
- added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy)
- core (xmpp): enabled `send` trigger and made it an asyncPoint

fix 375
This commit is contained in:
Syndace 2022-08-23 21:06:24 +02:00
commit 75ae8160ae

View file

@ -21,6 +21,14 @@
# XXX: this module use standard logging module when possible, but as SàT can work in different cases where logging is not the best choice (twisted, pyjamas, etc), it is necessary to have a dedicated module. Additional feature like environment variables and colors are also managed.
# TODO: change formatting from "%s" style to "{}" when moved to Python 3
from typing import TYPE_CHECKING, Any, Optional
from typing_extensions import TypedDict
if TYPE_CHECKING:
from logging import _ExcInfoType
else:
_ExcInfoType = Any
from sat.core.constants import Const as C
from sat.tools.common.ansi import ANSI as A
from sat.core import exceptions
@ -37,6 +45,10 @@ class Filtered(Exception):
pass
class KWArgs(TypedDict):
exc_info: _ExcInfoType
class Logger:
"""High level logging class"""
fmt = None # format option as given by user (e.g. SAT_LOG_LOGGER)
@ -60,7 +72,7 @@ class Logger:
tb = traceback.format_exc()
return message + "\n==== traceback ====\n" + tb
def out(self, message, level=None, **kwargs):
def out(self, message: object, level: Optional[str] = None, **kwargs: KWArgs) -> None:
"""Actually log the message
@param message: formatted message
@ -69,7 +81,7 @@ class Logger:
message = self.addTraceback(message)
print(message)
def log(self, level, message, **kwargs):
def log(self, level: str, message: object, **kwargs: KWArgs) -> None:
"""Print message
@param level: one of C.LOG_LEVELS
@ -84,7 +96,7 @@ class Logger:
except Filtered:
pass
def format(self, level, message):
def format(self, level: str, message: object) -> object:
"""Format message according to Logger.fmt
@param level: one of C.LOG_LEVELS
@ -117,19 +129,19 @@ class Logger:
else:
raise e
def debug(self, msg, **kwargs):
def debug(self, msg: object, **kwargs: KWArgs) -> None:
self.log(C.LOG_LVL_DEBUG, msg, **kwargs)
def info(self, msg, **kwargs):
def info(self, msg: object, **kwargs: KWArgs) -> None:
self.log(C.LOG_LVL_INFO, msg, **kwargs)
def warning(self, msg, **kwargs):
def warning(self, msg: object, **kwargs: KWArgs) -> None:
self.log(C.LOG_LVL_WARNING, msg, **kwargs)
def error(self, msg, **kwargs):
def error(self, msg: object, **kwargs: KWArgs) -> None:
self.log(C.LOG_LVL_ERROR, msg, **kwargs)
def critical(self, msg, **kwargs):
def critical(self, msg: object, **kwargs: KWArgs) -> None:
self.log(C.LOG_LVL_CRITICAL, msg, **kwargs)