From dfbdc7109fcba4c881231668fef7af9813a9a4eb Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 28 Jun 2021 14:49:01 +0200 Subject: [PATCH] Fixes for fix a warning about registering blueprints --- paramecio2/app.py | 13 ++++++------- paramecio2/libraries/sendmail.py | 16 +++++++++++++--- paramecio2/modules/welcome/__init__.py | 4 ++++ paramecio2/modules/welcome/app.py | 5 ++--- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/paramecio2/app.py b/paramecio2/app.py index 125907a..01cc13e 100644 --- a/paramecio2/app.py +++ b/paramecio2/app.py @@ -38,11 +38,13 @@ def start_app(): for key_app, added_app in config.apps.items(): controller_path=import_module(added_app[0]) - + controller_base=os.path.dirname(controller_path.__file__) dir_controllers=os.listdir(controller_base) + app_name=getattr(controller_path, added_app[1]) + for controller in dir_controllers: if controller.find('.py')!=-1 and controller.find('__init__')==-1: @@ -50,15 +52,12 @@ def start_app(): controller_py=controller.replace('.py', '') module_app=added_app[0]+'.'+controller_py - + a=import_module(module_app) - app_name=getattr(a, added_app[1]) - - app.register_blueprint(app_name, url_prefix=added_app[2]) - arr_module_path[key_app]=os.path.dirname(sys.modules[module_app].__file__) - + + app.register_blueprint(app_name, url_prefix=added_app[2]) """ module_app=config.apps[added_app][0] diff --git a/paramecio2/libraries/sendmail.py b/paramecio2/libraries/sendmail.py index 2b4127e..84f7374 100644 --- a/paramecio2/libraries/sendmail.py +++ b/paramecio2/libraries/sendmail.py @@ -36,9 +36,11 @@ class SendMail: else: self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS) + def connect(self): + + self.smtp=smtplib.SMTP(host=self.host, port=self.port) + if self.ssl==True: - - self.smtp=smtplib.SMTP(host=self.host, port=self.port) try: @@ -61,10 +63,11 @@ class SendMail: self.txt_error=e.__str__() return False + #login - if self.username!='': + if self.smtp!=None: try: @@ -87,9 +90,15 @@ class SendMail: self.txt_error='Error: any method for login is avaliable - '+e.__str__() return False + + return True def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]): + if self.smtp==None: + if not self.connect(): + return False + COMMASPACE=', ' if len(attachments)==0: @@ -168,6 +177,7 @@ class SendMail: if self.smtp!=None: self.smtp.quit() + self.smtp=None def __del__(self): diff --git a/paramecio2/modules/welcome/__init__.py b/paramecio2/modules/welcome/__init__.py index e69de29..7ac4675 100644 --- a/paramecio2/modules/welcome/__init__.py +++ b/paramecio2/modules/welcome/__init__.py @@ -0,0 +1,4 @@ +from flask import Blueprint, redirect + +welcome_app=Blueprint('welcome_app', __name__) + diff --git a/paramecio2/modules/welcome/app.py b/paramecio2/modules/welcome/app.py index 61ec5b0..93b504e 100644 --- a/paramecio2/modules/welcome/app.py +++ b/paramecio2/modules/welcome/app.py @@ -1,13 +1,12 @@ -from flask import Blueprint, redirect + from settings import config from paramecio2.libraries.mtemplates import PTemplate, env_theme +from paramecio2.modules.welcome import welcome_app env=env_theme(__file__) t=PTemplate(env) -welcome_app=Blueprint('welcome_app', __name__) - @welcome_app.route('/welcome') def home():