U
    P|jv!  ã                   @   sš   d Z dddddddg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                   @   s   e Zd ZdZdS )r   z A specification is violated
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú=/tmp/pip-unpacked-wheel-zcalc2_b/zope/interface/exceptions.pyr      s   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k
r&   | Y S X d S ©N)ÚargsÚ_NOT_GIVEN_CATCH)ÚselfÚixÚdefaultr   r   r   Ú_get_arg_or_default9   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   ÚtargetC   s    z_TargetInvalid.targetc                 C   s   | j }|| jkrdS d|›�S )Nz	An objectzThe object )r   r   )r   r   r   r   r   Ú_str_subject[   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_descriptionb   s    ÿz_TargetInvalid._str_descriptionz: z	<unknown>Ú.c                 C   s   d  | j| j| j| j| j¡S )Nz{} {}{}{}{})Úformatr   r    Ú_str_conjunctionÚ_str_detailsÚ_str_trailerr   r   r   r   Ú__str__l   s    ûz_TargetInvalid.__str__)N)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   v   s   
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   s
   | j d S ©Nr   ©r   r   r   r   r   Úname”   s    zBrokenImplementation.namec                 C   s    dt | jtƒrt| jƒn| 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   Z_IX_NAMEr   r(   r+   r$   r   r   r   r   r   „   s   

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   s
   | j d S ©Nr   r*   r   r   r   r   Úmethod¹   s    z!BrokenMethodImplementation.methodc                 C   s
   | j d S r)   r*   r   r   r   r   Úmess½   s    zBrokenMethodImplementation.messc              	   C   s˜   dd l }z|j}t}W n  tk
r6   |j}|j}Y nX z|| ƒ}W n  ttfk
rd   t| ƒ Y S X z
| j	}W n tk
rŠ   | j
}Y nX |||ƒ S r0   )ÚinspectÚ	signaturer-   ÚAttributeErrorÚ
getargspecÚformatargspecÚ
ValueErrorÚ	TypeErrorr.   r   r	   )Úimplr3   ÚsigZ	formatsigr+   r   r   r   Z__implementation_strÁ   s     
z/BrokenMethodImplementation.__implementation_strc                 C   sh   |   | j| j¡}| j}|| jk	rDd|krD| dd¡}||  |¡f }d t| jt	ƒr^t
| jƒn| j|¡S )NÚimplementationz%rz)The contract of {} is violated because {})r   Ú_IX_IMPLr   r2   ÚreplaceÚ/_BrokenMethodImplementation__implementation_strr"   r,   r1   r-   r.   )r   r:   Úmessager   r   r   r$   Ý   s    þz'BrokenMethodImplementation._str_detailsN)r	   r
   r   r   r=   r   r   r(   r1   r2   Ústaticmethodr?   r$   r   r   r   r   r   Ÿ   s   


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|ƒ¡ d S r   )ÚsuperÚ__init__Útuple)r   r   r   Ú
exceptions©Ú	__class__r   r   rC   ø   s    zMultipleInvalid.__init__c                 C   s
   | j d S )Nr/   r*   r   r   r   r   rE   û   s    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$   Ústripr-   )Ú.0Úxr   r   r   Ú	<genexpr>  s   ÿz/MultipleInvalid._str_details.<locals>.<genexpr>)ÚjoinrE   r   r   r   r   r$   ÿ   s    þzMultipleInvalid._str_detailsú:Ú )r	   r
   r   r   r   rC   r(   rE   r$   r#   r%   Ú__classcell__r   r   rF   r   r   ë   s   


c                   @   s   e Zd ZdZdS )r   z'The interface has invalid contents
    Nr   r   r   r   r   r     s   c                   @   s   e Zd ZdZdS )r   zŽAn implementation assertion is invalid

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