From 319c607f39cb704c153bb190f1cd52799d66482d Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 3 Dec 2024 00:12:38 +0100 Subject: [PATCH] plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic: Pydantic models are used more and more in Libervia, for the bridge API, and also to convert `domish.Element` to internal representation. Type hints have also been added in many places. rel 453 --- .../backend/plugins/plugin_misc_download.py | 14 +- .../plugins/plugin_misc_text_syntaxes.py | 2 +- .../backend/plugins/plugin_misc_uri_finder.py | 4 +- libervia/backend/plugins/plugin_xep_0048.py | 5 +- libervia/backend/plugins/plugin_xep_0060.py | 20 +- libervia/backend/plugins/plugin_xep_0103.py | 88 ++++-- libervia/backend/plugins/plugin_xep_0234.py | 43 +-- libervia/backend/plugins/plugin_xep_0300.py | 218 +++++++++----- libervia/backend/plugins/plugin_xep_0373.py | 12 +- libervia/backend/plugins/plugin_xep_0446.py | 272 ++++++++++++------ libervia/backend/plugins/plugin_xep_0447.py | 184 ++++++++++-- libervia/backend/plugins/plugin_xep_0448.py | 156 ++++++---- 12 files changed, 694 insertions(+), 324 deletions(-) diff --git a/libervia/backend/plugins/plugin_misc_download.py b/libervia/backend/plugins/plugin_misc_download.py index f26d4f61..97930413 100644 --- a/libervia/backend/plugins/plugin_misc_download.py +++ b/libervia/backend/plugins/plugin_misc_download.py @@ -277,12 +277,12 @@ class DownloadPlugin(object): callback: Callable[ [ SatXMPPEntity, - Dict[str, Any], - Dict[str, Any], + dict[str, Any], + dict[str, Any], Union[str, Path], - Dict[str, Any], + dict[str, Any], ], - Tuple[str, defer.Deferred], + tuple[str, defer.Deferred], ], ) -> None: """Register a handler to manage a type of attachment source @@ -295,11 +295,11 @@ class DownloadPlugin(object): source used. The callabke must return a tuple with: - progress ID - - a Deferred which fire whant the file is fully downloaded + - a Deferred which fire when the file is fully downloaded """ - if source_type is self._download_callbacks: + if source_type in self._download_callbacks: raise exceptions.ConflictError( - f"The is already a callback registered for source type {source_type!r}" + f"There is already a callback registered for source type {source_type!r}" ) self._download_callbacks[source_type] = callback diff --git a/libervia/backend/plugins/plugin_misc_text_syntaxes.py b/libervia/backend/plugins/plugin_misc_text_syntaxes.py index 35eb45a5..e5c51569 100644 --- a/libervia/backend/plugins/plugin_misc_text_syntaxes.py +++ b/libervia/backend/plugins/plugin_misc_text_syntaxes.py @@ -43,7 +43,7 @@ try: except ImportError: raise exceptions.MissingModule( 'Missing module "lxml_html_clean". Please download and install it from ' - 'http://lxml.de/. Note that this is a separate package to install in addition ' + "http://lxml.de/. Note that this is a separate package to install in addition " 'to "lxml".' ) diff --git a/libervia/backend/plugins/plugin_misc_uri_finder.py b/libervia/backend/plugins/plugin_misc_uri_finder.py index d03c9f63..d42cf0a1 100644 --- a/libervia/backend/plugins/plugin_misc_uri_finder.py +++ b/libervia/backend/plugins/plugin_misc_uri_finder.py @@ -74,12 +74,12 @@ class URIFinder(object): @return (dict[unicode, unicode]): map from key to found uri """ keys_re = "|".join(keys) - label_re = r'\"(?P