From 9332c4b673186abfa4bd3bf1e84c140de0bd2fa5 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 4 Feb 2017 05:16:32 +0100 Subject: [PATCH] Added a separate wsgi app for the modules --- paramecio/frontend/index.py | 5 ++++- paramecio/index.py | 15 ++++++++++----- paramecio/modules/admin/index.py | 25 +++++++++++++------------ paramecio/modules/welcome/index.py | 18 ++++++++---------- paramecio/wsgiapp.py | 5 +++++ 5 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 paramecio/wsgiapp.py diff --git a/paramecio/frontend/index.py b/paramecio/frontend/index.py index 9c96b08..96233db 100644 --- a/paramecio/frontend/index.py +++ b/paramecio/frontend/index.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 -from paramecio.index import app, run_app +from paramecio.wsgiapp import app +from paramecio.index import run_app + +application=app if __name__ == "__main__": run_app(app) diff --git a/paramecio/index.py b/paramecio/index.py index 7214327..e1bf246 100644 --- a/paramecio/index.py +++ b/paramecio/index.py @@ -8,6 +8,7 @@ from paramecio.cromosoma.webmodel import WebModel from paramecio.citoplasma.datetime import set_timezone from itsdangerous import JSONWebSignatureSerializer from paramecio.citoplasma.keyutils import create_key_encrypt, create_key_encrypt_256, create_key +from paramecio.wsgiapp import app #from paramecio.citoplasma.sessions import generate_session #Prepare links for static. @@ -18,7 +19,7 @@ workdir=os.getcwd() arr_module_path={} if config.yes_static==True: - @route('/media/') + @app.route('/media/') def send_static(filename): mimetype=guess_type(workdir+'/themes/'+config.theme+'/media/'+filename) @@ -26,7 +27,7 @@ if config.yes_static==True: #def add_func_static_module(module): - @route('/mediafrom//') + @app.route('/mediafrom//') def send_static_module(module, filename): path_module=arr_module_path[module]+'/media/' @@ -84,7 +85,7 @@ if config.ssl==True: #Prepare app -app = application = default_app() +application=app #app.add_hook('before_request', print_memory) @@ -166,16 +167,20 @@ if config.session_enabled==True: # Clean last slash -@hook('before_request') +@app.hook('before_request') def strip_path(): request.environ['PATH_INFO'] = request.environ['PATH_INFO'].rstrip('/') # Set error screen if not debug setted if config.debug==False: - @error(404) + @app.error(404) def error404(error): return 'Error: page not found' +else: + @app.error(500) + def error500(error): + return error set_timezone() diff --git a/paramecio/modules/admin/index.py b/paramecio/modules/admin/index.py index c100746..89f6784 100644 --- a/paramecio/modules/admin/index.py +++ b/paramecio/modules/admin/index.py @@ -20,6 +20,7 @@ from time import time from paramecio.citoplasma.keyutils import create_key_encrypt, create_key_encrypt_256, create_key from paramecio.citoplasma.sendmail import SendMail from os import path +from paramecio.wsgiapp import app import copy #from citoplasma.login import LoginClass @@ -57,11 +58,11 @@ for k, v in menu.items(): #print(d) -@get('/'+config.admin_folder) -@get('/'+config.admin_folder+'/') -@post('/'+config.admin_folder+'/') -@get('/'+config.admin_folder+'//') -@post('/'+config.admin_folder+'//') +@app.get('/'+config.admin_folder) +@app.get('/'+config.admin_folder+'/') +@app.post('/'+config.admin_folder+'/') +@app.get('/'+config.admin_folder+'//') +@app.post('/'+config.admin_folder+'//') def home(module='', submodule=''): # A simple boolean used for show or not the code of admin module in standard template @@ -231,7 +232,7 @@ def home(module='', submodule=''): return "" -@post('/'+config.admin_folder+'/login') +@app.post('/'+config.admin_folder+'/login') def login(): connection=WebModel.connection() @@ -343,7 +344,7 @@ def login(): return {'error': 1, 'csrf_token': s['csrf_token']} -@post('/'+config.admin_folder+'/register') +@app.post('/'+config.admin_folder+'/register') def register(): getpostfiles=GetPostFiles() @@ -404,7 +405,7 @@ def register(): return {'error': 1} -@get('/'+config.admin_folder+'/logout') +@app.get('/'+config.admin_folder+'/logout') def logout(): s=get_session() @@ -427,7 +428,7 @@ def logout(): redirect(make_url(config.admin_folder)) -@get('/'+config.admin_folder+'/recovery_password') +@app.get('/'+config.admin_folder+'/recovery_password') def recovery_password(): t=PTemplate(env) @@ -446,7 +447,7 @@ def recovery_password(): connection.close() return t.render_template('admin/recovery.phtml', forms=forms) -@post('/'+config.admin_folder+'/recovery_password') +@app.post('/'+config.admin_folder+'/recovery_password') def send_password(): connection=WebModel.connection() @@ -503,13 +504,13 @@ def send_password(): return {'email': '', 'error': 0} -@get('/'+config.admin_folder+'/check_token') +@app.get('/'+config.admin_folder+'/check_token') def check_token(): t=PTemplate(env) return t.render_template('admin/check_token.phtml') -@post('/'+config.admin_folder+'/check_token') +@app.post('/'+config.admin_folder+'/check_token') def check_code_token(): t=PTemplate(env) diff --git a/paramecio/modules/welcome/index.py b/paramecio/modules/welcome/index.py index 5dcdaae..e5c60d8 100644 --- a/paramecio/modules/welcome/index.py +++ b/paramecio/modules/welcome/index.py @@ -2,31 +2,29 @@ from paramecio.citoplasma.mtemplates import PTemplate, env_theme from paramecio.citoplasma.urls import make_url -from bottle import route, request +from paramecio.wsgiapp import app from settings import config #t=ptemplate(__file__) env=env_theme(__file__) -@route('/welcome') +t=PTemplate(env) + +@app.route('/welcome') def home(): - - t=PTemplate(env) return t.render_template('welcome.html', title="Welcome to Paramecio!!!", content="The simple web framework writed in Python3!!!") -@route('/welcome/') +@app.route('/welcome/') def page(id): - - t=PTemplate(env) - + return t.render_template('index.html', title="A simple example of a page", id=id, value=request.query.value) -@route('/welcome/test/') +@app.route('/welcome/test/') def test(id): return make_url('welcome/test/5', {'ohmygod': 'This is gooood', 'shutup':'Shut up!!'}) if config.default_module=="welcome": - home = route("/")(home) + home = app.route("/")(home) diff --git a/paramecio/wsgiapp.py b/paramecio/wsgiapp.py new file mode 100644 index 0000000..fb0f088 --- /dev/null +++ b/paramecio/wsgiapp.py @@ -0,0 +1,5 @@ +from bottle import Bottle + +app=Bottle() + +