o $ x` @sdZddlmZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z dd l m Z dd l mZdd l mZdd lmZmZmZd dgZefZdddZddZdddZddd Zeje_dZeefZddZddZdS)z!Verify interface implementations )print_functionN) FunctionType) MethodType)PYPY2)BrokenImplementation)BrokenMethodImplementation)DoesNotImplement)Invalid)MultipleInvalid) fromMethod fromFunctionMethod verifyObject verifyClassFc Cs|dkr|j}n|j}g}|s||s|t|||jddD]%\}}z t|||||Wq!tyF}z ||WYd}~q!d}~ww|rYt|dkrS|dt|||dS)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 ` the interface, or the candidate itself declares that it `provides ` 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)allNr) implementedBy providedByappendrnamesAndDescriptions_verify_elementr lenr ) iface candidate tentativevtypetesterexcsnamedescer"7/usr/lib/python3/dist-packages/zope/interface/verify.py_verify*s$    r$cCsJzt||}Wnty t|ts|dkrYdSt|||wt|ts(dSt|s2t|r4dSt|trZt j ddkrRt|t rR|dkrRt |||dd}n4t |||d}n,t|t rmt |jturmt|||}nt|trx|dkrxdSt|st|d|||dSt||}|rtrt|||rdSt|||||dS)Nrrr)rimlevel)rzimplementation is not a method)getattrAttributeError isinstancer rinspectismethoddescriptor isbuiltinrsys version_infotyper MethodTypes__func__r propertycallabler _incompatgetSignatureInfor_pypy2_false_positive)rrr rrattrmethmessr"r"r#r`sB      rcCt|||ddS)zF Verify that the *candidate* might correctly provide *iface*. rrr$rrrr"r"r#rscCr:)Nor;r<r=r"r"r#rsz*implementation requires too many argumentscCs<|tvrdStt}|dkr|nt|}||vrdSdS)NFrT)_KNOWN_PYPY2_FALSE_POSITIVESvars __builtins__valuesr/)msgrrknown_builtin_typescandidate_typer"r"r#r6s  r6cCspt|dt|dkrtSt|dt|dkr |ds dS|dr*|ds*dS|dr4|ds6dSdSdS)Nrequired positionalvarargsz-implementation doesn't allow enough argumentskwargsz0implementation doesn't support keyword argumentsz1implementation doesn't support variable arguments)r _MSG_TOO_MANY)rF implementedr"r"r#r4sr4)FN)F)__doc__ __future__rr*r-typesrrzope.interface._compatrzope.interface.exceptionsrrrr r zope.interface.interfacer r r __all__r0r$rrrrJ frozensetr?r6r4r"r"r"r#s8          6 E