mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
cleanup Route config, move filters init into custom_init
remove extra print
This commit is contained in:
parent
44f38f44d5
commit
a757f53bd5
@ -66,14 +66,13 @@ class Route:
|
|||||||
SLASH_QUERY_LOOKAHEAD ='(?=/|$|\?)'
|
SLASH_QUERY_LOOKAHEAD ='(?=/|$|\?)'
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, regex, handler, coll_group = 0, filters = [], lookahead = SLASH_QUERY_LOOKAHEAD):
|
def __init__(self, regex, handler, coll_group = 0, config = {}, lookahead = SLASH_QUERY_LOOKAHEAD):
|
||||||
self.path = regex
|
self.path = regex
|
||||||
self.regex = re.compile(regex + lookahead)
|
self.regex = re.compile(regex + lookahead)
|
||||||
self.handler = handler
|
self.handler = handler
|
||||||
# collection id from regex group (default 0)
|
# collection id from regex group (default 0)
|
||||||
self.coll_group = coll_group
|
self.coll_group = coll_group
|
||||||
self.filters = filters
|
self._custom_init(config)
|
||||||
self._custom_init()
|
|
||||||
|
|
||||||
|
|
||||||
def __call__(self, env, use_abs_prefix):
|
def __call__(self, env, use_abs_prefix):
|
||||||
@ -102,18 +101,18 @@ class Route:
|
|||||||
wburl_class = self.handler.get_wburl_type())
|
wburl_class = self.handler.get_wburl_type())
|
||||||
|
|
||||||
|
|
||||||
# Allow for setup of additional filters
|
# Allow for applying of additional filters
|
||||||
self._add_filters(wbrequest, matcher)
|
self._apply_filters(wbrequest, matcher)
|
||||||
|
|
||||||
return self._handle_request(wbrequest)
|
return self._handle_request(wbrequest)
|
||||||
|
|
||||||
def _add_filters(self, wbrequest, matcher):
|
def _apply_filters(self, wbrequest, matcher):
|
||||||
for filter in self.filters:
|
for filter in self.filters:
|
||||||
last_grp = len(matcher.groups())
|
last_grp = len(matcher.groups())
|
||||||
wbrequest.query_filter.append(filter.format(matcher.group(last_grp)))
|
wbrequest.query_filter.append(filter.format(matcher.group(last_grp)))
|
||||||
|
|
||||||
def _custom_init(self):
|
def _custom_init(self, config):
|
||||||
pass
|
self.filters = config.get('filters', [])
|
||||||
|
|
||||||
def _handle_request(self, wbrequest):
|
def _handle_request(self, wbrequest):
|
||||||
return self.handler(wbrequest)
|
return self.handler(wbrequest)
|
||||||
|
@ -56,7 +56,7 @@ def pywb_config_manual(config = {}):
|
|||||||
else:
|
else:
|
||||||
route_class = archivalrouter.Route
|
route_class = archivalrouter.Route
|
||||||
|
|
||||||
routes.append(route_class(name, wb_handler, filters = route_config.get('filters', [])))
|
routes.append(route_class(name, wb_handler, config = route_config))
|
||||||
|
|
||||||
# cdx query handler
|
# cdx query handler
|
||||||
if route_config.get('enable_cdx_api', False):
|
if route_config.get('enable_cdx_api', False):
|
||||||
|
@ -19,8 +19,6 @@ def create_wb_app(wb_router):
|
|||||||
else:
|
else:
|
||||||
env['REL_REQUEST_URI'] = env['REQUEST_URI']
|
env['REL_REQUEST_URI'] = env['REQUEST_URI']
|
||||||
|
|
||||||
print env['REL_REQUEST_URI']
|
|
||||||
|
|
||||||
response = None
|
response = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user