Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
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
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'] = \
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
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