changeset 4298:060d695ae98e

plugin XEP-0106, tools (common/email): type hints.
author Goffi <goffi@goffi.org>
date Fri, 06 Sep 2024 17:44:08 +0200 (3 months ago)
parents 0f953ce5f0a8
children d2deddd6df44
files libervia/backend/plugins/plugin_xep_0106.py libervia/backend/tools/common/email.py
diffstat 2 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0106.py	Fri Sep 06 17:42:07 2024 +0200
+++ b/libervia/backend/plugins/plugin_xep_0106.py	Fri Sep 06 17:44:08 2024 +0200
@@ -61,7 +61,7 @@
     def get_handler(self, client):
         return XEP_0106_handler()
 
-    def escape(self, text):
+    def escape(self, text) -> str:
         """Escape text
 
         @param text(unicode): text to escape
@@ -78,7 +78,7 @@
                 escaped.append(c)
         return "".join(escaped)
 
-    def unescape(self, escaped):
+    def unescape(self, escaped) -> str:
         """Unescape text
 
         @param escaped(unicode): text to unescape
--- a/libervia/backend/tools/common/email.py	Fri Sep 06 17:42:07 2024 +0200
+++ b/libervia/backend/tools/common/email.py	Fri Sep 06 17:44:08 2024 +0200
@@ -20,7 +20,9 @@
 """email sending facilities"""
 
 
+from configparser import ConfigParser
 from email.mime.text import MIMEText
+from twisted.internet import defer
 from twisted.mail import smtp
 from libervia.backend.core.constants import Const as C
 from libervia.backend.tools import config as tools_config
@@ -29,16 +31,22 @@
 log = getLogger(__name__)
 
 
-def send_email(config, to_emails, subject="", body="", from_email=None):
-    """Send an email using SàT configuration
+def send_email(
+    config: ConfigParser,
+    to_emails: list[str] | str,
+    subject: str = "",
+    body: str = "",
+    from_email: str | None = None,
+) -> defer.Deferred:
+    """Send an email using Libervia configuration
 
-    @param config (ConfigParser): the configuration instance
-    @param to_emails(list[unicode], unicode): list of recipients
+    @param config: the configuration instance
+    @param to_emails: list of recipients
         if unicode, it will be split to get emails
-    @param subject(unicode): subject of the message
-    @param body(unicode): body of the message
-    @param from_email(unicode): address of the sender
-    @return (D): same as smtp.sendmail
+    @param subject: subject of the message
+    @param body: body of the message
+    @param from_email: address of the sender
+    @return:Same as smtp.sendmail.
     """
     if isinstance(to_emails, str):
         to_emails = to_emails.split()