weaver.wps_restapi.patches ========================== .. py:module:: weaver.wps_restapi.patches .. autoapi-nested-parse:: Helpers to work around some default view configurations that are not desired. Module Contents --------------- .. py:class:: Configurator(registry=None, package=None, settings=None, root_factory=None, security_policy=None, authentication_policy=None, authorization_policy=None, renderers=None, debug_logger=None, locale_negotiator=None, request_factory=None, response_factory=None, default_permission=None, session_factory=None, default_view_mapper=None, autocommit=False, exceptionresponse_view=default_exceptionresponse_view, route_prefix=None, introspection=True, root_package=None) A Configurator is used to configure a :app:`Pyramid` :term:`application registry`. The Configurator lifecycle can be managed by using a context manager to automatically handle calling :meth:`pyramid.config.Configurator.begin` and :meth:`pyramid.config.Configurator.end` as well as :meth:`pyramid.config.Configurator.commit`. .. code-block:: python with Configurator(settings=settings) as config: config.add_route('home', '/') app = config.make_wsgi_app() If the ``registry`` argument is not ``None``, it must be an instance of the :class:`pyramid.registry.Registry` class representing the registry to configure. If ``registry`` is ``None``, the configurator will create a :class:`pyramid.registry.Registry` instance itself; it will also perform some default configuration that would not otherwise be done. After its construction, the configurator may be used to add further configuration to the registry. .. warning:: If ``registry`` is assigned the above-mentioned class instance, all other constructor arguments are ignored, with the exception of ``package``. If the ``package`` argument is passed, it must be a reference to a Python :term:`package` (e.g. ``sys.modules['thepackage']``) or a :term:`dotted Python name` to the same. This value is used as a basis to convert relative paths passed to various configuration methods, such as methods which accept a ``renderer`` argument, into absolute paths. If ``None`` is passed (the default), the package is assumed to be the Python package in which the *caller* of the ``Configurator`` constructor lives. If the ``root_package`` is passed, it will propagate through the configuration hierarchy as a way for included packages to locate resources relative to the package in which the main ``Configurator`` was created. If ``None`` is passed (the default), the ``root_package`` will be derived from the ``package`` argument. The ``package`` attribute is always pointing at the package being included when using :meth:`.include`, whereas the ``root_package`` does not change. If the ``settings`` argument is passed, it should be a Python dictionary representing the :term:`deployment settings` for this application. These are later retrievable using the :attr:`pyramid.registry.Registry.settings` attribute (aka ``request.registry.settings``). If the ``root_factory`` argument is passed, it should be an object representing the default :term:`root factory` for your application or a :term:`dotted Python name` to the same. If it is ``None``, a default root factory will be used. If ``security_policy`` is passed, it should be an instance of a :term:`security policy` or a :term:`dotted Python name` to the same. If ``authentication_policy`` is passed, it should be an instance of an :term:`authentication policy` or a :term:`dotted Python name` to the same. If ``authorization_policy`` is passed, it should be an instance of an :term:`authorization policy` or a :term:`dotted Python name` to the same. .. note:: A ``ConfigurationError`` will be raised when an authorization policy is supplied without also supplying an authentication policy (authorization requires authentication). If ``renderers`` is ``None`` (the default), a default set of :term:`renderer` factories is used. Else, it should be a list of tuples representing a set of renderer factories which should be configured into this application, and each tuple representing a set of positional values that should be passed to :meth:`pyramid.config.Configurator.add_renderer`. If ``debug_logger`` is not passed, a default debug logger that logs to a logger will be used (the logger name will be the package name of the *caller* of this configurator). If it is passed, it should be an instance of the :class:`logging.Logger` (PEP 282) standard library class or a Python logger name. The debug logger is used by :app:`Pyramid` itself to log warnings and authorization debugging information. If ``locale_negotiator`` is passed, it should be a :term:`locale negotiator` implementation or a :term:`dotted Python name` to same. See :ref:`custom_locale_negotiator`. If ``request_factory`` is passed, it should be a :term:`request factory` implementation or a :term:`dotted Python name` to the same. See :ref:`changing_the_request_factory`. By default it is ``None``, which means use the default request factory. If ``response_factory`` is passed, it should be a :term:`response factory` implementation or a :term:`dotted Python name` to the same. See :ref:`changing_the_response_factory`. By default it is ``None``, which means use the default response factory. If ``default_permission`` is passed, it should be a :term:`permission` string to be used as the default permission for all view configuration registrations performed against this Configurator. An example of a permission string:``'view'``. Adding a default permission makes it unnecessary to protect each view configuration with an explicit permission, unless your application policy requires some exception for a particular view. By default, ``default_permission`` is ``None``, meaning that view configurations which do not explicitly declare a permission will always be executable by entirely anonymous users (any authorization policy in effect is ignored). .. seealso:: See also :ref:`setting_a_default_permission`. If ``session_factory`` is passed, it should be an object which implements the :term:`session factory` interface. If a nondefault value is passed, the ``session_factory`` will be used to create a session object when ``request.session`` is accessed. Note that the same outcome can be achieved by calling :meth:`pyramid.config.Configurator.set_session_factory`. By default, this argument is ``None``, indicating that no session factory will be configured (and thus accessing ``request.session`` will throw an error) unless ``set_session_factory`` is called later during configuration. If ``autocommit`` is ``True``, every method called on the configurator will cause an immediate action, and no configuration conflict detection will be used. If ``autocommit`` is ``False``, most methods of the configurator will defer their action until :meth:`pyramid.config.Configurator.commit` is called. When :meth:`pyramid.config.Configurator.commit` is called, the actions implied by the called methods will be checked for configuration conflicts unless ``autocommit`` is ``True``. If a conflict is detected, a ``ConfigurationConflictError`` will be raised. Calling :meth:`pyramid.config.Configurator.make_wsgi_app` always implies a final commit. If ``default_view_mapper`` is passed, it will be used as the default :term:`view mapper` factory for view configurations that don't otherwise specify one (see :class:`pyramid.interfaces.IViewMapperFactory`). If ``default_view_mapper`` is not passed, a superdefault view mapper will be used. If ``exceptionresponse_view`` is passed, it must be a :term:`view callable` or ``None``. If it is a view callable, it will be used as an exception view callable when an :term:`exception response` is raised. If ``exceptionresponse_view`` is ``None``, no exception response view will be registered, and all raised exception responses will be bubbled up to Pyramid's caller. By default, the ``pyramid.httpexceptions.default_exceptionresponse_view`` function is used as the ``exceptionresponse_view``. If ``route_prefix`` is passed, all routes added with :meth:`pyramid.config.Configurator.add_route` will have the specified path prepended to their pattern. If ``introspection`` is passed, it must be a boolean value. If it's ``True``, introspection values during actions will be kept for use for tools like the debug toolbar. If it's ``False``, introspection values provided by registrations will be ignored. By default, it is ``True``. .. versionadded:: 1.1 The ``exceptionresponse_view`` argument. .. versionadded:: 1.2 The ``route_prefix`` argument. .. versionadded:: 1.3 The ``introspection`` argument. .. versionadded:: 1.6 The ``root_package`` argument. The ``response_factory`` argument. .. versionadded:: 1.9 The ability to use the configurator as a context manager with the ``with``-statement to make threadlocal configuration available for further configuration with an implicit commit. .. py:method:: route_prefix_context(route_prefix) Copy of the original configurator, with tweak for leaving the leading ``/`` of the supplied ``route_prefix``. .. fixme: .. todo:: Workaround for https://github.com/Pylons/pyramid/issues/3758 .. py:class:: NoAutoHeadList List that does not allow addition of HTTP HEAD method object references unless allowed once. Initialize self. See help(type(self)) for accurate signature. .. py:attribute:: allow_once :value: False .. py:method:: append(__object: Union[str, Tuple[str, Any, Any]]) -> None Append object to the end of the list. .. py:class:: ServiceAutoAcceptDecorator(name, path=None, description=None, cors_policy=None, depth=1, pyramid_route=None, **kw) Extends the view :meth:`decorator` to allow multiple ``accept`` headers provided all at once. The base :class:`CorniceService` only allows a single ``accept`` header value, which forces repeating the entire parameters over multiple separate decorator calls. .. py:method:: decorator(method: weaver.typedefs.RequestMethod, accept: Optional[str, Sequence[str]] = None, **kwargs: Any) -> Callable[[weaver.typedefs.AnyViewCallable], weaver.typedefs.AnyViewCallable] Add the ability to define methods using python's decorators syntax. For instance, it is possible to do this with this method:: service = Service("blah", "/blah") @service.decorator("get", accept="application/json") def my_view(request): pass .. py:class:: ServiceOnlyExplicitGetHead(*_: Any, **__: Any) Service that disallow the auto-insertion of HTTP HEAD method view when HTTP GET view is defined. This service overrides the default :class:`cornice.Service` in order to avoid auto-insertion of HTTP HEAD view. Similarly to :mod:`pyramid`, the view registration assume that HEAD are always wanted when adding GET definitions. Because HEAD view can be added explicitly, the class also detects these cases to let them pass as expected. Without this patch, all endpoint would otherwise report erroneous HEAD requests in the generated OpenAPI specification once HEAD is removed from :attr:`cornice_swagger.CorniceSwagger.ignore_methods`. .. seealso:: - HEAD method removed from ignored methods in :func:`weaver.wps_restapi.api.get_openapi_json`. - HEAD method auto-insertion disabled for :mod:`pyramid` in :func:`patch_pyramid_view_no_auto_head_get_method`. .. py:attribute:: defined_methods .. py:attribute:: definitions .. py:method:: add_view(method: Union[str, Tuple[str]], view: Any, **kwargs: Any) -> None Add a view to a method and arguments. All the :class:`Service` keyword params except `name` and `path` can be overwritten here. Additionally, :meth:`~cornice.service.Service.api` has following keyword params: :param method: The request method. Should be one of 'GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'TRACE', or 'CONNECT'. :param view: the view to hook to :param **kwargs: additional configuration for this view, including `permission`. .. py:class:: WeaverService(name, path=None, description=None, cors_policy=None, depth=1, pyramid_route=None, **kw) Service that combines all respective capabilities required by :mod:`weaver`. .. py:class:: RequestMethodPredicateNoGetHead(val: Union[str, Tuple[str]], config: Configurator) .. py:attribute:: val .. py:function:: patch_pyramid_view_no_auto_head_get_method(config: Configurator) -> None Replace predicate handlers automatically adding HTTP HEAD route/view when HTTP GET are defined by ones that doesn't.