U
    ,WO                     @   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dlmZ ddlmZ ddlmZmZ ddlmZ ddlmZ zddlmZ W n0 ek
r   dd Ze Z Z Z Z!eZY n2X ddl"mZ ddl"mZ ddl"m Z  ddl"m#Z# e
dZ$G dd de%eZ&dd Z'G dd deZ(G dd  d eZ)d!d" Z*d@d&d'Z+G d(d) d)eZ,e'Z-dAd*d+Z.G d,d- d-e(Z/dBd.d/Z0G d0d1 d1eZ1dCd2d3Z2G d4d5 d5eZ3G d6d7 d7eZ4G d8d9 d9e3e4Z5d#d#d#efd:d;Z6G d<d= d=e(e4Z7d#d#d#efd>d?Z8d#S )Dz.Component Architecture configuration handlers
    ConfigurationError)Bool)GlobalInterface)GlobalObject)PythonIdentifier)Tokens)MessageFactory)	Interface)implementedBy)
providedBy)TextLine)getSiteManager)	adaptedBygetName)provideInterface)_BLANK)
Permissionc                  O   s   t dd S )NzTsecurity proxied components are not supported because zope.security is not availabler   )argskw r   5/usr/lib/python3/dist-packages/zope/component/zcml.py_no_security$   s    r   )_checkerproxify)protectedFactory)securityAdapterFactoryzopec                   @   s   e Zd ZdS )ComponentConfigurationErrorN)__name__
__module____qualname__r   r   r   r   r   1   s   r   c                 O   s   t t | }||| d S N)getattrr   )Z
methodNamer   kwargsmethodr   r   r   handler4   s    r'   c                   @   sN   e Zd ZeededddZeededddZeededddZd	S )
IBasicComponentInformationzComponent to usezPython name of the implementation object.  This must identify an object in a module using the full dotted name.  If specified, the ``factory`` field must be left blank.Ftitledescriptionrequiredr   z*Permission required to use this component.FactoryzPython name of a factory which can create the implementation object.  This must identify an object in a module using the full dotted name. If specified, the ``component`` field must be left blank.N)	r    r!   r"   r   _	componentr   
permissionfactoryr   r   r   r   r(   8   s   	r(   c                   @   s   e Zd ZdZeededde dZeededdd	Z	eed
eddee
 ddZeededdd	Zeededdd	ZeededdddZeededdddZdS )IAdapterDirectivez
    Register an adapter
    zAdapter factory/factorieszHA list of factories (usually just one) that create the adapter instance.Tr*   r+   r,   
value_type Interface the component providesIThis attribute specifies the interface the adapter instance must provide.Fr)   zSpecifications to be adapted.This should be a list of interfaces or classesZmissing_valuer   zEThis adapter is only available, if the principal has this permission.NamezYAdapters can have names.

This attribute allows you to specify the name for this adapter.TrustedaI  Make the adapter a trusted adapter

        Trusted adapters have unfettered access to the objects they
        adapt.  If asked to adapt security-proxied objects, then,
        rather than getting an unproxied adapter of security-proxied
        objects, you get a security-proxied adapter of unproxied
        objects.
        r*   r+   r,   defaultLocatezMake the adapter a locatable adapter

        Located adapter should be used if a non-public permission
        is used.
        N)r    r!   r"   __doc__r   r.   r   r1   r   providesobjectfor_r   r0   r   namer   trustedlocater   r   r   r   r2   S   sT   	r2   c                    s    fdd} d |_ |S )Nc                    s    D ]}|| } q| S r#   r   )obf	factoriesr   r   r1      s    
z!_rolledUpFactory.<locals>.factoryr   r1   )rH   r1   r   rG   r   _rolledUpFactory   s    
rJ   N Fc              	   C   s  |d kr0t |dkr t|d }|d kr0tdt|}|d krt |dkrptt|d }t |dkrp|d }|d krtd|dkrt |dkrt|d }|}	t |	dkr|	d }n@t |	dk rtdn*t |	dkrt |dkrtdnt|	}|d k	rt	|||}|s&|d k	s&|r4t
||||}| jd|||ftd	||||| jfd
 | jd td|fd
 |r|D ]$}
