B
    0`                  @   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 }|s6||s6|t| | xZ| jddD ]J\}}yt| |||| W qD tk
r } z|| W dd}~X Y qDX qDW |rt|dkr|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vtypetesterZexcsnamedesce r   D/home/dcms/DCMS/lib/python3.7/site-packages/zope/interface/verify.py_verify*   s       r    c             C   sV  yt ||}W n6 tk
rD   t|ts4|dkr4d S t| ||Y nX t|tsTd S t|sht|rld S t|trt	j
d dkrt|tr|dkrt|| |dd}nt|| |d}nZt|trt|jtkrt|| |}n4t|tr|dkrd S t|st|d|| |d S t| | }|rRtrBt|||rBd S t|||| |d S )Nr   r      r   )r   Zimlevel)r   zimplementation is not a method)getattrAttributeError
isinstancer   r   inspectismethoddescriptor	isbuiltinr   sysversion_infotyper   MethodTypes__func__r   propertycallabler   	_incompatZgetSignatureInfor   _pypy2_false_positive)r   r   r   r   r   attrmethZmessr   r   r   r   `   s:    

 



r   c             C   s   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   s   t | ||ddS )No)r   )r    )r   r   r   r   r   r   r      s    z*implementation requires too many argumentsc             C   s<   | t krdS tt }|dkr$|nt|}||kr8dS dS )NFr   T)_KNOWN_PYPY2_FALSE_POSITIVESvars__builtins__valuesr*   )msgr   r   Zknown_builtin_typesZcandidate_typer   r   r   r0      s    r0   c             C   sl   t |d t | d krtS t |d t | d k r@|d s@dS | d rT|d sTdS | d rh|d shd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)r9   Zimplementedr   r   r   r/      s    r/   )FN)F)F)__doc__
__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   r0   r/   r   r   r   r   <module>   s2   
6E

