U
    ÌZjÂO  ã                   @   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   úV/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/zope/component/zcml.pyÚ_no_security$   s    r   )Ú_checker©Úproxify)ÚprotectedFactory)ÚsecurityAdapterFactoryZ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   )Ú
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 usez¨Python 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.ÚFactoryzÄPython 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 providesúIThis 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ÚLocatez�Make 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r€t |ƒdkrptt|d ƒƒ}t |ƒdkrp|d }|d kr€tdƒ‚|dkr t |ƒdkr t|d ƒ}|}	t |	ƒdkrº|	d }n@t |	ƒdk rÐtdƒ‚n*t |	ƒdkròt |ƒdkròt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)   Ú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=   z‹Make 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	r‚t|||ƒ}t|ƒ}|sš|d k	sš|r¨t||||ƒ}|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   ra   d  s   ýüra   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	rˆt|||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   rb   t  s4    

üýrb   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   rd   ˜  s   þþþrd   c                 C   s   | j d t|||fd� d S )NrQ   )rX   r   )rZ   rf   rg   rB   r   r   r   rf   ¬  s
    ýrf   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)   Ú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   Úclass_r   Úallowed_interfacer   Úallowed_attributesr   r   r   r   rh   ³  s>   ÿû
ýýõ÷rh   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 typere   N)r   r    r!   r>   r   r.   r   rB   r   r
   r?   rg   r   r   r   r   rn   æ  s"   üú	þrn   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   ro     s   ýro   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 r�t dƒ‚n8tˆ ƒdkr²t|ƒdkr²t 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   rq   r   r   r   Ú__init__  s    z view.<locals>.ProxyView.__init__c                 W   s   t | j|Ž | jƒS r"   )r   r1   rq   )rr   Úobjectsr   r   r   Ú__call__#  s    z view.<locals>.ProxyView.__call__N)r   r    r!   r>   rs   ru   r   r   r   r   Ú	ProxyView  s   rv   éÿÿÿÿzNo for interfaces specifiedrL   r   zNo view factory specifiedrN   c                    s(   ˆ d d… D ]}|| ƒ} qˆ d | |ƒS )Nrw   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   rg   rB   rA   r0   rl   rm   r?   rq   rv   r\   r   rG   r   ry   
  sh    ÿÿ ÿ


ÿ


    ÿýý

ýry   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 resourcerj   Frp   z=View attributes that are also allowed if user has permission.N)
r   r    r!   r>   r   r.   r   rl   r   rm   r   r   r   r   rz   V  s   ýürz   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   )rx   r1   rq   r   r   r   ÚproxyResourcex  s    zresource.<locals>.proxyResourceÚresourcerP   rQ   rK   )r   r   r1   rX   r'   rY   r   )
rZ   r1   rg   rB   r0   rl   rm   r?   rq   r{   r   r   r   r|   g  sF    ÿÿ ÿ
    ÿýýýr|   )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   ÚsecurityZzope.component.securityr   r.   Ú
ValueErrorr   r'   r(   r2   rJ   rO   r]   r_   r`   ra   rb   rd   rf   rh   rn   ro   ry   rz   r|   r   r   r   r   Ú<module>   s„   
E      ÿ
AA      ÿ
>    ÿ
$
3
ü
Lÿ ý