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   )	ZimplementedByZ
providedByappendr   ZnamesAndDescriptions_verify_elementr	   lenr
   )	iface	candidate	tentativevtypeZtesterZ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|st|d|| |d S t| | }|rtrt|||rd S t|||| |d S )Nr   r      r   )r   Zimlevel)r   zimplementation is not a method)getattrAttributeError
isinstancer   r   inspectZismethoddescriptorZ	isbuiltinr   sysversion_infotyper   MethodTypes__func__r   propertycallabler   	_incompatZgetSignatureInfor   _pypy2_false_positive)r   r   r   r   r   attrZmethZmessr   r   r   r   `   sD   

 
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or0   r1   r2   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   Zknown_builtin_typesZcandidate_typer   r   r   r-      s   r-   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requiredZ
positionalZvarargsz-implementation doesn't allow enough argumentskwargsz0implementation doesn't support keyword argumentsz1implementation doesn't support variable arguments)r   _MSG_TOO_MANY)r9   Zimplementedr   r   r   r,      s   r,   )FN)F)__doc__Z
__future__r   r$   r%   typesr   r   Zzope.interface._compatr   Zzope.interface.exceptionsr   r   r   r	   r
   Zzope.interface.interfacer   r   r   __all__r(   r   r   r   r   r;   	frozensetr4   r-   r,   r   r   r   r   <module>   s8   
6
E
