From a757f53bd58c018e09b23d47cf8b5003977b90dd Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Sat, 8 Feb 2014 22:01:31 -0800 Subject: [PATCH] cleanup Route config, move filters init into custom_init remove extra print --- pywb/archivalrouter.py | 15 +++++++-------- pywb/pywb_init.py | 2 +- pywb/wbapp.py | 2 -- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pywb/archivalrouter.py b/pywb/archivalrouter.py index 55a85dfb..a3781490 100644 --- a/pywb/archivalrouter.py +++ b/pywb/archivalrouter.py @@ -66,14 +66,13 @@ class Route: 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.regex = re.compile(regex + lookahead) self.handler = handler # collection id from regex group (default 0) self.coll_group = coll_group - self.filters = filters - self._custom_init() + self._custom_init(config) def __call__(self, env, use_abs_prefix): @@ -102,18 +101,18 @@ class Route: wburl_class = self.handler.get_wburl_type()) - # Allow for setup of additional filters - self._add_filters(wbrequest, matcher) + # Allow for applying of additional filters + self._apply_filters(wbrequest, matcher) return self._handle_request(wbrequest) - def _add_filters(self, wbrequest, matcher): + def _apply_filters(self, wbrequest, matcher): for filter in self.filters: last_grp = len(matcher.groups()) wbrequest.query_filter.append(filter.format(matcher.group(last_grp))) - def _custom_init(self): - pass + def _custom_init(self, config): + self.filters = config.get('filters', []) def _handle_request(self, wbrequest): return self.handler(wbrequest) diff --git a/pywb/pywb_init.py b/pywb/pywb_init.py index c2ddaffd..953a9a38 100644 --- a/pywb/pywb_init.py +++ b/pywb/pywb_init.py @@ -56,7 +56,7 @@ def pywb_config_manual(config = {}): else: 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 if route_config.get('enable_cdx_api', False): diff --git a/pywb/wbapp.py b/pywb/wbapp.py index afd8391f..44b85a0f 100644 --- a/pywb/wbapp.py +++ b/pywb/wbapp.py @@ -19,8 +19,6 @@ def create_wb_app(wb_router): else: env['REL_REQUEST_URI'] = env['REQUEST_URI'] - print env['REL_REQUEST_URI'] - response = None try: