weaver.wps_restapi.utils ======================== .. py:module:: weaver.wps_restapi.utils Module Contents --------------- .. py:data:: LOGGER .. py:exception:: HTTPHeadFileResponse(code: int = 200, headers: Optional[weaver.typedefs.HeadersType] = None, **kwargs: Any) Provides additional header handing when returning a response to HTTP HEAD request. When returning from HTTP HEAD, the body contents are omitted from the response. The response **MUST NOT** contain the body contents, but the HTTP headers **SHOULD** be identical to the corresponding HTTP GET request. .. seealso:: :rfc:`2616#section-9.4` .. note:: Even though no content is provided for HEAD response, ``204`` **SHOULD NOT** be used since it must emulate the GET response that would contain the content. When setting :attr:`HTTPException.empty_body` on :class:`pyramid.httpexceptions.HTTPException` derived classes, :mod:`pyramid` incorrectly drops important headers such as ``Content-Type`` and ``Content-Length`` that should be reported as if the file was returned when the represented entity is a file, although no content is actually present. When instead the body is omitted (``text=""`` or ``body=b''``), the :meth:`HTTPException.prepare` method also incorrectly overrides the ``Content-Type`` and ``Content-Length`` values. Finally, ``Content-Length`` also gets recalculated when the content iterator is created from the initialization parameters. This class takes care of all these edge cases to properly report content headers of HEAD requests although none is provided. Initialize self. See help(type(self)) for accurate signature. .. py:attribute:: code :value: 200 .. py:attribute:: title .. py:attribute:: explanation .. py:method:: prepare(environ: weaver.typedefs.SettingsType) -> None No contents for HEAD request. .. py:function:: get_wps_restapi_base_path(container: weaver.typedefs.AnySettingsContainer) -> str Obtain the REST :term:`API` base path. .. py:function:: get_wps_restapi_base_url(container: weaver.typedefs.AnySettingsContainer) -> str Obtain the REST :term:`API` base URL. .. py:function:: get_schema_ref(schema: colander.SchemaNode, container: Optional[weaver.typedefs.AnySettingsContainer] = None, ref_type: str = '$id', ref_name: True = True) -> Dict[str, str] Generates the JSON OpenAPI schema reference relative to the current `Weaver` instance. The provided schema should be one of the items listed in ``#/definitions`` of the ``/json`` endpoint. No validation is accomplished to avoid long processing of all references. If setting ``weaver.schema_url`` is set, this value will be used direct as fully-defined base URL. This could be used to refer to a static endpoint where schemas are hosted. Otherwise, the current Web Application resolved location is employed with JSON OpenAPI path. :param schema: schema-node instance or type for which to generate the OpenAPI reference. :param container: application settings to retrieve the base URL of the schema location. :param ref_type: key employed to form the reference (e.g.: "$id", "$ref", "$schema", "@id", etc.). :param ref_name: indicate if the plain name should also be included under field ``"schema"``. :return: OpenAPI schema reference .. py:function:: handle_schema_validation(schema: Optional[colander.SchemaNode] = None) -> weaver.typedefs.AnyCallableWrapped Convert a schema validation error into an HTTP error with error details about the failure. :param schema: If provided, document this schema as the reference of the failed schema validation. :raises HTTPBadRequest: If any schema validation error occurs when handling the decorated function. .. py:function:: add_renderer_context(event: pyramid.events.BeforeRender) -> None Adds an event subscriber that provides additional metadata for renderers.