o
    $x`!                     @   s   d Z g dZG dd deZG dd deZG dd deZG dd	 d	eZG d
d deZG dd deZG dd deZ	G dd de
ZdS )zInterface-specific exceptions
)InvalidDoesNotImplementBrokenImplementationBrokenMethodImplementationMultipleInvalidBadImplementsInvalidInterfacec                   @      e Zd ZdZdS )r   z A specification is violated
    N__name__
__module____qualname____doc__ r   r   ;/usr/lib/python3/dist-packages/zope/interface/exceptions.pyr          r   c                   @   sj   e Zd ZdZdZeZdZdddZe	dd Z
e	d	d
 Ze	dd Ze	dd ZdZdZdZdd ZdS )_TargetInvalid       z<Not Given>Nc                 C   s&   z| j | W S  | jy   | Y S w N)args_NOT_GIVEN_CATCH)selfixdefaultr   r   r   _get_arg_or_default8   s
   z"_TargetInvalid._get_arg_or_defaultc                 C   s   |  | jS r   )r   _IX_INTERFACEr   r   r   r   	interface>   s   z_TargetInvalid.interfacec                 C   s   |  | j| jS r   )r   
_IX_TARGET
_NOT_GIVENr   r   r   r   targetB   s   z_TargetInvalid.targetc                 C   s   | j }|| ju r
dS d|f S )Nz	An objectzThe object %r)r    r   )r   r    r   r   r   _str_subjectZ   s   

z_TargetInvalid._str_subjectc                 C   s   d| j pd S )Nz$has failed to implement interface %sz	<Unknown>)r   r   r   r   r   _str_descriptiona   s   z_TargetInvalid._str_descriptionz: z	<unknown>.c                 C   s   d| j | j| j| j| jf S )Nz%s %s%s%s%s)r!   r"   _str_conjunction_str_details_str_trailerr   r   r   r   __str__k   s   z_TargetInvalid.__str__r   )r
   r   r   r   r   
IndexErrorr   r   r   propertyr   r    r!   r"   r$   r%   r&   r'   r   r   r   r   r   "   s$    




r   c                   @   s   e Zd ZdZdZdS )r   a  
    DoesNotImplement(interface[, target])

    The *target* (optional) does not implement the *interface*.

    .. versionchanged:: 5.0.0
       Add the *target* argument and attribute, and change the resulting
       string value of this object accordingly.
    z.Does not declaratively implement the interfaceN)r
   r   r   r   r%   r   r   r   r   r   u   s    
r   c                   @   s:   e Zd ZdZejd Zed Zedd Z	edd Z
dS )r   a[  
    BrokenImplementation(interface, name[, target])

    The *target* (optional) is missing the attribute *name*.

    .. versionchanged:: 5.0.0
       Add the *target* argument and attribute, and change the resulting
       string value of this object accordingly.

       The *name* can either be a simple string or a ``Attribute`` object.
    r   c                 C   
   | j d S Nr   r   r   r   r   r   name      
zBrokenImplementation.namec                 C   s"   dt | jtrt| j S | j S )Nz!The %s attribute was not provided)
isinstancer-   strreprr   r   r   r   r%      s
   z!BrokenImplementation._str_detailsN)r
   r   r   r   r   r   _IX_NAMEr   r)   r-   r%   r   r   r   r   r      s    

r   c                   @   sT   e Zd ZdZdZed Zed Zedd Zedd Z	e
dd	 Zed
d ZdS )r   a  
    BrokenMethodImplementation(method, message[, implementation, interface, target])

    The *target* (optional) has a *method* in *implementation* that violates
    its contract in a way described by *mess*.

    .. versionchanged:: 5.0.0
       Add the *interface* and *target* argument and attribute,
       and change the resulting string value of this object accordingly.

       The *method* can either be a simple string or a ``Method`` object.

    .. versionchanged:: 5.0.0
       If *implementation* is given, then the *message* will have the
       string "implementation" replaced with an short but informative
       representation of *implementation*.

       r   c                 C   r*   )Nr   r,   r   r   r   r   method   r.   z!BrokenMethodImplementation.methodc                 C   r*   r+   r,   r   r   r   r   mess   r.   zBrokenMethodImplementation.messc              	      s   dd l }z|j}t}W n ty    |j}|j  fdd}Y nw z|| }W n ttfy6   t|  Y S w z| j	}W n tyH   | j
}Y nw ||| S )Nr   c                    s    |  S r   r   )sigfr   r   <lambda>   s    zABrokenMethodImplementation.__implementation_str.<locals>.<lambda>)inspect	signaturer0   AttributeError
getargspecformatargspec
ValueError	TypeErrorr1   r   r
   )implr:   r6   	formatsigr-   r   r7   r   __implementation_str   s(   

z/BrokenMethodImplementation.__implementation_strc                 C   sn   |  | j| j}| j}|| jur"d|v r"|dd}|| |f }dt| jtr1t	| j|f S | j|f S )Nimplementationz%rz)The contract of %s is violated because %s)
r   _IX_IMPLr   r5   replace/_BrokenMethodImplementation__implementation_strr/   r4   r0   r1   )r   rA   messager   r   r   r%      s   z'BrokenMethodImplementation._str_detailsN)r
   r   r   r   rE   r   r   r)   r4   r5   staticmethodrG   r%   r   r   r   r   r      s    


r   c                       sD   e Zd ZdZdZ fddZedd Zedd Zd	Z	d
Z
  ZS )r   z
    The *target* has failed to implement the *interface* in
    multiple ways.

    The failures are described by *exceptions*, a collection of
    other `Invalid` instances.

    .. versionadded:: 5.0
    r   c                    s   t t| ||t| d S r   )superr   __init__tuple)r   r   r    
exceptions	__class__r   r   rK      s   zMultipleInvalid.__init__c                 C   r*   )Nr3   r,   r   r   r   r   rM      r.   zMultipleInvalid.exceptionsc                 C   s   dd dd | jD  S )Nz
    c                 s   s,    | ]}t |tr|j nt|V  qd S r   )r/   r   r%   stripr0   ).0xr   r   r   	<genexpr>  s
    
z/MultipleInvalid._str_details.<locals>.<genexpr>)joinrM   r   r   r   r   r%      s   
zMultipleInvalid._str_details: )r
   r   r   r   r   rK   r)   rM   r%   r$   r&   __classcell__r   r   rN   r   r      s    


r   c                   @   r   )r   z'The interface has invalid contents
    Nr	   r   r   r   r   r   
  r   r   c                   @   r   )r   zAn implementation assertion is invalid

    because it doesn't contain an interface or a sequence of valid
    implementation assertions.
    Nr	   r   r   r   r   r     r   r   N)r   __all__	Exceptionr   r   r   r   r   r   r   r@   r   r   r   r   r   <module>   s   SK!