B
    `               	   @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ e 	 4 e 
d d dlmZmZmZmZmZmZmZ W dQ R X eZeZeZeZG dd	 d	eZG d
d deZG dd deZe ZeeefZeeG dd dZG dd dZdS )    N)implementer)IAuthorizationPolicy)lineage)is_nonstr_iterignore)
ACLAllowed	ACLDeniedAllowAllPermissionsListAuthenticatedDenyEveryonec               @   s   e Zd ZdS )r
   N)__name__
__module____qualname__ r   r   ]/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/pyramid/authorization.pyr
   !   s   r
   c               @   s   e Zd ZdS )r   N)r   r   r   r   r   r   r   r   %   s   r   c               @   s   e Zd ZdS )r   N)r   r   r   r   r   r   r   r   )   s   r   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ACLAuthorizationPolicyaH  An :term:`authorization policy` which consults an :term:`ACL`
    object attached to a :term:`context` to determine authorization
    information about a :term:`principal` or multiple principals.
    This class is a wrapper around :class:`.ACLHelper`, refer to that class for
    more detailed documentation.

    Objects of this class implement the
    :class:`pyramid.interfaces.IAuthorizationPolicy` interface.

    .. deprecated:: 2.0

        Authorization policies have been deprecated by the new security system.
        See :ref:`upgrading_auth_20` for more information.

    c             C   s   t  | _d S )N)	ACLHelperhelper)selfr   r   r   __init__C   s    zACLAuthorizationPolicy.__init__c             C   s   | j |||S )zReturn an instance of
        :class:`pyramid.authorization.ACLAllowed` instance if the policy
        permits access, return an instance of
        :class:`pyramid.authorization.ACLDenied` if not.)r   permits)r   context
principals
permissionr   r   r   r   F   s    zACLAuthorizationPolicy.permitsc             C   s   | j ||S )zReturn the set of principals explicitly granted the
        permission named ``permission`` according to the ACL directly
        attached to the ``context`` as well as inherited ACLs based on
        the :term:`lineage`.)r    principals_allowed_by_permission)r   r   r   r   r   r   r   M   s    z7ACLAuthorizationPolicy.principals_allowed_by_permissionN)r   r   r   __doc__r   r   r   r   r   r   r   r   1   s   r   c               @   s    e Zd ZdZdd Zdd ZdS )r   aX  A helper for use with constructing a :term:`security policy` which
    consults an :term:`ACL` object attached to a :term:`context` to determine
    authorization information about a :term:`principal` or multiple principals.
    If the context is part of a :term:`lineage`, the context's parents are
    consulted for ACL information too.

    c       
   	   C   s   d}xt |D ]}y
|j}W n tk
r2   wY nX |rFt|rF| }x\|D ]T}|\}}}	||krLt|	sp|	g}	||	krL|tkrt|||||S t|||||S qLW qW td||||S )aG  Return an instance of :class:`pyramid.authorization.ACLAllowed` if
        the ACL allows access a user with the given principals, return an
        instance of :class:`pyramid.authorization.ACLDenied` if not.

        When checking if principals are allowed, the security policy consults
        the ``context`` for an ACL first.  If no ACL exists on the context, or
        one does exist but the ACL does not explicitly allow or deny access for
        any of the effective principals, consult the context's parent ACL, and
        so on, until the lineage is exhausted or we determine that the policy
        permits or denies.

        During this processing, if any :data:`pyramid.authorization.Deny`
        ACE is found matching any principal in ``principals``, stop
        processing by returning an
        :class:`pyramid.authorization.ACLDenied` instance (equals
        ``False``) immediately.  If any
        :data:`pyramid.authorization.Allow` ACE is found matching any
        principal, stop processing by returning an
        :class:`pyramid.authorization.ACLAllowed` instance (equals
        ``True``) immediately.  If we exhaust the context's
        :term:`lineage`, and no ACE has explicitly permitted or denied
        access, return an instance of
        :class:`pyramid.authorization.ACLDenied` (equals ``False``).

        z0<No ACL found on any object in resource lineage>z<default deny>)r   __acl__AttributeErrorcallabler   r	   r   r   )
r   r   r   r   acllocationZace
ace_actionace_principalace_permissionsr   r   r   r   `   s*    


zACLHelper.permitsc          	   C   s   t  }xttt|D ]}y
|j}W n tk
r<   wY nX t  }t  }|r\t|r\| }x|D ]x\}}	}
t|
sz|
g}
|tkr||
kr|	|kr|	|	 |t
krb||
krb|	|	 |	tkrt  }P qb|	|krb||	 qbW || qW |S )a,  Return the set of principals explicitly granted the permission
        named ``permission`` according to the ACL directly attached to the
        ``context`` as well as inherited ACLs based on the :term:`lineage`.

        When computing principals allowed by a permission, we compute the set
        of principals that are explicitly granted the ``permission`` in the
        provided ``context``.  We do this by walking 'up' the object graph
        *from the root* to the context.  During this walking process, if we
        find an explicit :data:`pyramid.authorization.Allow` ACE for a
        principal that matches the ``permission``, the principal is included in
        the allow list.  However, if later in the walking process that
        principal is mentioned in any :data:`pyramid.authorization.Deny` ACE
        for the permission, the principal is removed from the allow list.  If
        a :data:`pyramid.authorization.Deny` to the principal
        :data:`pyramid.authorization.Everyone` is encountered during the
        walking process that matches the ``permission``, the allow list is
        cleared for all principals encountered in previous ACLs.  The walking
        process ends after we've processed the any ACL directly attached to
        ``context``; a set of principals is returned.

        )setreversedlistr   r   r   r    r   r	   addr   r   removeupdate)r   r   r   allowedr"   r!   Zallowed_hereZdenied_herer#   r$   r%   r   r   r   r      s2    


z*ACLHelper.principals_allowed_by_permissionN)r   r   r   r   r   r   r   r   r   r   r   W   s   :r   )warningsZzope.interfacer   Zpyramid.interfacesr   Zpyramid.locationr   Zpyramid.utilr   catch_warningssimplefilterZpyramid.securityr   Z_ACLAllowedr   Z
_ACLDeniedr	   r
   Z_AllPermissionsListr   r   r   ZALL_PERMISSIONSZDENY_ALLr   r   r   r   r   r   <module>   s$   

.
&