o ]LbIO@sdZddlmZmZddlZddlmZddlmZddlZddl Z ddl m Z ddl m Z d Z d Zd ZeZd d ZddZGdddeZGdddeZeZzddlmZWn eybYnweZGdddeZeZzddlmZWn eyYnwgZzddlmZWn eyYnwGdddeZGdddeeeZedddZGd d!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)0z Interface object implementation )absolute_import generatorsN) MethodType) FunctionType)Invalid)ro__interface_tagged_values__cCs2tdj}|ti}|dg}||tS)Nr invariants)sys _getframef_locals setdefault TAGGED_DATAappend_decorator_non_return)callrtagsr rO/usr/lib/python3/dist-packages/mercurial/thirdparty/zope/interface/interface.py invariant"s    rcCs$tdj}|ti}|||<tS)z;Attaches a tagged value to an interface at definition time.r)r rrrrr)keyvaluer tagged_valuesrrr taggedValue*s  rc@sHeZdZdddZddZddZdd Zdd d Zd dZddZ d S)ElementcCs0|s |ddkr |}d}||_||_i|_dS)z*Create an 'attribute' description  rN)find__name____doc___Element__tagged_values)selfr!r"rrr__init__9s  zElement.__init__cC|jS)z! Returns the name of the object. r!r$rrrgetNameDzElement.getNamecCr&)z+ Returns the documentation for the object. )r"r(rrrgetDocHr*zElement.getDoccCs |j|Sz* Returns the value associated with 'tag'. r#)r$tagrrrgetTaggedValueL zElement.getTaggedValueNcCs|j||Sr,)r#get)r$r.defaultrrrqueryTaggedValuePzElement.queryTaggedValuecCs |jS)z Returns a list of all tags. )r#keysr(rrrgetTaggedValueTagsTr0zElement.getTaggedValueTagscCs||j|<dS)z Associates 'value' with 'key'. Nr-)r$r.rrrrsetTaggedValueXr4zElement.setTaggedValue)rN) r! __module__ __qualname__r%r)r+r/r3r6r7rrrrr2s    rc@s(eZdZddZddZddZeZdS)SpecificationBasePycCt|}||jvS)z2Is the interface implemented by an object ) providedBy_implied)r$obspecrrrr=^s zSpecificationBasePy.providedBycCr<)zTest whether the specification is implemented by a class or factory. Raise TypeError if argument is neither a class nor a callable. ) implementedByr>)r$clsr@rrrrAds z!SpecificationBasePy.implementedBycCs ||jvS)zCIs the interface the same as or extend the given interface r>)r$ interfacerrr isOrExtendsls zSpecificationBasePy.isOrExtendsN)r!r9r:r=rArE__call__rrrrr;\s r;)SpecificationBasec@s$eZdZdZefddZddZdS)InterfaceBasePyz:Base class that wants to be replaced with a C base :) cCsXt|dd}|dur||}|dur|S||}|dur |S|tur&|Std||)z)Adapt an object to the interface __conform__NzCould not adapt)getattr _call_conform __adapt___marker TypeError)r$obj alternateconformadapterrrrrF~s    zInterfaceBasePy.__call__cCs6||r|StD]}|||}|dur|Sq dS)z(Adapt an object to the reciever N)r= adapter_hooks)r$rOhookrRrrrrLs  zInterfaceBasePy.__adapt__N)r!r9r:r"rMrFrLrrrrrHzs  rH) InterfaceBase)rSc@szeZdZdZejZejZdddZddZddZ d d Z e d d e Z d dZ 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. rcCsi|_t|_t||_dSr8)r>weakrefWeakKeyDictionary dependentstuple __bases__)r$basesrrrr%s zSpecification.__init__cCs|j|dd|j|<dSNrr)rYr1)r$ dependentrrr subscribeszSpecification.subscribecCs@|j|dd}|s|j|=dS|dkr||j|<dSt|r])rYr1KeyError)r$r^nrrr unsubscribes  zSpecification.unsubscribecCsB|jD]}||q||jd<|D]}||q||dS)Nr[)r[rb__dict__r_changed)r$r\brrr __setBasess    zSpecification.__setBasescCs|jddS)Nr[r)rcr1r(rrrszSpecification.cCsz|`Wn ty Ynw|j}|t|}z t|vr#|tWn ty-Ynwt||_ tdd|D|_ |D]}d||<q?t|j D]}| |qMdS)z4We, or something we depend on, have changed cSsg|] }t|tr|qSr) isinstanceInterfaceClass).0ancestorrrr s z)Specification.changed..rN)_v_attrsAttributeErrorr>clearr Interfacer NameErrorrZ__sro____iro__rYr5rd)r$originally_changedimplied ancestorsrkr^rrrrds,      zSpecification.changedccs:i}|jD]}|D] }||vrd||<|Vq qdS)DReturn an iterator for the interfaces in the specification. rN)r[ interfaces)r$seenbaserDrrrrxs  zSpecification.interfacesTcCs||jvo | p ||kS)zDoes the specification extend the given interface? Test whether an interface in the specification extends the given interface rC)r$rDstrictrrrextends s  zSpecification.extendsNcCs t||Sr8)rWref)r$callbackrrrrW zSpecification.weakrefcCstz|j}Wntyi}|_Ynw||}|dur2|jD]}||}|dur1|||<nq |dur8|S|S)z+Query for an attribute description N)rmrnr1rsdirect)r$namer2attrsattrifacerrrr1s      zSpecification.get)r)Tr8)r!r9r:r"rGrEr=r%r_rb_Specification__setBasespropertyr[rdrxr|rWr1rrrrrVs"    ! rVc@seZdZdZ  d3ddZddZdd Zd d Zd4d dZddZ d4ddZ ddZ e Z ddZ ddZd5ddZd5ddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2ZdS)6riz0Prototype (scarecrow) Interfaces Implementation.rNc Cs|duri}|dur.|d}t|tr|d=nz tdjd}Wn ttfy-Ynw||_|d}|durHt|t sH|durE|}|d=|durNd}t |||| t d}|durn|D] \}} ||| qc|D] } t| ts{tdqpt ||t|D]7\}} |dvr||=qt| t r|| _| js|| _qt| trt| ||d||<q| tur||=qtd |||_d |j|jf|_dS) Nr9rr!r"rzExpected base interfaces) __locals__r:__annotations__)rzConcrete attribute, %s.%s)r1rhstrr r f_globalsrnr`r9 Attributerr%popritemsr7rirNrVlistrDr!r fromFunctionrInvalidInterface_InterfaceClass__attrs__identifier__) r$rr\rr"r9d tagged_datarvalrzrrrrr%4s\          zInterfaceClass.__init__ccs |VdS)rwNrr(rrrrxxs zInterfaceClass.interfacescCr&r8)r[r(rrrgetBases}zInterfaceClass.getBasescCs||kp||S)zSame interface or extends?)r|)r$otherrrrisEqualOrExtendedBysz"InterfaceClass.isEqualOrExtendedByFcCsB|s|jS|j}|jD] }|t||q|S)z4Return the attribute names defined by the interface.)rr5copyr[updatedictfromkeysnamesr$allrrzrrrrs    zInterfaceClass.namescCst|jddS)NT)r)iterrr(rrr__iter__szInterfaceClass.__iter__cCsP|s|jSi}|jdddD] }|t||q||j|S)z=Return attribute names and descriptions defined by interface.N)rrr[rrnamesAndDescriptionsrrrrrs  z#InterfaceClass.namesAndDescriptionscCs||}|dur |St|)z4Return the attribute description for the given name.N)r1r`)r$rrrrrgetDescriptionFors z InterfaceClass.getDescriptionForcCs||duSr8r1r$rrrr __contains__zInterfaceClass.__contains__cCs |j|Sr8)rr1rrrrrrzInterfaceClass.directcCs |||Sr8r)r$rr2rrrqueryDescriptionForrz"InterfaceClass.queryDescriptionForc Cs|dgD]$}z||Wqty*}z|dur||WYd}~qd}~ww|jD]}z|||Wq.tyF|durDYq.w|rMt|dS)z&validate object to defined invariants.r N)r3rrr[validateInvariants)r$rOerrorsrerzrrrrs(   z!InterfaceClass.validateInvariantscCsRz|jWSty(|j}|j}|rd||f}d|jj|f}||_|YSw)Nrz<%s %s>)_v_reprrnr!r9 __class__)r$rmrrrr__repr__s  zInterfaceClass.__repr__cCs4z||WStytdjdurYdSw)N)rNr exc_infotb_next)r$rQrrrrKs  zInterfaceClass._call_conformcCr&r8r'r(rrr __reduce__rzInterfaceClass.__reduce__cCsL|durdSt|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. Nrr!rr9)rJ)r$rn1n2rrr__cmps zInterfaceClass.__cmpcCs4|j}d|vs d|vrtddSt|j|jfS)Nr9r!z-Hashing uninitialized InterfaceClass instancer)rcwarningswarnhashr!r9)r$rrrr__hash__s  zInterfaceClass.__hash__cCs||}|dkSNr_InterfaceClass__cmpr$rcrrr__eq__ zInterfaceClass.__eq__cCs||}|dkSrrrrrr__ne__rzInterfaceClass.__ne__cCs||}|dkSrrrrrr__lt__rzInterfaceClass.__lt__cCs||}|dkSrrrrrr__le__rzInterfaceClass.__le__cCs||}|dkSrrrrrr__gt__rzInterfaceClass.__gt__cCs||}|dkSrrrrrr__ge__"rzInterfaceClass.__ge__)rNNN)Fr8)r!r9r:r"r%rxrrrrrr __getitem__rrrrrrKrrrrrrrrrrrrrri,s8 D       rirpzzope.interface)r9c@seZdZdZdZdS)rzAttribute descriptions N)r!r9r:r"rDrrrrr)src@s`eZdZdZdZZdZZZddZ ddZ dd Z e e e e Z d d Zd d ZddZdS)MethodzMethod interfaces The idea here is that you have objects that describe methods. This provides an opportunity for rich meta-data. rNcCs|jduriS|jSr8 _optionalr(rrr _get_optionalCs zMethod._get_optionalcCs ||_dSr8r)r$optrrr _set_optionalG zMethod._set_optionalcCs d|_dSr8rr(rrr _del_optionalIrzMethod._del_optionalcOst|j|jr8)BrokenImplementationrDr!)r$argskwrrrrFMrzMethod.__call__cCs|j|j|j|j|jdS)N positionalrequiredoptionalvarargskwargsrr(rrrgetSignatureInfoPs zMethod.getSignatureInfocCsg}|jD]}||||jvr"|ddt|j|7<q|jr.|d|j|jr9|d|jdd|S)Nr=*z**z(%s)z, )rrrr5reprrrjoin)r$sigvrrrgetSignatureStringXs  zMethod.getSignatureString)r!r9r:r"rrrrrrrrrrrFrrrrrrr5s   rcCs|p|j}t||j}t|ddpd}|j}|j|}|j|d}i} |t|} | dkr7|| d}d} | t t || d||d||_ |d| |_ | |_ |} |jt@rg|| |_| d} nd|_|jt@ru|| |_nd|_||_|jD] \} } || | q|S)N __defaults__rrr)r!rr"rJ__code__ co_argcount co_varnameslenrrziprrrco_flags CO_VARARGSrCO_VARKEYWORDSrrDrcrr7)funcrDimlevelrmethoddefaultscodenarrnrargnorrrrrres6         rcCs&t|tr |j}n|}t||d|dS)Nr)rr)rhr__func__r)methrDrrrrr fromMethods rcCshddlm}ddlm}|t|ddlm}|t|ddlm}|t|ddlm }|t |dS)Nr)classImplements) IAttribute)IMethod) IInterface)ISpecification) declarationsrrxrrrrrrirrV)rrrrrrrr_wires        r)rA)r=)r)r)NrN)NN)*r" __future__rrr typesrrrrW exceptionsrrrrrobjectrrrrr;rG_zope_interface_coptimizations ImportErrorrMrHrUrSrVrirprrrrrrrAr=rrrrrrsf     * "   | 0 -