edZddlZddlmZddlmZddlZddlmZddlm Z ddl m Z ddl m Z gdZd Zd Zd Zd ZeZeZd ZdZGddZeZeGddZGddZeGddeeZegdZGddeZGddeZ e deeefddiZ!dZ"Gd de!Z#e#d!d"#Z$d$e$_%e$jMe$e$jNe$fk(sJe$e_(e$e _(Gd%d&e#Z)Gd'd(eZ*Gd)d*e*Z+d3d+Z,d4d,Z-d-Z.dd.l/m0Z0dd/l/m1Z1dd0lm2Z2dd1lm3Z3dd2l/m4Z4ejMe4e4y)5z Interface object implementation N) MethodType) FunctionType) _use_c_impl)Invalid)ro)InterfaceClass Specification adapter_hooks__interface_tagged_values____interface_methods__ctjdj}|jti}|jdg}|j |t S)N invariants)sys _getframef_locals setdefault TAGGED_DATAappend_decorator_non_return)callrtagsrs :/usr/lib/python3/dist-packages/zope/interface/interface.py invariantr1sL}}Q((H   {B /Dr2Jd  ctjdj}|jti}|||<t S)z;Attaches a tagged value to an interface at definition time.r)rrrrrr)keyvaluer tagged_valuess r taggedValuer"9s8}}Q((H'' R8MM#  rcJeZdZdZd dZdZdZdZd dZdZ d Z eZ eZ e Z y) ElementzI Default implementation of `zope.interface.interfaces.IElement`. cb|s|jddk\r|}d}||_||_d|_y)N r)find__name____doc___Element__tagged_values)selfr(r)s r__init__zElement.__init__Ks78==-2GH    $rc|jS)z! Returns the name of the object. r(r+s rgetNamezElement.getNameVs }}rc|jS)z+ Returns the documentation for the object. )r)r/s rgetDoczElement.getDocZs ||rcN|js t||j|S* Returns the value associated with 'tag'. )r*KeyError)r+tags rgetTaggedValuezElement.getTaggedValuees&##3- ##C((rNcV|jr|jj||S|Sr4)r*get)r+r7defaults rqueryTaggedValuezElement.queryTaggedValueks)9=9M9Mt##''W5ZSZZrcR|jr|jjSdS)z# Returns a collection of all tags. )r*keysr/s rgetTaggedValueTagszElement.getTaggedValueTagsos$.2.B.Bt##((*JJrcH|ji|_||j|<y)z Associates 'value' with 'key'. N)r*r+r7r s rsetTaggedValuezElement.setTaggedValuess&    '#%D $)S!r)N)r( __module__ __qualname__r)r,r0r2r8r<r@rCqueryDirectTaggedValuegetDirectTaggedValuegetDirectTaggedValueTagsr>rrr$r$As@ $) [K* .)1rr$c&eZdZdZdZdZdZeZy)SpecificationBase)_implied _dependents_bases_v_attrs__iro____sro__ __weakref__c4t|}||jvS)z2Is the interface implemented by an object ) providedByrM)r+obspecs rrUzSpecificationBase.providedBys"~t}}$$rc4t|}||jvS)zTest whether the specification is implemented by a class or factory. Raise TypeError if argument is neither a class nor a callable. ) implementedByrM)r+clsrWs rrYzSpecificationBase.implementedBys S!t}}$$rc||jvS)zCIs the interface the same as or extend the given interface rM)r+ interfaces r isOrExtendszSpecificationBase.isOrExtendssDMM))rN)r(rFrG __slots__rUrYr^__call__r>rrrLrLs I% %* HrrLc.eZdZdZdZdZdZdZdZy)NameAndModuleComparisonMixinr>c||ury|y|j|jf} |j|jf}||kD||kz S#t$r tcYSwxYw)a Compare *self* to *other* based on ``__name__`` and ``__module__``. Return 0 if they are equal, return 1 if *self* is greater than *other*, and return -1 if *self* is less than *other*. If *other* does not have ``__name__`` or ``__module__``, then return ``NotImplemented``. .. caution:: This allows comparison to things well outside the type hierarchy, perhaps not symmetrically. For example, ``class Foo(object)`` and ``class Foo(Interface)`` in the same file would compare equal, depending on the order of operands. Writing code like this by hand would be unusual, but it could happen with dynamic creation of types and interfaces. None is treated as a pseudo interface that implies the loosest contact possible, no contract. For that reason, all interfaces sort before None. r)r(rFAttributeErrorNotImplemented)r+othern1n2s r_comparez%NameAndModuleComparisonMixin._comparesm0 D= =mmT__ - "..%"2"23B RBG$$  "! ! "sAAAcB|j|}|tur|S|dkSNrrjrfr+rgcs r__lt__z#NameAndModuleComparisonMixin.__lt__& MM%   H1u rcB|j|}|tur|S|dkSrlrmrns r__le__z#NameAndModuleComparisonMixin.__le__& MM%   HAv rcB|j|}|tur|S|dkDSrlrmrns r__gt__z#NameAndModuleComparisonMixin.__gt__rqrcB|j|}|tur|S|dk\Srlrmrns r__ge__z#NameAndModuleComparisonMixin.__ge__rtrN) r(rFrGr_rjrprsrvrxr>rrrbrbs#I%%N   rrbcTeZdZdZdZd dZdZedZe fdZ dZ d Z d Z d Zy) InterfaceBasez:Base class that wants to be replaced with a C base :) )r( __ibmodule___v_cached_hashNc ||_||_yrE)r(r{)r+namemodules rr,zInterfaceBase.__init__ s "rctrE)NotImplementedErrorr+conforms r _call_conformzInterfaceBase._call_conform s!!rc|jSrE)r{r/s r__module_property__z!InterfaceBase.__module_property__s   rc |j}||j|}||S|j|}||S|tur|St d||#t$rd}YPwxYw)z)Adapt an object to the interface NzCould not adapt) __conform__rer __adapt___marker TypeError)r+obj alternateradapters rr`zInterfaceBase.__call__s ooG  ((1G"..%  N G # )355 G s A AAc^|j|r|StD]}|||}||cSy)z(Adapt an object to the receiver N)rUr )r+rhookrs rrzInterfaceBase.__adapt__*s? ??3 J! D4oG"  rc |jS#t$r4t|j|jf|_Y|jSwxYwrE)r|rehashr(rFr/s r__hash__zInterfaceBase.__hash__7sK I&& & I"& t'G"HD """ Is /A  A cB|j|}|tur|S|dk(Srlrmrns r__eq__zInterfaceBase.__eq__?rtrcL||ury|j|}|tur|S|dk7S)NFrrmrns r__ne__zInterfaceBase.__ne__Es0 D= MM%   HAv rNN)r(rFrGr)r_r,rpropertyrrr`rrrrr>rrrzrzsJI #"!!'.6* # rrzr ceZdZdZdZdZejZejZddZ e dZ dZ dZ dZe d eZeZd Zd Zd Zdd ZddZddZy)r awSpecifications 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. r>Ncxd|_d|_i|_d|_d|_d|_t ||_y)Nr>)rNrOrMrPrQrRtuple __bases__)r+basess rr,zSpecification.__init__gs:      urcd|jtj|_|jSrE)rNweakrefWeakKeyDictionaryr/s r dependentszSpecification.dependentsys+    #&88:D rc\|jj|ddz|j|<y)Nrr)rr:rN)r+ dependents r subscribezSpecification.subscribes(&*oo&9&9)Q&G!&K#rc |j|}|dz}|s|j|=y|dkDsJ||j|<y#t$r t|wxYw)Nrr)rNrr6r)r+rns r unsubscribezSpecification.unsubscribesf &  +A Q *q5L5)*DOOI & &9% % &s =Ac|jD]}|j|||_|D]}|j||j |yrE)rrrOrchanged)r+rbs r __setBaseszSpecification.__setBasessS A MM$    A KK   Trc|jSrE)rOr/s rzSpecification.s T[[rc|j|jDcic]}||jc}}|j}|-|r+|d|ur$|Dcgc]}||ur| }}|j ||Scc}wcc}w)z Calculate and return the resolution order for this object, using its ``__bases__``. Ensures that ``Interface`` is always the last (lowest priority) element. ) base_mrosrd)_do_calculate_rorrR_ROOTr)r+rsrorootxs r_calculate_srozSpecification._calculate_srosF##^^/  qyyL/ # zz  Bt(;D=C JJt  )/ s A3 A8c d|_|j}|j|j}t ||_t |Dcgc]}t |tr|c}|_|D]}d||< t |jr|jjndD]}|j|d|_ycc}w)z We, or something we depend on, have changed. By the time this is called, the things we depend on, such as our bases, should themselves be stable. Nr>) rPrMclearrrrR isinstancerrQrNr?r)r+originally_changedimplied ancestorsancestorrs rrzSpecification.changeds -- '') Y' y 8!+Hn!E' ! " #H "GH  # $:J:Jt//446PRS 2I   0 1 2  ! s C c#xKi}|jD]%}|jD]}||vsd||<|'yw)DReturn an iterator for the interfaces in the specification. rN)r interfaces)r+seenbaser]s rrzSpecification.interfacessLNN $D!__. $ D(&'DO#O $ $s)::c6||jvxr | xs||k7S)zDoes the specification extend the given interface? Test whether an interface in the specification extends the given interface r\)r+r]stricts rextendszSpecification.extends s) dmm+6*4$)"3 rc.tj||SrE)rref)r+callbacks rrzSpecification.weakrefs{{4**rc|j}| ix}|_|j|}|+|jD]}|j|}||||<n||S|S)z+Query for an attribute description )rPr:rQdirect)r+r~r;attrsattrifaces rr:zSpecification.getst  =$& &EDMyy < ||D)#"&E$K   ,w0D0r)r>)TrE)r(rFrGr)r_rrLr^rUr,rrrr_Specification__setBasesr calculate_rorrrrrrr:r>rrr r Qs I E$//K"--J&$  L +   I$7r@$ +1rr c,eZdZdZdZedZdZy)_InterfaceMetaClassr>ctjdjd}tjd}t |t rtjd}||d<tj||||}||_ |S)Nrr(rFr) rr f_globalsrz__dict__rstrtype__new___InterfaceMetaClass__module)rZr~rrrF moduledescrkinds rrz_InterfaceMetaClass.__new__ssv ]]1%// ; $,,\: k3 '(001FGK)l||Cue4"  rc|jSrE)rrZs rrFz_InterfaceMetaClass.__module__s ||rcNdj|j|jS)Nz)formatrr(rs r__repr__z_InterfaceMetaClass.__repr__s# '' LL LL  rN)r(rFrGr_rrrr>rrrr(s(RI$ rrrr_r>ctjdj}|jti}|||j <t S)a Convert a method specification to an actual method of the interface. This is a decorator that functions like `staticmethod` et al. The primary use of this decorator is to allow interface definitions to define the ``__adapt__`` method, but other interface methods can be overridden this way too. .. seealso:: `zope.interface.interfaces.IInterfaceDeclaration.interfacemethod` r)rrrrINTERFACE_METHODSr(r)funcrmethodss rinterfacemethodrs?}}Q((H!!"3R8G!GDMM  rceZdZdZ ddZ ddZdZdZdZdZ dd Z d Z dd Z d Z e Zd ZdZddZddZddZdZdZdZdZdZdZy)rz Prototype (scarecrow) Interfaces Implementation. Note that it is not possible to change the ``__name__`` or ``__module__`` after an instance of this object has been constructed. Ncrt|tsJ|xsi}|jtd}|rs|j d|vrd|jdinid|vrd|d<t |t r|f}n|turt f}n|t f}t||dz||}tj|S)N __classcell__rr_CALL_CUSTOM_ADAPTz) rrpoprupdate issubclass _InterfaceClassWithCustomMethodsrr_InterfaceClassBaser)rZr~rrr)rFneeds_custom_class cls_basess rrzInterfaceClass.__new__s%''' "YY'8$?   % %"e+!%))O"<=  00;<"#78#?@ F &=?  "BC $s),,"C #**3//rctd|Ds td|i}|H|jd}t|tr|d=n# t j djd}tj||||jd}|t|ts||}|d=|d}tj||||jtd}|*|j!D]\}} |j#|| t$j|||j'||_dj+|||_y#ttf$rYwxYw) Nc3<K|]}t|tywrE)rr).0rs r z*InterfaceClass.__init__..sF:dN3FszExpected base interfacesrFrr(r)rD{}.{})allrr:rrrrrrer6rzr, Attributer$rritemsrCr _InterfaceClass__compute_attrs_InterfaceClass__attrsr__identifier__) r+r~rrr)rFd tagged_datarvals rr,zInterfaceClass.__init__sa FFF67 7 =E  <0J*c*,'"%q!1!;!;J!GJ tT:6 IIi  =a+?G)$ ?GtW-ii T2  "'--/ .S##C- . tU+++E2 %nnZ>9'1s "EE E c fd}|jDcic]\}}|dvr|tur ||||c}}Scc}}w)Nct|tr|_|js||_|St|trt ||}|St d|z)N)r~zConcrete attribute, )rrr]r(r fromFunctionInvalidInterface)anameavalr+s r update_valuez4InterfaceClass.__compute_attrs..update_value s]$ *!%}}$)DM K D,/#D$U;K''='EFFr) __locals__rG__annotations__)rr)r+rrrrs` r__compute_attrszInterfaceClass.__compute_attrssX  %{{}  t11 <t, ,   s >c#K|yw)rNr>r/s rrzInterfaceClass.interfaces$s  sc|jSrE)rr/s rgetBaseszInterfaceClass.getBases)s ~~rc2||k(xs|j|S)zSame interface or extends?)r)r+rgs risEqualOrExtendedByz"InterfaceClass.isEqualOrExtendedBy,su}3 d 33rc|s|jjS|jj}|jD]5}|j t j |j|7|jS)z4Return the attribute names defined by the interface.)rr?copyrrdictfromkeysnamesr+rrrs rrzInterfaceClass.names0sg<<$$& & LL   NN 5D HHT]]4::c?3 4 5vvxrc8t|jdS)NT)r)iterrr/s r__iter__zInterfaceClass.__iter__<sDJJ4J())rc|s|jjSi}|jdddD]+}|jt |j |-|j|j|jS)z=Return attribute names and descriptions defined by interface.Nrd)rrrrrnamesAndDescriptionsrs rrz#InterfaceClass.namesAndDescriptions?ss<<%%' ' NN4R4( ;D HHT$33C89 : ; wwyrcB|j|}||St|)z4Return the attribute description for the given name.)r:r6r+r~rs rgetDescriptionForz InterfaceClass.getDescriptionForLs# HHTN =Htnrc(|j|duSrEr:r+r~s r __contains__zInterfaceClass.__contains__Vsxx~T))rc8|jj|SrE)rr:rs rrzInterfaceClass.directYs||%%rc&|j||SrEr)r+r~r;s rqueryDescriptionForz"InterfaceClass.queryDescriptionFor\sxxg&&rc|jD]"}|jddD] } || $|r t|y#t$r}||j|nYd}~Ad}~wwxYw)z&validate object to defined invariants.rr>N)rQrHrr)r+rerrorsrrerrors rvalidateInvariantsz!InterfaceClass.validateInvariants_s\\ E"99,K  cN   &/ !  ) e,-sA A( A##A(cl|jD]$}|j|t}|tus"|cS|S)z Queries for the value associated with *tag*, returning it from the nearest interface in the ``__iro__``. If not found, returns *default*. )rQrHr)r+r7r;rr s rr<zInterfaceClass.queryTaggedValueos=\\ E00g>EG#  rcZ|j|t}|tur t||S)r5)r;)r<rr6rBs rr8zInterfaceClass.getTaggedValue|s.%%c7%; G 3-  rczt}|jD]!}|j|j#|S)z Returns a list of all tags. )setrQrrJ)r+r?rs rr@z!InterfaceClass.getTaggedValueTagss6uLL 9D KK557 8 9 rc |jS#t$r=t|}dj|jj |}||_|cYSwxYw)Nz<{} {}>)_v_reprrerr __class__r(rs rrzInterfaceClass.__repr__sQ <<  t9D  !8!8$?ADLH  s AAAc^|j}|j}|rdj||}|S)Nr)r(r{r)r+r~ms r__str__zInterfaceClass.__str__s.}}    >>!T*D rcv ||S#t$r%tjdjYywxYw)N)rrexc_infotb_nextrs rrzInterfaceClass._call_conformsH 4=  ||~a ((45  s  +88c|jSrEr.r/s r __reduce__zInterfaceClass.__reduce__s }}r)Nr>NNN)r>NNN)FrE)r(rFrGr)rr,rrr r rrrr __getitem__rrr"r&r<r8r@rr0rr6r>rrrrs?C0<<@ 1?f 8 4 * $K*&'" &r Interfacezzope.interface)rFctfSrE)r8r>rrrrsI<rceZdZdZy)rz_ Marker class for interfaces with custom methods that override InterfaceClass methods. N)r(rFrGr)r>rrrrsrrc&eZdZdZdZdZdZdZy)rzAttribute descriptions Ncy)z/Return extra data to put at the end of __str__.rDr>r/s r _get_str_infozAttribute._get_str_infosrcd}|j3|jjdz|jjzdz}||jxsdz|jzS)NrD.z )r]rFr(r=)r+ofs rr0zAttribute.__str__s[  >> %**S04>>3J3JJSPBT]]1k2T5G5G5IIIrcdjt|jt|jt ||S)Nz<{}.{} object at 0x{:x} {}>)rrrFr(idr/s rrzAttribute.__repr__s9,33 J ! ! J   tH    r)r(rFrGr)r]r=r0rr>rrrrsIJ rrc`eZdZdZdxZZdxZxZZdZ dZ dZ e e e e Z dZdZd ZeZy) MethodzMethod interfaces The idea here is that you have objects that describe methods. This provides an opportunity for rich meta-data. r>Nc6|jiS|jSrE _optionalr/s r _get_optionalzMethod._get_optionals >> !I~~rc||_yrErF)r+opts r _set_optionalzMethod._set_optionals rcd|_yrErFr/s r _del_optionalzMethod._del_optionals rcBt|j|jrE)BrokenImplementationr]r()r+argskws rr`zMethod.__call__s"4>>4==AArcv|j|j|j|j|jdS)N positionalrequiredoptionalvarargskwargsrSr/s rgetSignatureInfozMethod.getSignatureInfos/"oo MM MM<<++  rc g}|jD]V}|j|||jjvs1|dxxdt |j|zz cc<X|j r|jd|j z|j r|jd|j zddj|zS)Nrd=*z**z(%s)z, )rTrrVr?reprrWrXjoin)r+sigvs rgetSignatureStringzMethod.getSignatureStrings 8A JJqMDMM&&((B3dmmA&6!777 8 << JJsT\\) * ;; JJtdkk) * #&&r)r(rFrGr)rTrUrGrWrXrHrKrMrrVr`rYrar=r>rrrDrDsVJ#''I'& }mDHB ''MrrDc |xs |j}t||j}t|ddxsd}|j}|j |z }|j |d}i} t|} | s t|dd} || z } | dkr|| d}d} | jtt|| d||d||_ |d| |_ | |_ |} |jtzr|| |_| dz} nd|_|jt"zr || |_nd|_||_|j(j+D]\} }|j-| ||S)N __defaults__r>__defaults_count__rr)r(rDr)getattr__code__ co_argcount co_varnameslenrrziprTrUrVco_flags CO_VARARGSrWCO_VARKEYWORDSrXr]rrrC)rr]imlevelr~methoddefaultscodenarrJdefaults_countnrargnorr s rrrsr  4==D D$,, 'Ft^T28bH ==D  G #B   WX &E C]N !';Q? n B AvRCD> JJtCbc H-./cr FCRjFOFO E }}z!u  }}~%e    Fmm))+* Uc5)* Mrc^t|tr |j}n|}t||d|S)Nr)rnr~)rr__func__r)methr]r~rs r fromMethodryDs+$ #}} i >>rcddlm}ddlm}|t|ddlm}|t |ddlm}|t|ddlm }|t|ddlm }|t|y)Nr)classImplements)IElement) IAttribute)IMethod)ISpecification) IInterface) zope.interface.declarationsr{zope.interface.interfacesr|r$r}rr~rDrr rr)r{r|r}r~rrs r_wirerMsF;2GX&4Iz*1FG$8M>24NJ/r)rY)rU)r)rO)_empty)NrNr)5r)rtypesrrrzope.interface._compatrzope.interface.exceptionsrzope.interface.rorrzope.interface__all__rlrmrrobjectrrrr"r$SpecificationBasePyrLrbrzr r rrrrrr8rrrRrrrrDrryrrrYrUrrOrr>rrrs .-0  + + (!!:2:2z ++ +\KK\ M02EM M^B0 T1%T1ne $e P*M7+" !$D(DL ;3C D /  )YL(((  ~   >0'Y0'f1h?0*626: / ff%r