|
d k	rx| jd td|
fd
 qxd S )N   r   zJNo for attribute was provided and can't determine what the factory adapts.Missing 'provides' attributerK   zNo factory specified-Can't use multiple factories and multiple foradapterregisterAdapterdiscriminatorcallabler   )lenr   	TypeErrortuplelistr   r   r   rJ   r   r   actionr'   infor   )_contextr1   r?   rA   r0   rB   rC   rD   prH   ifacer   r   r   rO      sl    



    
rO   c                   @   s   e Zd ZdZeededddZeededddZeeded	ddZ	e
ed
eddee ddZeededddZeededdddZeededdddZdS )ISubscriberDirectivez
    Register a subscriber
    zSubscriber factoryz1A factory used to create the subscriber instance.Fr)   ZHandlerz&A callable object that handles events.r5   r6   z5Interfaces or classes that this subscriber depends onr7   r8   r3   r   zHThis subscriber is only available, if the principal has this permission.r:   aX  Make the subscriber a trusted subscriber

        Trusted subscribers have unfettered access to the objects they
        adapt.  If asked to adapt security-proxied objects, then,
        rather than getting an unproxied subscriber of security-proxied
        objects, you get a security-proxied subscriber of unproxied
        objects.
        r;   r=   zMake the subscriber a locatable subscriber

        Located subscribers should be used if a non-public permission
        is used.
        N)r    r!   r"   r>   r   r.   r1   r'   r   r?   r   r@   rA   r   r0   r   rC   rD   r   r   r   r   r]      sR   	r]   c           	   	   C   s8  |d kr.|d krt d|d k	r(t d|}n |d k	r>t d|d krNt d|d krnt|}|d krnt d|d k	rt|||}t|}|s|d k	s|rt||||}|d k	r| jd td||t| jfd n| jd td|||t| jfd |d k	r
| jd t	d	|fd |D ]$}|d k	r| jd t	d	|fd qd S )
NzNo factory or handler providedz Cannot use handler with provideszCannot use handler with factoryz@You must specify a provided interface when registering a factoryzWNo for attribute was provided and can't determine what the factory (or handler) adapts.ZregisterHandlerrQ   ZregisterSubscriptionAdapterrK   )
rU   r   r   rV   r   rX   _handlerr   rY   r   )	rZ   rA   r1   r'   r?   r0   rC   rD   r\   r   r   r   
subscriber&  sp           

r_   c                   @   s<   e Zd ZdZeededddZeededddZdS )	IUtilityDirectivezRegister a utility.zProvided interfacez"Interface provided by the utility.Fr)   r9   zTName of the registration.  This is used by application code when locating a utility.N)	r    r!   r"   r>   r   r.   r?   r   rB   r   r   r   r   r`   d  s   r`   c                 C   s   |r|rt d|d krT|r*tt|}ntt|}t|dkrL|d }nt d|dkrr|rjt|}nt|}|d k	rt|||d}| jd||ftd|||| j	ft
|d	d
 | jd td|fd d S )Nz$Can't specify factory and component.rL   r   rM   rK   )r?   r0   utilityZregisterUtilityrI   )rR   rS   r   r   rQ   )rU   rW   r   r   rT   r   r   rX   r'   rY   dictr   )rZ   r?   r/   r1   r0   rB   r   r   r   ra   t  s4    

ra   c                   @   s@   e Zd ZdZeedddZeedddZeedddZ	dS )	IInterfaceDirectivez
    Define an interface
    r
   Tr*   r,   zInterface typeFr9   N)
r    r!   r"   r>   r   r.   	interfacetyper   rB   r   r   r   r   rc     s   rc   c                 C   s   | j d t|||fd d S )NrQ   )rX   r   )rZ   re   rf   rB   r   r   r   re     s
    re   c                   @   s   e Zd ZdZeededdee ddZe	ededd	d
Z
eededd	d
Zeededd	e dZeededd	e dZdS )IBasicViewInformationz,This is the basic information for all views.z*Specifications of the objects to be viewedz7This should be a list of interfaces or classes
        Tr8   r3   r   z&The permission needed to use the view.Fr)   ZClassz2A class that provides attributes used by the view.6Interface that is also allowed if user has permission.a=  
        By default, 'permission' only applies to viewing the view and
        any possible sub views. By specifying this attribute, you can
        make the permission also apply to everything described in the
        supplied interface.

        Multiple interfaces can be provided, separated by
        whitespace.zAView attributes that are also allowed if the user has permission.z
        By default, 'permission' only applies to viewing the view and
        any possible sub views. By specifying 'allowed_attributes',
        you can make the permission also apply to the extra attributes
        on the view object.N)r    r!   r"   r>   r   r.   r   r@   rA   r   r0   Zclass_r   allowed_interfacer   allowed_attributesr   r   r   r   rg     s>   
