How to use the arxiv.base.logging.getLogger 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 / search / controllers / api / __init__.py View on Github external
from search import consts
from search.services import index
from search.controllers.util import paginate
from search.domain import (
    Query,
    APIQuery,
    FieldedSearchList,
    FieldedSearchTerm,
    DateRange,
    Classification,
    DocumentSet,
    ClassicAPIQuery,
)


logger = logging.getLogger(__name__)


SearchResponseData = TypedDict(
    "SearchResponseData",
    {"results": DocumentSet, "query": Union[Query, ClassicAPIQuery]},
)


def search(params: MultiDict) -> Tuple[Dict[str, Any], int, Dict[str, Any]]:
    """
    Handle a search request from the API.

    Parameters
    ----------
    params : :class:`MultiDict`
        GET query parameters from the request.
github arXiv / arxiv-search / search / services / index / results.py View on Github external
"""

import re
from datetime import datetime
from math import floor
from typing import Any, Dict, Union

from elasticsearch_dsl.response import Response, Hit
from elasticsearch_dsl.utils import AttrList, AttrDict
from search.domain import Document, Query, DocumentSet, Classification, Person
from arxiv.base import logging

from .util import MAX_RESULTS, TEXISM
from .highlighting import add_highlighting, preview

logger = logging.getLogger(__name__)
logger.propagate = False


def to_document(raw: Union[Hit, dict], highlight: bool = True) -> Document:
    """Transform an ES search result back into a :class:`.Document`."""
    # typing: ignore
    result: Document = {}

    result['match'] = {}  # Hit on field, but no highlighting.
    result['truncated'] = {}    # Preview is truncated.

    result.update(raw.__dict__['_d_'])

    # Parse dates to date/datetime objects.
    if 'announced_date_first' in result:
        result['announced_date_first'] = \
github arXiv / arxiv-search / search / routes / classic_api / __init__.py View on Github external
"""Provides the classic search API."""

__all__ = ["blueprint", "exceptions"]

from flask import Blueprint, make_response, request, Response

from arxiv.base import logging
from arxiv.users.auth import scopes
from arxiv.users.auth.decorators import scoped
from search import serialize
from search.controllers import classic_api
from search.routes.consts import ATOM_XML
from search.routes.classic_api import exceptions

logger = logging.getLogger(__name__)

blueprint = Blueprint("classic_api", __name__, url_prefix="/classic_api")


@blueprint.route("/query", methods=["GET"])
@scoped(required=scopes.READ_PUBLIC)
def query() -> Response:
    """Main query endpoint."""
    logger.debug("Got query: %s", request.args)
    data, status_code, headers = classic_api.query(request.args)
    # requested = request.accept_mimetypes.best_match([JSON, ATOM_XML])
    # if requested == ATOM_XML:
    #     return serialize.as_atom(data), status, headers
    response_data = serialize.as_atom(data.results, query=data.query)
    headers.update({"Content-type": ATOM_XML})
    response: Response = make_response(response_data, status_code, headers)
github arXiv / arxiv-search / search / routes / classic_api / exceptions.py View on Github external
MethodNotAllowed,
    RequestEntityTooLarge,
    BadRequest,
    InternalServerError,
    HTTPException,
)
from flask import make_response, Response

from arxiv.base import logging
from search.serialize import as_atom
from search.domain import Error
from search.routes.consts import ATOM_XML
from search.errors import ValidationError


logger = logging.getLogger(__name__)

_handlers = []


def handler(exception: type) -> Callable:
    """Generate a decorator to register a handler for an exception."""

    def deco(func: Callable) -> Callable:
        """Register a function as an exception handler."""
        _handlers.append((exception, func))
        return func

    return deco


def get_handlers() -> List[Tuple[type, Callable]]:
github arXiv / arxiv-search / search / controllers / classic_api / __init__.py View on Github external
from arxiv.base import logging
from arxiv.identifier import parse_arxiv_id

from search.services import index
from search.errors import ValidationError
from search.domain import (
    SortDirection,
    SortBy,
    SortOrder,
    DocumentSet,
    ClassicAPIQuery,
    ClassicSearchResponseData,
)

logger = logging.getLogger(__name__)


def query(
    params: MultiDict,
) -> Tuple[ClassicSearchResponseData, HTTPStatus, Dict[str, Any]]:
    """
    Handle a search request from the Clasic API.

    First, the method maps old request parameters to new parameters:
    - search_query -> query
    - start -> start
    - max_results -> size

    Then the request is passed to :method:`search()` and returned.

    If ``id_list`` is specified in the parameters and ``search_query`` is
github arXiv / arxiv-search / search / controllers / advanced / __init__.py View on Github external
from search.services import index, SearchSession
from search.domain import (
    AdvancedQuery,
    FieldedSearchTerm,
    DateRange,
    Classification,
    FieldedSearchList,
    ClassificationList,
    Query,
)
from search import consts
from search.controllers.advanced import forms
from search.controllers.util import paginate, catch_underscore_syntax


logger = logging.getLogger(__name__)


Response = Tuple[Dict[str, Any], int, Dict[str, Any]]


TERM_FIELD_PTN = re.compile(r"terms-([0-9])+-term")


def search(request_params: MultiDict) -> Response:
    """
    Perform a search from the advanced search interface.

    This is intended to support ONLY form-based search, to replace the classic
    advanced search view.

    Parameters