mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 15:09:54 +01:00
webagg app: support bottle debug properly as opt param
This commit is contained in:
parent
7884d4394b
commit
0399cc1046
@ -1,6 +1,5 @@
|
||||
from webagg.inputrequest import DirectWSGIInputRequest, POSTInputRequest
|
||||
from bottle import route, request, response, abort, Bottle
|
||||
import bottle
|
||||
from bottle import route, request, response, abort, Bottle, debug as bottle_debug
|
||||
|
||||
import requests
|
||||
import traceback
|
||||
@ -15,6 +14,10 @@ class ResAggApp(object):
|
||||
self.application = Bottle()
|
||||
self.application.default_error_handler = self.err_handler
|
||||
self.route_dict = {}
|
||||
self.debug = kwargs.get('debug', False)
|
||||
|
||||
if self.debug:
|
||||
bottle_debug(True)
|
||||
|
||||
@self.application.route('/')
|
||||
def list_routes():
|
||||
@ -22,7 +25,7 @@ class ResAggApp(object):
|
||||
|
||||
def add_route(self, path, handler):
|
||||
@self.application.route([path, path + '/<mode:path>'], 'ANY')
|
||||
@wrap_error
|
||||
@self.wrap_error
|
||||
def direct_input_request(mode=''):
|
||||
params = dict(request.query)
|
||||
params['mode'] = mode
|
||||
@ -30,7 +33,7 @@ class ResAggApp(object):
|
||||
return handler(params)
|
||||
|
||||
@self.application.route([path + '/postreq', path + '/<mode:path>/postreq'], 'POST')
|
||||
@wrap_error
|
||||
@self.wrap_error
|
||||
def post_fullrequest(mode=''):
|
||||
params = dict(request.query)
|
||||
params['mode'] = mode
|
||||
@ -42,7 +45,7 @@ class ResAggApp(object):
|
||||
self.route_dict[path + '/postreq'] = handler_dict
|
||||
|
||||
def err_handler(self, exc):
|
||||
if bottle.debug:
|
||||
if self.debug:
|
||||
print(exc)
|
||||
traceback.print_exc()
|
||||
response.status = exc.status_code
|
||||
@ -51,9 +54,7 @@ class ResAggApp(object):
|
||||
response.headers['ResErrors'] = err_msg
|
||||
return err_msg
|
||||
|
||||
|
||||
#=============================================================================
|
||||
def wrap_error(func):
|
||||
def wrap_error(self, func):
|
||||
def wrap_func(*args, **kwargs):
|
||||
try:
|
||||
out_headers, res, errs = func(*args, **kwargs)
|
||||
@ -69,7 +70,7 @@ def wrap_error(func):
|
||||
|
||||
last_exc = errs.pop('last_exc', None)
|
||||
if last_exc:
|
||||
if bottle.debug:
|
||||
if self.debug:
|
||||
traceback.print_exc()
|
||||
|
||||
response.status = last_exc.status()
|
||||
@ -88,7 +89,7 @@ def wrap_error(func):
|
||||
return err_msg
|
||||
|
||||
except Exception as e:
|
||||
if bottle.debug:
|
||||
if self.debug:
|
||||
traceback.print_exc()
|
||||
abort(500, 'Internal Error: ' + str(e))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user