rg   c                   @   sP   e Zd ZdZeededdedZeededde	dZ
eed	dd
ZdS )IBasicResourceInformationz)
    Basic information for resources
    zThe name of the resource.z3The name shows up in URLs/paths. For example 'foo'.Tr;   z&The interface this component provides.zi
        A view can provide an interface.  This would be used for
        views that support other views.FzRequest typerd   N)r    r!   r"   r>   r   r.   r   rB   r   r
   r?   rf   r   r   r   r   rk     s"   	rk   c                   @   s$   e Zd ZdZeedde dZdS )IViewDirectivezRegister a view for a componentr-   Fr*   r,   r4   N)r    r!   r"   r>   r   r.   r   r1   r   r   r   r   rl     s   rl   c	              	      sD  |s|r|st d|d k	rLt| |||}	G dd dt}
|
|d |	|d< |sXt dt|}| t dkrz d }nNt dk rt dn8t dkrt|dkrt d	n fd
d} d |_||f }| jd|||ftd||||| jfd | jd t	d|fd |d k	r@|D ]$}|d k	r| jd t	d|fd qd S )NzF'permission' required with 'allowed_interface' or 'allowed_attributes'c                   @   s    e Zd ZdZdd Zdd ZdS )zview.<locals>.ProxyViewz#Class to create simple proxy views.c                 S   s   || _ || _d S r#   )r1   checker)selfr1   rn   r   r   r   __init__  s    z view.<locals>.ProxyView.__init__c                 W   s   t | j| | jS r#   )r   r1   rn   )ro   Zobjectsr   r   r   __call__#  s    z view.<locals>.ProxyView.__call__N)r    r!   r"   r>   rp   rq   r   r   r   r   	ProxyView  s   rr   zNo for interfaces specifiedrL   r   zNo view factory specifiedrN   c                    s(    d d D ]}|| } q d | |S )Nrs   r   )rE   requestrF   rG   r   r   r1   7  s    
zview.<locals>.factoryviewrP   rQ   rK   )
r   r   r@   rV   rT   r1   rX   r'   rY   r   )rZ   r1   rf   rB   rA   r0   ri   rj   r?   rn   rr   r\   r   rG   r   ru   
  sh     





    

ru   c                   @   s8   e Zd ZdZeedde dZeedde dZ	dS )IResourceDirectivezRegister a resourcerh   Frm   z=View attributes that are also allowed if user has permission.N)
r    r!   r"   r>   r   r.   r   ri   r   rj   r   r   r   r   rv   V  s   rv   c           
   	   C   s   |s|r|st d|d k	rBt| |||}||fdd}	||	_|	}| jd|||ftd||f||| jfd | jd td|fd | jd td|fd d S )NzDMust use name attribute with allowed_interface or allowed_attributesc                 S   s   t || |S r#   r   )rt   r1   rn   r   r   r   proxyResourcex  s    zresource.<locals>.proxyResourceresourcerP   rQ   rK   )r   r   r1   rX   r'   rY   r   )
rZ   r1   rf   rB   r0   ri   rj   r?   rn   rw   r   r   r   rx   g  sF     
    rx   )NNNrK   FF)NNNNNFF)NNNNrK   )NrK   )9r>   Zzope.configuration.exceptionsr   Zzope.configuration.fieldsr   r   r   r   r   Zzope.i18nmessageidr	   Zzope.interfacer
   r   r   Zzope.schemar   Zzope.component._apir   Zzope.component._declarationr   r   Zzope.component.interfacer   Zzope.component._compatr   Zzope.security.zcmlr   ImportErrorr   r   r   r   ZsecurityZzope.component.securityr   r.   
ValueErrorr   r'   r(   r2   rJ   rO   r]   r^   r_   r`   ra   rc   re   rg   rk   rl   ru   rv   rx   r   r   r   r   <module>   s   
E      
AA      
>    
$
3

L 