from pyramid.view import view_config from h.api import cors from h.api.events import AnnotationEvent from h.api.presenters import AnnotationJSONPresenter from h.api.presenters import AnnotationJSONLDPresenter from h.api import search as search_lib from h.api import schemas from h.api import storage _ = i18n.TranslationStringFactory(__package__) cors_policy = cors.policy(allow_headers=( 'Authorization', 'Content-Type', 'X-Annotator-Auth-Token', 'X-Client-Id', ), allow_methods=('HEAD', 'GET', 'POST', 'PUT', 'DELETE')) class APIError(Exception): """Base exception for problems handling API requests.""" def __init__(self, message, status_code=500): self.status_code = status_code super(APIError, self).__init__(message) class PayloadError(APIError): """Exception raised for API requests made with missing/invalid payloads.""" def __init__(self):
from h.api.events import AnnotationEvent from h.api import search as search_lib from h.api import logic from h.api import validators from h.api.resources import Annotation from h.api.resources import Annotations from h.api.resources import Root log = logging.getLogger(__name__) cors_policy = cors.policy( allow_headers=( 'Authorization', 'Content-Type', 'X-Annotator-Auth-Token', 'X-Client-Id', ), allow_methods=('HEAD', 'GET', 'POST', 'PUT', 'DELETE')) def api_config(**settings): """ A view configuration decorator with defaults. JSON in and out. CORS with tokens and client id but no cookie. """ settings.setdefault('decorator', cors_policy) return json_view(**settings)
from h.api import cors from h.api.events import AnnotationEvent from h.api import search as search_lib from h.api import logic from h.api import schemas from h.api.resources import Annotation from h.api.resources import Annotations from h.api.resources import Root log = logging.getLogger(__name__) cors_policy = cors.policy( allow_headers=("Authorization", "Content-Type", "X-Annotator-Auth-Token", "X-Client-Id"), allow_methods=("HEAD", "GET", "POST", "PUT", "DELETE"), ) def api_config(**settings): """ A view configuration decorator with defaults. JSON in and out. CORS with tokens and client id but no cookie. """ settings.setdefault("decorator", cors_policy) return json_view(**settings) def json_view(**settings): """A view configuration decorator with JSON defaults."""