U
    ,ò¿W)  ã                   @   s¶   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	l
mZ dd
l
mZ ddlmZ dZG dd„ deƒZdd„ Zddd„Zdd„ Zdd„ ZdS )z5zope.security support for the configuration handlers
é    )Ú
providedBy)Ú	ProxyBase)ÚgetProxiedObject)ÚLocatingTrustedAdapterFactory)ÚLocatingUntrustedAdapterFactory)ÚTrustedAdapterFactory)ÚChecker)ÚCheckerPublic)ÚInterfaceChecker)ÚProxyzzope.Publicc                   @   s    e Zd ZdZdd„ ZeeƒZdS )ÚPermissionProxy)Ú__Security_checker__c                 C   s   t t| ƒƒS ©N)r   r   )Úself© r   ú9/usr/lib/python3/dist-packages/zope/component/security.pyÚ__providedBy__"   s    zPermissionProxy.__providedBy__N)Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r   Úpropertyr   r   r   r   r      s   r   c                 C   sh   |s|sdg}|t krt}i }|r4|D ]}|||< q&|r\|D ]}|jddD ]}|||< qLq<t|ƒ}|S )NÚ__call__T)Úall)ÚPublicPermissionr	   Únamesr   )Z_contextÚ
permissionZallowed_interfaceZallowed_attributesZrequireÚnameÚiÚcheckerr   r   r   Ú_checker&   s    
r    Nc                 C   sH   |dkr6|dks|dkr t dƒ‚|tkr,t}t||ƒ}t| ƒ} || _| S )zˆTry to get the object proxied with the `checker`, but not too soon

    We really don't want to proxy the object unless we need to.
    Nz<Required arguments: checker or both provides and permissions)Ú
ValueErrorr   r	   r
   r   r   )Úobr   Úprovidesr   r   r   r   Úproxify9   s    
r$   c                    s.   |t krt}t||ƒ‰ ‡ ‡fdd„}ˆ|_|S )Nc                     s6   ˆ| Ž }z
ˆ |_ W n tk
r0   t|ˆ ƒ}Y nX |S r   )r   ÚAttributeErrorr   )Úargsr"   ©r   Úoriginal_factoryr   r   ÚfactoryO   s    
z!protectedFactory.<locals>.factory)r   r	   r
   r)   )r(   r#   r   r)   r   r'   r   ÚprotectedFactoryJ   s    
r*   c                 C   sJ   |t krt}|s |d k	r6|tk	r6|r,t| ƒS t| ƒS n|rBt| ƒS | S d S r   )r   r	   r   r   r   )r)   r   ZlocateZtrustedr   r   r   ÚsecurityAdapterFactoryY   s    
r+   )NNN)Ú__doc__Zzope.interfacer   Z
zope.proxyr   r   Zzope.security.adapterr   r   r   Zzope.security.checkerr   r	   r
   Zzope.security.proxyr   r   r   r    r$   r*   r+   r   r   r   r   Ú<module>   s    
