3 [P@sdZddlmZddlZddlmZddlmZddlZddlZddl m Z ddl m Z dZ d Zd ZeZd d Zd dZGdddeZGdddeZeZyddlmZWnek rYnXeZGdddeZeZyddlmZWnek rYnXgZyddlmZWnek r0YnXGdddeZGdddeeeZedddZGdd d eZ Gd!d"d"e Z!d-d#d$Z"d.d%d&Z#d'd(Z$dd)l%m&Z&dd*l%m'Z'dd+l m(Z(dd,l m)Z)dS)/z Interface object implementation ) generatorsN) MethodType) FunctionType)Invalid)roZ__interface_tagged_values__cCs2tjdj}|jti}|jdg}|j|tS)N invariants)sys _getframef_locals setdefault TAGGED_DATAappend_decorator_non_return)callr Ztagsr r!/usr/lib64/python3.6/interface.py invariant"s     rcCs$tjdj}|jti}|||<tS)z;Attaches a tagged value to an interface at definition time.r )r r r rrr)keyvaluer Z tagged_valuesrrr taggedValue*s  rc@sLeZdZdZdddZddZddZd d Zdd d ZddZ ddZ d S)ElementzI Default implementation of `zope.interface.interfaces.IElement`. cCs2| r|jddkr|}d}||_||_i|_dS)N r)find__name____doc___Element__tagged_values)selfrrrrr__init__<s zElement.__init__cCs|jS)z! Returns the name of the object. )r)r rrrgetNameEszElement.getNamecCs|jS)z+ Returns the documentation for the object. )r)r rrrgetDocIszElement.getDoccCs |j|S)z* Returns the value associated with 'tag'. )r)r tagrrrgetTaggedValueMszElement.getTaggedValueNcCs|jj||S)z* Returns the value associated with 'tag'. )rget)r r$defaultrrrqueryTaggedValueQszElement.queryTaggedValuecCs |jjS)z Returns a list of all tags. )rkeys)r rrrgetTaggedValueTagsUszElement.getTaggedValueTagscCs||j|<dS)z Associates 'value' with 'key'. N)r)r r$rrrrsetTaggedValueYszElement.setTaggedValue)r)N) r __module__ __qualname__rr!r"r#r%r(r*r+rrrrr2s  rc@s(eZdZddZddZddZeZdS)SpecificationBasePycCst|}||jkS)z2Is the interface implemented by an object ) providedBy_implied)r obspecrrrr/_szSpecificationBasePy.providedBycCst|}||jkS)zTest whether the specification is implemented by a class or factory. Raise TypeError if argument is neither a class nor a callable. ) implementedByr0)r clsr2rrrr3esz!SpecificationBasePy.implementedBycCs ||jkS)zCIs the interface the same as or extend the given interface )r0)r interfacerrr isOrExtendsmszSpecificationBasePy.isOrExtendsN)rr,r-r/r3r6__call__rrrrr.]sr.)SpecificationBasec@s$eZdZdZefddZddZdS)InterfaceBasePyz:Base class that wants to be replaced with a C base :) cCs\t|dd}|dk r*|j|}|dk r*|S|j|}|dk r@|S|tk rL|Std||dS)z)Adapt an object to the interface Z __conform__NzCould not adapt)getattr _call_conform __adapt___marker TypeError)r objZ alternateconformadapterrrrr7s   zInterfaceBasePy.__call__cCs6|j|r|Sx"tD]}|||}|dk r|SqWdS)z(Adapt an object to the reciever N)r/ adapter_hooks)r r?hookrArrrr<s    zInterfaceBasePy.__adapt__N)rr,r-rr=r7r<rrrrr9{s r9) InterfaceBase)rBc@s|eZdZdZejZejZffddZddZddZ dd Z e d d e Z d d Z ddZdddZdddZdddZdS) SpecificationawSpecifications An interface specification is used to track interface declarations and component registrations. This class is a base class for both interfaces themselves and for interface specifications (declarations). Specifications are mutable. If you reassign their bases, their relations with other specifications are adjusted accordingly. cCsi|_tj|_t||_dS)N)r0weakrefWeakKeyDictionary dependentstuple __bases__)r basesrrrr!s zSpecification.__init__cCs|jj|dd|j|<dS)Nrr )rHr&)r dependentrrr subscribeszSpecification.subscribecCs@|jj|dd}|s |j|=n|dkr4||j|<nt|dS)Nrr )rHr&KeyError)r rLnrrr unsubscribes   zSpecification.unsubscribecCsJx|jD]}|j|qW||jd<x|D]}|j|q*W|j|dS)NrJ)rJrP__dict__rMchanged)r rKbrrrZ __setBasess    zSpecification.__setBasescCs|jjdfS)NrJ)rQr&)r rrrszSpecification.cCsy|`Wntk rYnX|j}|jt|}yt|krH|jtWntk r^YnXt||_ tdd|D|_ x|D] }f||<qWx t|j j D]}|j |qWdS)z4We, or something we depend on, have changed cSsg|]}t|tr|qSr) isinstanceInterfaceClass).0ancestorrrr sz)Specification.changed..N)_v_attrsAttributeErrorr0clearr Interfacer NameErrorrIZ__sro____iro__rHr)rR)r Zoriginally_changedZimpliedZ ancestorsrXrLrrrrRs$   zSpecification.changedccs@i}x6|jD],}x&|jD]}||krd||<|VqWq WdS)zDReturn an iterator for the interfaces in the specification. r N)rJ interfaces)r seenbaser5rrrr`s  zSpecification.interfacesTcCs||jko| p||kS)zDoes the specification extend the given interface? Test whether an interface in the specification extends the given interface )r0)r r5strictrrrextends s zSpecification.extendsNcCs tj||S)N)rFref)r callbackrrrrFszSpecification.weakrefc Cs|y |j}Wntk r(i}|_YnX|j|}|dkrhx*|jD] }|j|}|dk rD|||<PqDW|dkrt|S|SdS)z+Query for an attribute description N)rZr[r&r_direct)r namer'attrsattrZifacerrrr&s    zSpecification.get)T)N)N)rr,r-rr8r6r/r!rMrPZ_Specification__setBasespropertyrJrRr`rdrFr&rrrrrEs    ! rEc@seZdZdZfdddfddZddZddZd d Zd2d d ZddZ d3ddZ ddZ e Z ddZ ddZd4ddZd5ddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1ZdS)6rVz0Prototype (scarecrow) Interfaces Implementation.Nc Cs|dkr i}|dkr^|jd}t|tr0|d=n.ytjdjd}Wnttfk r\YnX||_|jd}|dk rt|t s|dkr|}|d=|dkrd}t j ||||j t d}|dk rx |jD]\}} |j|| qWx|D]} t| tstdqWtj ||xt|jD]~\}} |d kr8||=qt| t rZ|| _| js|| _n>t| trzt| ||d ||<n| tkr||=n td |qW||_d |j|jf|_dS)Nr,r rrrzExpected base interfaces __locals__r-__annotations__)rhzConcrete attribute, z%s.%s)rlr-rm)r&rUstrr r f_globalsr[rNr, Attributerr!popritemsr+rVr>rElistr5rr fromFunctionrInvalidInterface_InterfaceClass__attrsZ__identifier__) r rhrKrirr,dZ tagged_datarvalrbrjrrrr!5sV             zInterfaceClass.__init__ccs |VdS)zDReturn an iterator for the interfaces in the specification. Nr)r rrrr`yszInterfaceClass.interfacescCs|jS)N)rJ)r rrrgetBases~szInterfaceClass.getBasescCs||kp|j|S)zSame interface or extends?)rd)r otherrrrisEqualOrExtendedBysz"InterfaceClass.isEqualOrExtendedByFcCsF|s|jjS|jj}x$|jD]}|jtj|j|q W|jS)z4Return the attribute names defined by the interface.)rvr)copyrJupdatedictfromkeysnames)r allrrbrrrrs    zInterfaceClass.namescCst|jddS)NT)r)iterr)r rrr__iter__szInterfaceClass.__iter__cCsT|s|jjSi}x,|jdddD]}|jt|j|q$W|j|j|jS)z=Return attribute names and descriptions defined by interface.Nr )rvrrrJr}r~namesAndDescriptions)r rrrbrrrrs  z#InterfaceClass.namesAndDescriptionscCs"|j|}|dk r|St|dS)z4Return the attribute description for the given name.N)r&rN)r rhrrrrgetDescriptionFors z InterfaceClass.getDescriptionForcCs|j|dk S)N)r&)r rhrrr __contains__szInterfaceClass.__contains__cCs |jj|S)N)rvr&)r rhrrrrgszInterfaceClass.directcCs |j||S)N)r&)r rhr'rrrqueryDescriptionForsz"InterfaceClass.queryDescriptionForcCsxZ|jdgD]J}y ||Wqtk rV}z|dkr<n |j|WYdd}~XqXqWx>|jD]4}y|j||Wqdtk r|dkrYqdXqdW|rt|dS)z&validate object to defined invariants.r N)r(rrrJvalidateInvariants)r r?errorsrerbrrrrs    z!InterfaceClass.validateInvariantsc CsRy|jStk rL|j}|j}|r2d||f}d|jj|f}||_|SXdS)Nz%s.%sz<%s %s>)Z_v_reprr[rr, __class__)r rhmrrrr__repr__s zInterfaceClass.__repr__c Cs6y||Stk r0tjdjdk r,YnXdS)N)r>r exc_infotb_next)r r@rrrr;s zInterfaceClass._call_conformcCs|jS)N)r)r rrr __reduce__szInterfaceClass.__reduce__cCsL|dkr dSt|ddt|ddf}t|ddt|ddf}||k||kS)aMake interfaces sortable TODO: It would ne nice if: More specific interfaces should sort before less specific ones. Otherwise, sort on name and module. But this is too complicated, and we're going to punt on it for now. For now, sort on interface and module name. None is treated as a pseudo interface that implies the loosest contact possible, no contract. For that reason, all interfaces sort before None. Nr rrr,r)r:)r rzZn1Zn2rrrZ__cmps zInterfaceClass.__cmpcCs4|j}d|ksd|kr$tjddSt|j|jfS)Nr,rz-Hashing uninitialized InterfaceClass instancer )rQwarningswarnhashrr,)r rwrrr__hash__s  zInterfaceClass.__hash__cCs|j|}|dkS)Nr)_InterfaceClass__cmp)r rzcrrr__eq__s zInterfaceClass.__eq__cCs|j|}|dkS)Nr)r)r rzrrrr__ne__s zInterfaceClass.__ne__cCs|j|}|dkS)Nr)r)r rzrrrr__lt__s zInterfaceClass.__lt__cCs|j|}|dkS)Nr)r)r rzrrrr__le__s zInterfaceClass.__le__cCs|j|}|dkS)Nr)r)r rzrrrr__gt__s zInterfaceClass.__gt__cCs|j|}|dkS)Nr)r)r rzrrrr__ge__#s zInterfaceClass.__ge__)F)F)N)N)rr,r-rr!r`ryr{rrrr __getitem__rrgrrrr;rrrrrrrrrrrrrrV-s4 C     rVr]zzope.interface)r,c@seZdZdZdZdS)rpzAttribute descriptions N)rr,r-rr5rrrrrp*srpc@s`eZdZdZfZZdZZZddZ ddZ ddZ e e e e Z d d Zd d Zd dZdS)MethodzMethod interfaces The idea here is that you have objects that describe methods. This provides an opportunity for rich meta-data. NcCs|jdkriS|jS)N) _optional)r rrr _get_optionalDs zMethod._get_optionalcCs ||_dS)N)r)r optrrr _set_optionalHszMethod._set_optionalcCs d|_dS)N)r)r rrr _del_optionalJszMethod._del_optionalcOst|j|jdS)N)BrokenImplementationr5r)r argskwrrrr7NszMethod.__call__cCs|j|j|j|j|jdS)N) positionalrequiredoptionalvarargskwargs)rrrrr)r rrrgetSignatureInfoQs zMethod.getSignatureInfocCsg}xD|jD]:}|j|||jjkr |ddt|j|7<q W|jr`|jd|j|jrv|jd|jddj|S)Nr =*z**z(%s)z, r)rrrr)reprrrjoin)r ZsigvrrrgetSignatureStringYs  "zMethod.getSignatureString)rr,r-rrrrrrrrrrkrr7rrrrrrr6s  rcCs |p|j}t||j}t|ddp$f}|j}|j|}|j|d}i} |t|} | dkrn|| d}d} | jt t || d||d||_ |d| |_ | |_ |} |jt@r|| |_| d} nd|_|jt@r|| |_nd|_||_x$|jjD]\} } |j| | qW|S)N __defaults__rr )rrrr:__code__ co_argcount co_varnameslenr}r~ziprrrco_flags CO_VARARGSrCO_VARKEYWORDSrr5rQrrr+)funcr5imlevelrhmethodZdefaultscodeZnarrZnrZargnorrrrrrtfs6         rtcCs&t|tr|j}n|}t||d|dS)Nr )rrh)rUr__func__rt)methr5rhrrrr fromMethods rcCshddlm}ddlm}|t|ddlm}|t|ddlm}|t|ddlm }|t |dS)Nr)classImplements) IAttribute)IMethod) IInterface)ISpecification) zope.interface.declarationsrZzope.interface.interfacesrrprrrrVrrE)rrrrrrrr_wires        r)r3)r/)ru)r)NrN)NN)*rZ __future__rr typesrrrrFZzope.interface.exceptionsrZzope.interface.rorrrrobjectrrrrr.r8Z-zope.interface._zope_interface_coptimizations ImportErrorr=r9rDrBrErVr]rprrtrrrr3r/rurrrrrs^     +"|  0 -