Example #1
0
    def __init__(self, config):
        self.search_view = init_view(config, 'search_html')

        self.is_frame_mode = config.get('framed_replay', False)
        self.frame_mod = 'tf_'
        self.replay_mod = ''

        self.response_class = WbResponse

        if self.is_frame_mode:
            #html = config.get('frame_insert_html', 'templates/frame_insert.html')
            #self.search_view = J2TemplateView(html, config.get('jinja_env'))
            self.frame_insert_view = init_view(config, 'frame_insert_html')
            assert (self.frame_insert_view)

            self.banner_html = config.get('banner_html', 'banner.html')

            if config.get('enable_memento', False):
                self.response_class = MementoResponse

            if self.is_frame_mode == 'inverse':
                self.frame_mod = ''
                self.replay_mod = 'mp_'

        else:
            self.frame_insert_view = None
            self.banner_html = None
Example #2
0
    def __init__(self, config):
        self.search_view = init_view(config, 'search_html')

        self.is_frame_mode = config.get('framed_replay', False)
        self.frame_mod = 'tf_'
        self.replay_mod = ''

        self.response_class = WbResponse

        if self.is_frame_mode:
            #html = config.get('frame_insert_html', 'templates/frame_insert.html')
            #self.search_view = J2TemplateView(html, config.get('jinja_env'))
            self.frame_insert_view = init_view(config, 'frame_insert_html')
            assert(self.frame_insert_view)

            self.banner_html = config.get('banner_html', 'banner.html')

            if config.get('enable_memento', False):
                self.response_class = MementoResponse

            if self.is_frame_mode == 'inverse':
                self.frame_mod = ''
                self.replay_mod = 'mp_'

        else:
            self.frame_insert_view = None
            self.banner_html = None
Example #3
0
    def __init__(self, query_handler, config=None):
        super(WBHandler, self).__init__(config)

        self.index_reader = query_handler
        self.not_found_view = init_view(config, 'not_found_html')

        self.replay = self._init_replay_view(config)

        self.fallback_handler = None
        self.fallback_name = config.get('fallback')
Example #4
0
    def __init__(self, query_handler, config=None):
        super(WBHandler, self).__init__(config)

        self.index_reader = query_handler
        self.not_found_view = init_view(config, 'not_found_html')

        self.replay = self._init_replay_view(config)

        self.fallback_handler = None
        self.fallback_name = config.get('fallback')
Example #5
0
def init_collection(route_config):
    ds_rules_file = route_config.get("domain_specific_rules", None)

    html_view = init_view(route_config, "query_html", J2HtmlCapturesView)

    server_cls = route_config.get("server_cls")

    query_handler = QueryHandler.init_from_config(route_config, ds_rules_file, html_view, server_cls)

    return query_handler
Example #6
0
def init_collection(route_config):
    ds_rules_file = route_config.get('domain_specific_rules', None)

    html_view = init_view(route_config, 'query_html', J2HtmlCapturesView)

    server_cls = route_config.get('server_cls')

    query_handler = QueryHandler.init_from_config(route_config, ds_rules_file,
                                                  html_view, server_cls)

    return query_handler
Example #7
0
File: server.py Project: netj/pokr
def init_modules():
    from flask.ext.assets import Environment as Asset
    from database import init_db
    from utils.assets import init_app as init_asset
    from utils.jinja import init_app as init_jinja
    from utils.i18n import PopongBabel
    from utils.linkall import init_app as init_linkall
    from utils.mobile import PopongMobile
    from utils.reverse_proxy import init_app as init_reverse_proxy
    from views import init_app as init_view
    from widgets import init_app as init_widgets

    Asset(app)
    init_asset(app)
    init_db(app)
    init_jinja(app)
    PopongBabel(app, **BABEL_SETTINGS)
    PopongMobile(app)
    init_linkall(app)
    init_reverse_proxy(app, SCRIPT_NAME)
    init_view(app)
    init_widgets(app)
Example #8
0
def init_modules():
    from flask.ext.assets import Environment as Asset
    from database import init_db
    from utils.assets import init_app as init_asset
    from utils.jinja import init_app as init_jinja
    from utils.i18n import PopongBabel
    from utils.linkall import init_app as init_linkall
    from utils.mobile import PopongMobile
    from utils.reverse_proxy import init_app as init_reverse_proxy
    from views import init_app as init_view
    from widgets import init_app as init_widgets

    Asset(app)
    init_asset(app)
    init_db(app)
    init_jinja(app)
    PopongBabel(app, **BABEL_SETTINGS)
    PopongMobile(app)
    init_linkall(app)
    init_reverse_proxy(app, SCRIPT_NAME)
    init_view(app)
    init_widgets(app)
Example #9
0
File: run.py Project: nacyot/pokr
    from utils.mobile import PopongMobile
    from utils.reverse_proxy import init_app as init_reverse_proxy
    from views import init_app as init_view
    from widgets import init_app as init_widgets

    Asset(app)
    init_cache(app)
    init_asset(app)
    init_db(app)
    init_jinja(app)
    PopongBabel(app)
    PopongMobile(app)
    init_linkall(app)
    init_login(app)
    init_reverse_proxy(app)
    init_view(app)
    init_widgets(app)

    setattr(app, '__loaded__', True)


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('port', type=int, nargs='?', default=50029)
    parser.add_argument('-l', dest='locale', default='auto',
                        help='force locale (e.g. en, kr)')
    return parser.parse_args()


