o
    $x`ä   ã                   @   sò   d Z ddlmZ ddlZddl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mZ ddgZefZddd„Zdd„ Zddd„Zddd„Zej e_ dZeefƒZdd„ Zdd„ ZdS )z!Verify interface implementations
é    )Úprint_functionN)ÚFunctionType)Ú
MethodType)ÚPYPY2)ÚBrokenImplementation)ÚBrokenMethodImplementation)ÚDoesNotImplement)ÚInvalid)ÚMultipleInvalid)Ú
fromMethodÚfromFunctionÚMethodÚverifyObjectÚverifyClassFc           	      C   s¶   |dkr| j }n| j}g }|s||ƒs| t| |ƒ¡ | jdd�D ]%\}}z
t| ||||ƒ W q! tyF } z| |¡ W Y d}~q!d}~ww |rYt|ƒdkrS|d ‚t| ||ƒ‚dS )a�  
    Verify that *candidate* might correctly provide *iface*.

    This involves:

    - Making sure the candidate claims that it provides the
      interface using ``iface.providedBy`` (unless *tentative* is `True`,
      in which case this step is skipped). This means that the candidate's class
      declares that it `implements <zope.interface.implementer>` the interface,
      or the candidate itself declares that it `provides <zope.interface.provider>`
      the interface

    - Making sure the candidate defines all the necessary methods

    - Making sure the methods have the correct signature (to the
      extent possible)

    - Making sure the candidate defines all the necessary attributes

    :return bool: Returns a true value if everything that could be
       checked passed.
    :raises zope.interface.Invalid: If any of the previous
       conditions does not hold.

    .. versionchanged:: 5.0
        If multiple methods or attributes are invalid, all such errors
        are collected and reported. Previously, only the first error was reported.
        As a special case, if only one such error is present, it is raised
        alone, like before.
    ÚcT)ÚallNé   r   )	ÚimplementedByÚ
providedByÚappendr   ÚnamesAndDescriptionsÚ_verify_elementr	   Úlenr
   )	ÚifaceÚ	candidateÚ	tentativeÚvtypeÚtesterÚexcsÚnameÚdescÚe© r"   ú7/usr/lib/python3/dist-packages/zope/interface/verify.pyÚ_verify*   s$    €ÿr$   c                 C   sJ  zt ||ƒ}W n ty    t|tƒs|dkrY d S t| ||ƒ‚w t|tƒs(d S t |¡s2t |¡r4d S t|tƒrZt	j
d dkrRt|tƒrR|dkrRt|| |dd�}n4t|| |d�}n,t|tƒrmt|jƒtu rmt|| |ƒ}nt|tƒrx|dkrxd S t|ƒs„t|d|| |ƒ‚d S t| ¡ | ¡ ƒ}|r£tr›t|||ƒr›d S t|||| |ƒ‚d S )Nr   r   é   r   )r   Úimlevel)r   zimplementation is not a method)ÚgetattrÚAttributeErrorÚ
isinstancer   r   ÚinspectÚismethoddescriptorÚ	isbuiltinr   ÚsysÚversion_infoÚtyper   ÚMethodTypesÚ__func__r   ÚpropertyÚcallabler   Ú	_incompatÚgetSignatureInfor   Ú_pypy2_false_positive)r   r   r    r   r   ÚattrÚmethÚmessr"   r"   r#   r   `   sB   ú

 ÿ
ÿýr   c                 C   ó   t | ||dd�S )zF
    Verify that the *candidate* might correctly provide *iface*.
    r   ©r   ©r$   ©r   r   r   r"   r"   r#   r   ¥   s   c                 C   r:   )NÚor;   r<   r=   r"   r"   r#   r   «   s   z*implementation requires too many argumentsc                 C   s<   | t vrdS ttƒ ¡ }|dkr|nt|ƒ}||v rdS dS )NFr   T)Ú_KNOWN_PYPY2_FALSE_POSITIVESÚvarsÚ__builtins__Úvaluesr/   )Úmsgr   r   Úknown_builtin_typesÚcandidate_typer"   r"   r#   r6   ¶   s   r6   c                 C   sp   t |d ƒt | d ƒkrtS t |d ƒt | d ƒk r |d s dS | d r*|d s*dS | d r4|d s6dS d S d S )NÚrequiredÚ
positionalÚvarargsz-implementation doesn't allow enough argumentsÚkwargsz0implementation doesn't support keyword argumentsz1implementation doesn't support variable arguments)r   Ú_MSG_TOO_MANY)rF   Úimplementedr"   r"   r#   r4   Í   s   ÿÿr4   )FN)F)Ú__doc__Ú
__future__r   r*   r-   Útypesr   r   Úzope.interface._compatr   Úzope.interface.exceptionsr   r   r   r	   r
   Úzope.interface.interfacer   r   r   Ú__all__r0   r$   r   r   r   rJ   Ú	frozensetr?   r6   r4   r"   r"   r"   r#   Ú<module>   s8   þ
6
E
ÿ