Ver Fonte

upd: now Error works for no error
Also added user_name and password optional to send_email.

Mikael Koli há 4 anos atrás
pai
commit
d497721467
2 ficheiros alterados com 11 adições e 4 exclusões
  1. 1 1
      redmail/email/__init__.py
  2. 10 3
      redmail/models/system.py

+ 1 - 1
redmail/email/__init__.py

@@ -5,7 +5,7 @@ gmail = EmailSender(
     port=587,
 )
 
-def send_email(*args, host:str, port:int, user_name:str, password:str, **kwargs):
+def send_email(*args, host:str, port:int, user_name:str=None, password:str=None, **kwargs):
     """Send email
 
     Parameters

+ 10 - 3
redmail/models/system.py

@@ -29,6 +29,13 @@ class Error:
             return self.as_html_inline()
         elif self.content_type == "html":
             return self.as_html()
+        else:
+            raise ValueError(f"Invalid content_type: {self.content_type}")
+
+    def __bool__(self):
+        "Return true if there is an error, false if not"
+        exc_type, _, _ = self.exc_format()
+        return exc_type is not None
 
     def as_text(self):
         "Format traceback as text"
@@ -96,7 +103,7 @@ class Error:
             exc_value = self.exception
             exc_type = type(self.exception)
             tb = self.exception.__traceback__
-        tb_list = traceback.format_tb(tb)
-        exc_str = str(exc_value)
-        exc_type_str = exc_type.__name__
+        tb_list = traceback.format_tb(tb) if tb is not None else None
+        exc_str = str(exc_value) if exc_value is not None else None
+        exc_type_str = exc_type.__name__ if exc_type is not None else None
         return exc_type_str, exc_str, tb_list