From fc70da5e202b0efb9756b4354a474194165275df Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 20 Mar 2018 06:09:02 +0100 Subject: [PATCH] Fix in app loading --- paramecio/citoplasma/urls.py | 28 +++++++++++++++++-- paramecio/index.py | 53 ++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/paramecio/citoplasma/urls.py b/paramecio/citoplasma/urls.py index aedd78d..71b0912 100644 --- a/paramecio/citoplasma/urls.py +++ b/paramecio/citoplasma/urls.py @@ -2,6 +2,7 @@ from settings import config from bottle import request, response, HTTPResponse +import urllib.parse # A modified version of bottle url for don't need set x-proxy shit for redirect... @@ -33,7 +34,8 @@ def make_url(path, query_args={}): if len(query_args)>0: - get_query='?'+"&".join( [x+'='+y for x,y in query_args.items()] ) + #get_query='?'+"&".join( [x+'='+y for x,y in query_args.items()] ) + get_query='?'+urllib.parse.urlencode(query_args) return config.base_url+path+get_query @@ -48,7 +50,29 @@ def add_get_parameters(url, **args): if url.find('?')==-1: added_url='?' - return url+added_url+"&".join( [x+'='+str(y) for x,y in args.items()] ) + get_query=urllib.parse.urlencode(args) + + return url+added_url+get_query + +def make_external_url(path, query_args={}): + + """ + This is a method for create urls for external systems + + Keyword arguments: + path -- The base url of the url + query_args -- a ser of get variables for add to url + + """ + + get_query='' + + if len(query_args)>0: + + #get_query='?'+"&".join( [x+'='+y for x,y in query_args.items()] ) + get_query='?'+urllib.parse.urlencode(query_args) + + return path+get_query def get_actual_url(): diff --git a/paramecio/index.py b/paramecio/index.py index 4ea8391..884a69d 100644 --- a/paramecio/index.py +++ b/paramecio/index.py @@ -82,6 +82,32 @@ debug(config.debug) application=app +# Load modules + +try: + + from settings import modules + + prepare_app() + +except: + + @app.route('/') + def catch_errors(all='/'): + try: + from pathlib import Path + from settings import modules + import time + prepare_app() + p=Path('index.py') + p.touch() + time.sleep(1) + except: + raise + + redirect(request.url) + catch_errors=app.route('/')(catch_errors) + # Prepare static routes if config.yes_static==True: @@ -112,33 +138,6 @@ if config.yes_static==True: else: mimetype=guess_type(path_module+'/'+filename) return static_file(filename, root=path_module, mimetype=mimetype[0]) - -# Load modules - -try: - - from settings import modules - - prepare_app() - -except: - - @app.route('/') - def catch_errors(all='/'): - try: - from pathlib import Path - from settings import modules - import time - prepare_app() - p=Path('index.py') - p.touch() - time.sleep(1) - except: - raise - - redirect(request.url) - catch_errors=app.route('/')(catch_errors) - def run_app(app): if config.server_used!='cherrypy':