How to use the arxiv.base.Base function in arxiv

To help you get started, we’ve selected a few arxiv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arXiv / arxiv-search / tests / stubs / docmeta.py View on Github external
import json
from flask import Flask
from flask.json import jsonify
from werkzeug.exceptions import NotFound, InternalServerError

from arxiv.base import Base
from arxiv.base.converter import ArXivConverter
from arxiv.base import logging

logger = logging.getLogger(__name__)

METADATA_DIR = os.environ.get("METADATA_DIR")


app = Flask("metadata")
Base(app)

app.url_map.converters["arxiv"] = ArXivConverter


@app.route("/docmeta/", methods=["GET"])
def docmeta(document_id):
    """Retrieve document metadata."""
    logger.debug(f"Get metadata for {document_id}")
    logger.debug(f"Metadata base is {METADATA_DIR}")
    if not METADATA_DIR:
        raise InternalServerError("Metadata directory not set")
    metadata_path = os.path.join(METADATA_DIR, f"{document_id}.json")
    logger.debug(f"Metadata path is {metadata_path}")
    if not os.path.exists(metadata_path):
        raise NotFound("No such document")
    with open(metadata_path) as f:
github arXiv / arxiv-search / search / factory.py View on Github external
def create_ui_web_app() -> Flask:
    """Initialize an instance of the search frontend UI web application."""
    logging.getLogger("boto").setLevel(logging.ERROR)
    logging.getLogger("boto3").setLevel(logging.ERROR)
    logging.getLogger("botocore").setLevel(logging.ERROR)

    app = Flask("search")
    app.config.from_pyfile("config.py")  # type: ignore
    app.url_map.converters["archive"] = ArchiveConverter

    index.SearchSession.init_app(app)

    Base(app)
    app.register_blueprint(ui.blueprint)

    s3.init_app(app)

    wrap(app, [request_logs.ClassicLogsMiddleware])
    # app.config['PROFILE'] = True
    # app.config['DEBUG'] = True
    # app.wsgi_app = ProfilerMiddleware(
    #     app.wsgi_app, restrictions=[100], sort_by=('cumtime', )
    # )

    for filter_name, template_filter in filters.filters:
        app.template_filter(filter_name)(template_filter)

    return app
github arXiv / arxiv-browse / browse / factory.py View on Github external
def create_web_app() -> Flask:
    """Initialize an instance of the browse web application."""
    app = Flask('browse', static_url_path=f'/static/browse/{APP_VERSION}')
    app.config.from_pyfile('config.py')  # type: ignore

    # TODO Only needed until this route is added to arxiv-base
    if 'URLS' not in app.config:
        app.config['URLS'] = []
    app.config['URLS'].append(
        ('search_archive', '/search/', BASE_SERVER))

    models.init_app(app)  # type: ignore
    Base(app)
    Auth(app)
    app.register_blueprint(ui.blueprint)
    s3.init_app(app)

    if not app.jinja_env.globals:
        app.jinja_env.globals = {}

    app.jinja_env.globals['canonical_url'] = canonical_url

    if not app.jinja_env.filters:
        app.jinja_env.filters = {}

    app.jinja_env.filters['entity_to_utf'] = entity_to_utf

    app.jinja_env.filters['clickthrough_url_for'] = clickthrough_url
    app.jinja_env.filters['show_email_hash'] = \
github arXiv / arxiv-search / search / factory.py View on Github external
def create_api_web_app() -> Flask:
    """Initialize an instance of the search frontend UI web application."""
    logging.getLogger("boto").setLevel(logging.ERROR)
    logging.getLogger("boto3").setLevel(logging.ERROR)
    logging.getLogger("botocore").setLevel(logging.ERROR)

    app = Flask("search")
    app.json_encoder = ISO8601JSONEncoder
    app.config.from_pyfile("config.py")  # type: ignore

    index.SearchSession.init_app(app)

    Base(app)
    auth.Auth(app)
    app.register_blueprint(api.blueprint)

    wrap(
        app,
        [request_logs.ClassicLogsMiddleware, auth.middleware.AuthMiddleware],
    )

    for error, handler in api.exceptions.get_handlers():
        app.errorhandler(error)(handler)

    return app
github arXiv / arxiv-search / search / factory.py View on Github external
def create_classic_api_web_app() -> Flask:
    """Initialize an instance of the search frontend UI web application."""
    logging.getLogger("boto").setLevel(logging.ERROR)
    logging.getLogger("boto3").setLevel(logging.ERROR)
    logging.getLogger("botocore").setLevel(logging.ERROR)

    app = Flask("search")
    app.json_encoder = ISO8601JSONEncoder
    app.config.from_pyfile("config.py")  # type: ignore

    index.SearchSession.init_app(app)

    Base(app)
    auth.Auth(app)
    app.register_blueprint(classic_api.blueprint)

    wrap(
        app,
        [request_logs.ClassicLogsMiddleware, auth.middleware.AuthMiddleware],
    )

    for error, handler in classic_api.exceptions.get_handlers():
        app.errorhandler(error)(handler)

    return app