def __init__(self, config): self.search_view = (J2TemplateView.create_template( config.get('search_html'), 'Search Page')) self.is_frame_mode = config.get('framed_replay', False) self.response_class = WbResponse if self.is_frame_mode: html = config.get('frame_insert_html', 'ui/frame_insert.html') self.frame_insert_view = (J2TemplateView.create_template( html, 'Frame Insert')) self.banner_html = config.get('banner_html', 'banner.html') if config.get('enable_memento', False): self.response_class = MementoResponse else: self.frame_insert_view = None self.banner_html = None
def __init__(self, query_handler, config=None): super(WBHandler, self).__init__(config) self.index_reader = query_handler self.not_found_view = (J2TemplateView.create_template( config.get('not_found_html'), 'Not Found Error')) self.replay = self._init_replay_view(config) self.fallback_handler = None self.fallback_name = config.get('fallback')
def create_wb_router(passed_config={}): config = DictChain(passed_config, DEFAULTS) routes = [] # TODO: examine this more hostname = os.environ.get('PYWB_HOST_NAME') if hostname: hostpaths = [hostname] else: hostpaths = config.get('hostpaths') port = config.get('port') # collections based on cdx source collections = config.get('collections') if config.get('enable_memento', False): request_class = MementoRequest else: request_class = WbRequest # store live and replay handlers handler_dict = {} # setup template globals template_globals = config.get('template_globals') if template_globals: add_env_globals(template_globals) for name, value in collections.iteritems(): if isinstance(value, BaseHandler): handler_dict[name] = value routes.append(Route(name, value, config=route_config)) continue route_config = init_route_config(value, config) if route_config.get('index_paths') == '$liveweb': live = create_live_handler(route_config) handler_dict[name] = live routes.append(Route(name, live, config=route_config)) continue query_handler = init_collection(route_config) wb_handler = create_wb_handler( query_handler=query_handler, config=route_config, ) handler_dict[name] = wb_handler logging.debug('Adding Collection: ' + name) route_class = route_config.get('route_class', Route) routes.append( route_class(name, wb_handler, config=route_config, request_class=request_class)) # cdx query handler cdx_api_suffix = route_config.get('enable_cdx_api', False) if cdx_api_suffix: add_cdx_api_handler(name, cdx_api_suffix, routes, query_handler) if config.get('debug_echo_env', False): routes.append(Route('echo_env', DebugEchoEnvHandler())) if config.get('debug_echo_req', False): routes.append(Route('echo_req', DebugEchoHandler())) static_routes = config.get('static_routes') for static_name, static_path in static_routes.iteritems(): routes.append(Route(static_name, StaticHandler(static_path))) # resolve any cross handler references for route in routes: if hasattr(route.handler, 'resolve_refs'): route.handler.resolve_refs(handler_dict) # default to regular archival mode router = ArchivalRouter if config.get('enable_http_proxy', False): router = ProxyArchivalRouter view = J2TemplateView.create_template(config.get('proxy_select_html'), 'Proxy Coll Selector') if not 'proxy_options' in passed_config: passed_config['proxy_options'] = {} if view: passed_config['proxy_options']['proxy_select_view'] = view view = J2TemplateView.create_template( config.get('proxy_cert_download_html'), 'Proxy Cert Download') if view: passed_config['proxy_options']['proxy_cert_download_view'] = view # Finally, create wb router return router( routes, # Specify hostnames that pywb will be running on # This will help catch occasionally missed rewrites that # fall-through to the host # (See archivalrouter.ReferRedirect) hostpaths=hostpaths, port=port, abs_path=config.get('absolute_paths', True), home_view=J2TemplateView.create_template(config.get('home_html'), 'Home Page'), error_view=J2TemplateView.create_template(config.get('error_html'), 'Error Page'), config=config)
def create_wb_router(passed_config={}): defaults = load_yaml_config(DEFAULT_CONFIG) config = DictChain(passed_config, defaults) routes = [] port = config.get('port') collections = config.get('collections', {}) static_routes = config.get('static_routes', {}) # collections based on file system dir_loader = DirectoryCollsLoader(config, static_routes) collections.update(dir_loader()) if config.get('enable_memento', False): request_class = MementoRequest else: request_class = WbRequest # store live and replay handlers handler_dict = {} # setup template globals template_globals = config.get('template_globals') if template_globals: add_env_globals(template_globals) for name, value in collections.iteritems(): if isinstance(value, BaseHandler): handler_dict[name] = value routes.append(Route(name, value, config=route_config)) continue route_config = init_route_config(value, config) if route_config.get('index_paths') == '$liveweb': live = create_live_handler(route_config) handler_dict[name] = live routes.append(Route(name, live, config=route_config)) continue query_handler = init_collection(route_config) wb_handler = create_wb_handler( query_handler=query_handler, config=route_config, ) handler_dict[name] = wb_handler logging.debug('Adding Collection: ' + name) route_class = route_config.get('route_class', Route) routes.append(route_class(name, wb_handler, config=route_config, request_class=request_class)) # cdx query handler cdx_api_suffix = route_config.get('enable_cdx_api', False) if cdx_api_suffix: add_cdx_api_handler(name, cdx_api_suffix, routes, query_handler) if config.get('debug_echo_env', False): routes.append(Route('echo_env', DebugEchoEnvHandler())) if config.get('debug_echo_req', False): routes.append(Route('echo_req', DebugEchoHandler())) for static_name, static_path in static_routes.iteritems(): routes.append(Route(static_name, StaticHandler(static_path))) # resolve any cross handler references for route in routes: if hasattr(route.handler, 'resolve_refs'): route.handler.resolve_refs(handler_dict) # default to regular archival mode router = ArchivalRouter if config.get('enable_http_proxy', False): router = ProxyArchivalRouter view = J2TemplateView.create_template( config.get('proxy_select_html'), 'Proxy Coll Selector') if 'proxy_options' not in passed_config: passed_config['proxy_options'] = {} if view: passed_config['proxy_options']['proxy_select_view'] = view view = J2TemplateView.create_template( config.get('proxy_cert_download_html'), 'Proxy Cert Download') if view: passed_config['proxy_options']['proxy_cert_download_view'] = view # Finally, create wb router return router( routes, port=port, abs_path=config.get('absolute_paths', True), home_view=J2TemplateView.create_template(config.get('home_html'), 'Home Page'), error_view=J2TemplateView.create_template(config.get('error_html'), 'Error Page'), config=config )
def create_wb_router(passed_config={}): defaults = load_yaml_config(DEFAULT_CONFIG) config = DictChain(passed_config, defaults) routes = [] port = config.get('port') collections = config.get('collections', {}) static_routes = config.get('static_routes', {}) # collections based on file system dir_loader = DirectoryCollsLoader(config, static_routes) collections.update(dir_loader()) if config.get('enable_memento', False): request_class = MementoRequest else: request_class = WbRequest # store live and replay handlers handler_dict = {} # setup template globals template_globals = config.get('template_globals') if template_globals: add_env_globals(template_globals) for name, value in collections.iteritems(): if isinstance(value, BaseHandler): handler_dict[name] = value routes.append(Route(name, value, config=route_config)) continue route_config = init_route_config(value, config) if route_config.get('index_paths') == '$liveweb': live = create_live_handler(route_config) handler_dict[name] = live routes.append(Route(name, live, config=route_config)) continue query_handler = init_collection(route_config) wb_handler = create_wb_handler( query_handler=query_handler, config=route_config, ) handler_dict[name] = wb_handler logging.debug('Adding Collection: ' + name) route_class = route_config.get('route_class', Route) routes.append( route_class(name, wb_handler, config=route_config, request_class=request_class)) # cdx query handler cdx_api_suffix = route_config.get('enable_cdx_api', False) if cdx_api_suffix: add_cdx_api_handler(name, cdx_api_suffix, routes, query_handler) if config.get('debug_echo_env', False): routes.append(Route('echo_env', DebugEchoEnvHandler())) if config.get('debug_echo_req', False): routes.append(Route('echo_req', DebugEchoHandler())) for static_name, static_path in static_routes.iteritems(): routes.append(Route(static_name, StaticHandler(static_path))) # resolve any cross handler references for route in routes: if hasattr(route.handler, 'resolve_refs'): route.handler.resolve_refs(handler_dict) # default to regular archival mode router = ArchivalRouter if config.get('enable_http_proxy', False): router = ProxyArchivalRouter view = J2TemplateView.create_template(config.get('proxy_select_html'), 'Proxy Coll Selector') if 'proxy_options' not in passed_config: passed_config['proxy_options'] = {} if view: passed_config['proxy_options']['proxy_select_view'] = view view = J2TemplateView.create_template( config.get('proxy_cert_download_html'), 'Proxy Cert Download') if view: passed_config['proxy_options']['proxy_cert_download_view'] = view # Finally, create wb router return router( routes, port=port, abs_path=config.get('absolute_paths', True), home_view=J2TemplateView.create_template(config.get('home_html'), 'Home Page'), error_view=J2TemplateView.create_template(config.get('error_html'), 'Error Page'), config=config)
def create_wb_router(passed_config={}): config = DictChain(passed_config, DEFAULTS) routes = [] # TODO: examine this more hostname = os.environ.get('PYWB_HOST_NAME') if hostname: hostpaths = [hostname] else: hostpaths = config.get('hostpaths') port = config.get('port') # collections based on cdx source collections = config.get('collections') if config.get('enable_memento', False): request_class = MementoRequest else: request_class = WbRequest # store live and replay handlers handler_dict = {} # setup template globals template_globals = config.get('template_globals') if template_globals: add_env_globals(template_globals) for name, value in collections.iteritems(): if isinstance(value, BaseHandler): handler_dict[name] = value routes.append(Route(name, value, config=route_config)) continue route_config = init_route_config(value, config) if route_config.get('index_paths') == '$liveweb': live = create_live_handler(route_config) handler_dict[name] = live routes.append(Route(name, live, config=route_config)) continue query_handler = init_collection(route_config) wb_handler = create_wb_handler( query_handler=query_handler, config=route_config, ) handler_dict[name] = wb_handler logging.debug('Adding Collection: ' + name) route_class = route_config.get('route_class', Route) routes.append(route_class(name, wb_handler, config=route_config, request_class=request_class)) # cdx query handler cdx_api_suffix = route_config.get('enable_cdx_api', False) if cdx_api_suffix: add_cdx_api_handler(name, cdx_api_suffix, routes, query_handler) if config.get('debug_echo_env', False): routes.append(Route('echo_env', DebugEchoEnvHandler())) if config.get('debug_echo_req', False): routes.append(Route('echo_req', DebugEchoHandler())) static_routes = config.get('static_routes') for static_name, static_path in static_routes.iteritems(): routes.append(Route(static_name, StaticHandler(static_path))) # resolve any cross handler references for route in routes: if hasattr(route.handler, 'resolve_refs'): route.handler.resolve_refs(handler_dict) # default to regular archival mode router = ArchivalRouter if config.get('enable_http_proxy', False): router = ProxyArchivalRouter view = J2TemplateView.create_template( config.get('proxy_select_html'), 'Proxy Coll Selector') if not 'proxy_options' in passed_config: passed_config['proxy_options'] = {} if view: passed_config['proxy_options']['proxy_select_view'] = view view = J2TemplateView.create_template( config.get('proxy_cert_download_html'), 'Proxy Cert Download') if view: passed_config['proxy_options']['proxy_cert_download_view'] = view # Finally, create wb router return router( routes, # Specify hostnames that pywb will be running on # This will help catch occasionally missed rewrites that # fall-through to the host # (See archivalrouter.ReferRedirect) hostpaths=hostpaths, port=port, abs_path=config.get('absolute_paths', True), home_view=J2TemplateView.create_template(config.get('home_html'), 'Home Page'), error_view=J2TemplateView.create_template(config.get('error_html'), 'Error Page'), config=config )