# standalone mode
if __name__ == '__main__':
Example #10
0
def create_wb_router(passed_config=None):
    passed_config = passed_config or {}

    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', {})

    root_route = None

    # collections based on file system
    if config.get('enable_auto_colls', True):
        colls_loader_cls = config.get('colls_loader_cls', DirectoryCollsLoader)
        dir_loader = colls_loader_cls(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
    templates_dirs = config['templates_dirs']
    jinja_env = J2TemplateView.init_shared_env(paths=templates_dirs)
    jinja_env.globals.update(config.get('template_globals', {}))

    for static_name, static_path in static_routes.iteritems():
        routes.append(Route(static_name, StaticHandler(static_path)))

    for name, value in collections.iteritems():
        if isinstance(value, BaseHandler):
            handler_dict[name] = value
            new_route = Route(name, value, config=config)
            if name != '':
                routes.append(new_route)
            else:
                root_route = new_route
            continue

        route_config = init_route_config(value, config)
        route_class = route_config.get('route_class', Route)

        if route_config.get('index_paths') == '$liveweb':
            live = create_live_handler(route_config)
            handler_dict[name] = live
            new_route = route_class(name, live, config=route_config)
            if name != '':
                routes.append(new_route)
            else:
                root_route = new_route
            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)

        new_route = route_class(name,
                                wb_handler,
                                config=route_config,
                                request_class=request_class)

        if name != '':
            routes.append(new_route)
        else:
            root_route = new_route

        # 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,
                                route_class=route_class)

    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()))

    if root_route:
        routes.append(root_route)

    # 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 = init_view(config, 'proxy_select_html')

        if 'proxy_options' not in passed_config:
            passed_config['proxy_options'] = {}

        if view:
            passed_config['proxy_options']['proxy_select_view'] = view

        view = init_view(config, 'proxy_cert_download_html')

        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=init_view(config, 'home_html'),
                  error_view=init_view(config, 'error_html'),
                  config=config)
Example #11
0
def create_wb_router(passed_config=None):
    passed_config = passed_config or {}

    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', {})

    root_route = None

    # collections based on file system
    if config.get('enable_auto_colls', True):
        colls_loader_cls = config.get('colls_loader_cls', DirectoryCollsLoader)
        dir_loader = colls_loader_cls(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
    templates_dirs = config['templates_dirs']
    jinja_env = J2TemplateView.init_shared_env(paths=templates_dirs)
    jinja_env.globals.update(config.get('template_globals', {}))

    for static_name, static_path in static_routes.iteritems():
        routes.append(Route(static_name, StaticHandler(static_path)))

    for name, value in collections.iteritems():
        if isinstance(value, BaseHandler):
            handler_dict[name] = value
            new_route = Route(name, value, config=config)
            if name != '':
                routes.append(new_route)
            else:
                root_route = new_route
            continue

        route_config = init_route_config(value, config)
        route_class = route_config.get('route_class', Route)

        if route_config.get('index_paths') == '$liveweb':
            live = create_live_handler(route_config)
            handler_dict[name] = live
            new_route = route_class(name, live, config=route_config)
            if name != '':
                routes.append(new_route)
            else:
                root_route = new_route
            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)

        new_route = route_class(name, wb_handler,
                                config=route_config,
                                request_class=request_class)

        if name != '':
            routes.append(new_route)
        else:
            root_route = new_route

        # 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,
                                route_class=route_class)

    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()))

    if root_route:
        routes.append(root_route)

    # 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 = init_view(config, 'proxy_select_html')

        if 'proxy_options' not in passed_config:
            passed_config['proxy_options'] = {}

        if view:
            passed_config['proxy_options']['proxy_select_view'] = view

        view = init_view(config, 'proxy_cert_download_html')

        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=init_view(config, 'home_html'),
        error_view=init_view(config, 'error_html'),
        config=config
    )
Example #12
0
def create_wb_router(passed_config=None):
    passed_config = passed_config or {}

    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", {})

    root_route = None

    # collections based on file system
    if config.get("enable_auto_colls", True):
        colls_loader_cls = config.get("colls_loader_cls", DirectoryCollsLoader)
        dir_loader = colls_loader_cls(config, static_routes, collections)
        dir_loader()
        # 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
    templates_dirs = config["templates_dirs"]
    jinja_env = J2TemplateView.init_shared_env(paths=templates_dirs, packages=config["template_packages"])

    jinja_env.globals.update(config.get("template_globals", {}))

    for static_name, static_path in static_routes.iteritems():
        routes.append(Route(static_name, StaticHandler(static_path)))

    for name, value in collections.iteritems():
        if isinstance(value, BaseHandler):
            handler_dict[name] = value
            new_route = Route(name, value, config=config)
            if name != "":
                routes.append(new_route)
            else:
                root_route = new_route
            continue

        route_config = init_route_config(value, config)
        route_class = route_config.get("route_class", Route)

        if route_config.get("index_paths") == "$liveweb":
            live = create_live_handler(route_config)
            handler_dict[name] = live
            new_route = route_class(name, live, config=route_config)
            if name != "":
                routes.append(new_route)
            else:
                root_route = new_route
            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)

        new_route = route_class(name, wb_handler, config=route_config, request_class=request_class)

        if name != "":
            routes.append(new_route)
        else:
            root_route = new_route

        # 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, route_class=route_class)

    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()))

    if root_route:
        routes.append(root_route)

    # 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 = init_view(config, "proxy_select_html")

        if "proxy_options" not in passed_config:
            passed_config["proxy_options"] = {}

        if view:
            passed_config["proxy_options"]["proxy_select_view"] = view

        view = init_view(config, "proxy_cert_download_html")

        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=init_view(config, "home_html"),
        error_view=init_view(config, "error_html"),
        info_view=init_view(config, "info_json"),
        config=config,
    )