cowbird.api.generic =================== .. py:module:: cowbird.api.generic Attributes ---------- .. autoapisummary:: cowbird.api.generic.LOGGER Classes ------- .. autoapisummary:: cowbird.api.generic.RemoveSlashNotFoundViewFactory Functions --------- .. autoapisummary:: cowbird.api.generic.internal_server_error cowbird.api.generic.not_found_or_method_not_allowed cowbird.api.generic.guess_target_format cowbird.api.generic.validate_accept_header_tween cowbird.api.generic.apply_response_format_tween cowbird.api.generic.get_exception_info cowbird.api.generic.get_request_info Module Contents --------------- .. py:data:: LOGGER .. py:class:: RemoveSlashNotFoundViewFactory(notfound_view: Optional[Callable[[pyramid.request.Request], cowbird.typedefs.AnyResponseType]] = None) Bases: :py:obj:`object` Utility that will try to resolve a path without appended slash if one was provided. .. py:attribute:: notfound_view :value: None .. py:method:: __call__(request: pyramid.request.Request) -> cowbird.typedefs.AnyResponseType .. py:function:: internal_server_error(request: pyramid.request.Request) -> pyramid.httpexceptions.HTTPException Overrides default HTTP. .. py:function:: not_found_or_method_not_allowed(request: pyramid.request.Request) -> pyramid.httpexceptions.HTTPException Overrides the default ``HTTPNotFound`` [404] by appropriate ``HTTPMethodNotAllowed`` [405] when applicable. Not found response can correspond to underlying process operation not finding a required item, or a completely unknown route (path did not match any existing API definition). Method not allowed is more specific to the case where the path matches an existing API route, but the specific request method (GET, POST, etc.) is not allowed on this path. Without this fix, both situations return [404] regardless. .. py:function:: guess_target_format(request: pyramid.request.Request) -> Tuple[str, bool] Guess the best applicable response ``Content-Type`` header according to request ``Accept`` header and ``format`` query, or defaulting to :py:data:`CONTENT_TYPE_JSON`. :returns: tuple of matched MIME-type and where it was found (``True``: header, ``False``: query) .. py:function:: validate_accept_header_tween(handler: Callable[[pyramid.request.Request], pyramid.response.Response], registry: pyramid.registry.Registry) -> Callable[[pyramid.request.Request], pyramid.response.Response] Tween that validates that the specified request ``Accept`` header or ``format`` query (if any) is supported by the application and for the given context. :raises HTTPNotAcceptable: if desired ``Content-Type`` is not supported. .. py:function:: apply_response_format_tween(handler: Callable[[pyramid.request.Request], pyramid.httpexceptions.HTTPException], registry: pyramid.registry.Registry) -> Callable[[pyramid.request.Request], pyramid.response.Response] Tween that obtains the request ``Accept`` header or ``format`` query (if any) to generate the response with the desired ``Content-Type``. The target ``Content-Type`` is expected to have been validated by :func:`validate_accept_header_tween` beforehand to handle not-acceptable errors. The tween also ensures that additional request metadata extracted from :func:`get_request_info` is applied to the response body if not already provided by a previous operation. .. py:function:: get_exception_info(response: Union[pyramid.httpexceptions.HTTPException, pyramid.request.Request, pyramid.response.Response], content: Optional[cowbird.typedefs.JSON] = None, exception_details: bool = False) -> cowbird.typedefs.JSON Obtains additional exception content details about the :paramref:`response` according to available information. .. py:function:: get_request_info(request: Union[pyramid.request.Request, pyramid.httpexceptions.HTTPException], default_message: Optional[str] = None, exception_details: bool = False) -> cowbird.typedefs.JSON Obtains additional content details about the :paramref:`request` according to available information.