B
    `A$                 @   s   d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZmZ G dd dZeeG d	d
 d
ZdS )    )implementer)action_method)IDefaultRootFactoryIExecutionPolicyIRequestExtensionsIRequestFactoryIResponseFactoryIRootFactoryISessionFactory)default_execution_policy)DefaultRootFactory)InstancePropertyHelperget_callable_namec               @   sZ   e Zd Zedd ZeZedd Zedd Zedd ZedddZ	edd Z
d	S )FactoriesConfiguratorMixinc                sX       dkrt  fdd}dd d} |d< jt||fd dS )ae  Add a :term:`root factory` to the current configuration
        state.  If the ``factory`` argument is ``None`` a default root
        factory will be registered.

        .. note::

           Using the ``root_factory`` argument to the
           :class:`pyramid.config.Configurator` constructor can be used to
           achieve the same purpose.
        Nc                  s    j  t j  t d S )N)registryregisterUtilityr	   r    )factoryselfr   `/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/pyramid/config/factories.pyregister#   s    z=FactoriesConfiguratorMixin.set_root_factory.<locals>.registerzroot factorieszroot factoryr   )introspectables)maybe_dottedr   introspectableobject_descriptionactionr	   )r   r   r   intrr   )r   r   r   set_root_factory   s    
z+FactoriesConfiguratorMixin.set_root_factoryc                sL       fdd}dd d} |d< jt||fd dS )a  
        Configure the application with a :term:`session factory`.  If this
        method is called, the ``factory`` argument must be a session
        factory callable or a :term:`dotted Python name` to that factory.

        .. note::

           Using the ``session_factory`` argument to the
           :class:`pyramid.config.Configurator` constructor can be used to
           achieve the same purpose.
        c                  s   j  t d S )N)r   r   r
   r   )r   r   r   r   r   A   s    z@FactoriesConfiguratorMixin.set_session_factory.<locals>.registerzsession factoryNr   )r   )r   r   r   r   r
   )r   r   r   r   r   )r   r   r   set_session_factory2   s    
z.FactoriesConfiguratorMixin.set_session_factoryc                sL       fdd}dd d} |d< jt||fd dS )a  The object passed as ``factory`` should be an object (or a
        :term:`dotted Python name` which refers to an object) which
        will be used by the :app:`Pyramid` router to create all
        request objects.  This factory object must have the same
        methods and attributes as the
        :class:`pyramid.request.Request` class (particularly
        ``__call__``, and ``blank``).

        See :meth:`pyramid.config.Configurator.add_request_method`
        for a less intrusive way to extend the request objects with
        custom methods and properties.

        .. note::

           Using the ``request_factory`` argument to the
           :class:`pyramid.config.Configurator` constructor
           can be used to achieve the same purpose.
        c                  s   j  t d S )N)r   r   r   r   )r   r   r   r   r   c   s    z@FactoriesConfiguratorMixin.set_request_factory.<locals>.registerzrequest factoryNr   )r   )r   r   r   r   r   )r   r   r   r   r   )r   r   r   set_request_factoryM   s    
z.FactoriesConfiguratorMixin.set_request_factoryc                sL       fdd}dd d} |d< jt||fd dS )a  The object passed as ``factory`` should be an object (or a
        :term:`dotted Python name` which refers to an object) which
        will be used by the :app:`Pyramid` as the default response
        objects. The factory should conform to the
        :class:`pyramid.interfaces.IResponseFactory` interface.

        .. note::

           Using the ``response_factory`` argument to the
           :class:`pyramid.config.Configurator` constructor
           can be used to achieve the same purpose.
        c                  s   j  t d S )N)r   r   r   r   )r   r   r   r   r      s    zAFactoriesConfiguratorMixin.set_response_factory.<locals>.registerzresponse factoryNr   )r   )r   r   r   r   r   )r   r   r   r   r   )r   r   r   set_response_factoryo   s    
z/FactoriesConfiguratorMixin.set_response_factoryNFc                s
   dk	r   p|r4tj |d\ ndkrD jnt fdd} dkrxdfd nrd d} |d< d|d	< ||d
< jdf||fd nDd d} |d< d|d	< d|d
< jdf||fd dS )a  Add a property or method to the request object.

        When adding a method to the request, ``callable`` may be any
        function that receives the request object as the first
        parameter. If ``name`` is ``None`` then it will be computed
        from the name of the ``callable``.

        When adding a property to the request, ``callable`` can either
        be a callable that accepts the request as its single positional
        parameter, or it can be a property descriptor. If ``callable`` is
        a property descriptor, it has to be an instance of a class which is
        a subclass of ``property``. If ``name`` is ``None``, the name of
        the property will be computed from the name of the ``callable``.

        If the ``callable`` is a property descriptor a ``ValueError``
        will be raised if ``name`` is ``None`` or ``reify`` is ``True``.

        See :meth:`pyramid.request.Request.set_property` for more
        details on ``property`` vs ``reify``. When ``reify`` is
        ``True``, the value of ``property`` is assumed to also be
        ``True``.

        In all cases, ``callable`` may also be a
        :term:`dotted Python name` which refers to either a callable or
        a property descriptor.

        If ``callable`` is ``None`` then the method is only used to
        assist in conflict detection between different addons requesting
        the same attribute on the request object.

        This is the recommended method for extending the request object
        and should be used in favor of providing a custom request
        factory via
        :meth:`pyramid.config.Configurator.set_request_factory`.

        .. versionadded:: 1.4
        N)namereifyc                 sD   j t} | d kr(t } j | t r2| jn| j} |< d S )N)r   ZqueryUtilityr   _RequestExtensionsr   descriptorsmethods)extsplist)callabler!   propertyr   r   r   r      s    z?FactoriesConfiguratorMixin.add_request_method.<locals>.registerzrequest extensionszrequest propertyr(   Tr)   r"   )r   zrequest methodF)r   r   Zmake_property__name__r   r   r   r   )r   r(   r!   r)   r"   r   r   r   )r(   r!   r)   r   r   add_request_method   sB    )

z-FactoriesConfiguratorMixin.add_request_methodc                sX       dkrt  fdd}dd d} |d< jt||fd dS )a8  
        Override the :app:`Pyramid` :term:`execution policy` in the
        current configuration.  The ``policy`` argument must be an instance
        of an :class:`pyramid.interfaces.IExecutionPolicy` or a
        :term:`dotted Python name` that points at an instance of an
        execution policy.

        Nc                  s   j  t d S )N)r   r   r   r   )policyr   r   r   r      s    zAFactoriesConfiguratorMixin.set_execution_policy.<locals>.registerzexecution policyr,   )r   )r   r   r   r   r   r   )r   r,   r   r   r   )r,   r   r   set_execution_policy   s    

z/FactoriesConfiguratorMixin.set_execution_policy)NNFF)r*   
__module____qualname__r   r   Z_set_root_factoryr   r   r    r+   r-   r   r   r   r   r      s   "[r   c               @   s   e Zd Zdd ZdS )r#   c             C   s   i | _ i | _d S )N)r$   r%   )r   r   r   r   __init__  s    z_RequestExtensions.__init__N)r*   r.   r/   r0   r   r   r   r   r#     s   r#   N)Zzope.interfacer   Zpyramid.config.actionsr   Zpyramid.interfacesr   r   r   r   r   r	   r
   Zpyramid.routerr   Zpyramid.traversalr   Zpyramid.utilr   r   r   r#   r   r   r   r   <module>   s   $	 r