TJJc@sdZddklZddkZddkZddkZddklZddklZddk l Z dZ dZ d Z eZd Zd Zd efd YZdefdYZeZeZdefdYZeZgZyddkZWnej on(XddklZddklZlZdefdYZdeeefdYZedddZdefdYZdefdYZe de d Z!e e d!Z"d"Z#dd#k$l%Z%l&Z&dd$k l'Z'dd%k l(Z(dS(&sWInterface object implementation $Id: interface.py 82877 2008-01-14 20:58:02Z witsch $ i(t generatorsN(t FunctionType(tro(tInvalidiit__interface_tagged_values__cCsGtidi}|ith}|idg}|i|tS(Nit invariants(tsyst _getframetf_localst setdefaultt TAGGED_DATAtappendt_decorator_non_return(tcallRttagsR((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt invariant#s  cCs2tidi}|ith}|||/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt taggedValue+s tElementcBsMeZddZdZdZdZddZdZdZ RS( tcCsM| o&|iddjo|}d}n||_||_h|_dS(s*Create an 'attribute' description t iN(tfindtNonet__name__t__doc__t_Element__tagged_values(tselfRR((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt__init__:s    cCs|iS(s! Returns the name of the object. (R(R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytgetNameEscCs|iS(s+ Returns the documentation for the object. (R(R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytgetDocIscCs |i|S(s* Returns the value associated with 'tag'. (R(Rttag((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytgetTaggedValueMscCs|ii||S(s* Returns the value associated with 'tag'. (Rtget(RR tdefault((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytqueryTaggedValueQscCs |iiS(s Returns a list of all tags. (Rtkeys(R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytgetTaggedValueTagsUscCs||i|/usr/lib64/python2.6/site-packages/zope/interface/interface.pytsetTaggedValueYsN( Rt __module__RRRR!RR$R&R'(((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR3s     tSpecificationBasePycBs)eZdZdZdZeZRS(cCst|}||ijS(soIs the interface implemented by an object >>> from zope.interface import * >>> class I1(Interface): ... pass >>> class C(object): ... implements(I1) >>> c = C() >>> class X(object): ... pass >>> x = X() >>> I1.providedBy(x) False >>> I1.providedBy(C) False >>> I1.providedBy(c) True >>> directlyProvides(x, I1) >>> I1.providedBy(x) True >>> directlyProvides(C, I1) >>> I1.providedBy(C) True (t providedByt_implied(Rtobtspec((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR*_s cCst|}||ijS(sTest whether the specification is implemented by a class or factory. Raise TypeError if argument is neither a class nor a callable.(t implementedByR+(RtclsR-((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR.|s cCs ||ijS(sIs the interface the same as or extend the given interface Examples:: >>> from zope.interface import Interface >>> from zope.interface.declarations import Declaration >>> class I1(Interface): pass ... >>> class I2(I1): pass ... >>> class I3(Interface): pass ... >>> class I4(I3): pass ... >>> spec = Declaration() >>> int(spec.extends(Interface)) 1 >>> spec = Declaration(I2) >>> int(spec.extends(Interface)) 1 >>> int(spec.extends(I1)) 1 >>> int(spec.extends(I2)) 1 >>> int(spec.extends(I3)) 0 >>> int(spec.extends(I4)) 0 (R+(Rt interface((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt isOrExtendss(RR(R*R.R1t__call__(((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR)]s   !tInterfaceBasePycBs#eZdZedZdZRS(s:Base class that wants to be replaced with a C base :) cCst|dd}|dj o%|i|}|dj o|Sn|i|}|dj o|S|tj o|Std||dS(s)Adapt an object to the interface t __conform__sCould not adaptN(tgetattrRt _call_conformt __adapt__t_markert TypeError(Rtobjt alternatetconformtadapter((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR2s     cCsK|i|o|Sx/tD]'}|||}|dj o|SqWdS(s(Adapt an object to the reciever N(R*t adapter_hooksR(RR:thookR=((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR7s (RR(RR8R2R7(((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR3s (tSpecificationBase(t InterfaceBaseR>t SpecificationcBseZdZeiZeiZd dZdZdZdZ e de Z dZ dZ edZd d Zd d ZRS( sISpecifications 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 cases, their relations with other specifications are adjusted accordingly. For example: >>> from zope.interface import Interface >>> class I1(Interface): ... pass >>> class I2(I1): ... pass >>> class I3(I2): ... pass >>> [i.__name__ for i in I1.__bases__] ['Interface'] >>> [i.__name__ for i in I2.__bases__] ['I1'] >>> I3.extends(I1) 1 >>> I2.__bases__ = (Interface, ) >>> [i.__name__ for i in I2.__bases__] ['Interface'] >>> I3.extends(I1) 0 cCs+h|_ti|_t||_dS(N(R+tweakreftWeakKeyDictionaryt dependentsttuplet __bases__(Rtbases((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRs cCs$|ii|dd|i|/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt subscribescCs\|ii|dd}|p|i|=n+|djo||i|/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt unsubscribe s  cCs]x|iD]}|i|q W||id/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt __setBasess  cCs|iiddS(RG((RNR"(R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt!sc Cs|i}|it|}y"t|jo|itnWntj onXt||_tg}|D]!}t|t o ||qtqt~|_ x|D]}d||/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRO%s"    *ccsUh}xH|iD]=}x4|iD]&}||jod||<|Vq#q#WqWdS(sReturn an iterator for the interfaces in the specification for example:: >>> from zope.interface import Interface >>> class I1(Interface): pass ... >>> class I2(I1): pass ... >>> class I3(Interface): pass ... >>> class I4(I3): pass ... >>> spec = Specification((I2, I3)) >>> spec = Specification((I4, spec)) >>> i = spec.interfaces() >>> i.next().getName() 'I4' >>> i.next().getName() 'I2' >>> i.next().getName() 'I3' >>> list(i) [] iN(RGt interfaces(RtseentbaseR0((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR_Bs    cCs"||ijo| p ||jS(sDoes the specification extend the given interface? Test whether an interface in the specification extends the given interface Examples:: >>> from zope.interface import Interface >>> from zope.interface.declarations import Declaration >>> class I1(Interface): pass ... >>> class I2(I1): pass ... >>> class I3(Interface): pass ... >>> class I4(I3): pass ... >>> spec = Declaration() >>> int(spec.extends(Interface)) 1 >>> spec = Declaration(I2) >>> int(spec.extends(Interface)) 1 >>> int(spec.extends(I1)) 1 >>> int(spec.extends(I2)) 1 >>> int(spec.extends(I3)) 0 >>> int(spec.extends(I4)) 0 >>> I2.extends(I2) 0 >>> I2.extends(I2, False) 1 >>> I2.extends(I2, strict=False) 1 (R+(RR0tstrict((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytextendsds(cCsti||S(N(RCtref(Rtcallback((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRCscCsy |i}Wn tj oh}|_nX|i|}|djoCx@|iD]1}|i|}|dj o|||/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR"s       (N(RR(RR@R1R*RRJRMt_Specification__setBasestpropertyRGROR_tTrueRcRRCR"(((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRBs'        " - RXcBseZdZdddddZdZdZdZedZ dZ edZ dZ e Z d Zd Zdd Zd Zdd ZdZdZdZdZdZdZdZdZRS(s0Prototype (scarecrow) Interfaces Implementation.c Csj|djo h}n|djod|id}t|to |d=qytidid}Wqttfj oqXn||_ |id}|dj o6t|t p"|djo |}n|d=qn|djo d}nt i ||||i td}|dj o1x.|iD]\}} |i|| q9Wnx.|D]&} t| tptdqdqdWti ||x|iD]\}} t| t o$|| _| ip || _q@qt| tot| |d|||/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRsV                   ccs |VdS(sGReturn an iterator for the interfaces in the specification for example:: >>> from zope.interface import Interface >>> class I1(Interface): pass ... >>> >>> i = I1.interfaces() >>> i.next().getName() 'I1' >>> list(i) [] N((R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR_scCs|iS(N(RG(R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytgetBasesscCs||jp |i|S(sSame interface or extends?(Rc(Rtother((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytisEqualOrExtendedByscCsa|p|iiS|ii}x0|iD]%}|iti|i|q.W|iS(s4Return the attribute names defined by the interface.(RwR%tcopyRGtupdatetdicttfromkeystnames(RtalltrRa((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRs #cCst|idtS(NR(titerRRo(R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt__iter__scCsr|p|iiSh}x:|idddD]"}|it|i|q2W|i|i|iS(s=Return attribute names and descriptions defined by interface.Ni(RwRtRGRRtnamesAndDescriptions(RRRRa((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRs cCs1|i|}|dj o|St|dS(s4Return the attribute description for the given name.N(R"RRK(RRiR((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytgetDescriptionFor"s cCs|i|dj S(N(R"R(RRi((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt __contains__,scCs|ii|S(N(RwR"(RRi((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRh/scCs|i||S(N(R"(RRiR#((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytqueryDescriptionFor2scBsWe|do|iSh}d|i|U||i}|i|i||_|S(s6Return a defered class corresponding to the interface.t _deferredsclass %s: pass(thasattrRRt_InterfaceClass__dRN(Rtklass((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytdeferred5s  c Csxa|idgD]M}y||Wqtj o*}|djoq`|i|qXqWxO|iD]D}y|i||Wqntj o|djoqqnXqnW|ot|ndS(s&validate object to defined invariants.RN(R$RRR RGtvalidateInvariants(RR:terrorsR teRa((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRCs"   cCsdS(sRetrieve a named interface.N(R(RR,Ri((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt _getInterfaceVscCspxH|iiD]7\}}t|to||jo|||/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt__dZs  cCsry |iSWn`tj oT|i}|i}|od||f}nd|ii|f}||_|SXdS(Ns%s.%ss<%s %s>(t_v_reprRgRR(t __class__(RRitmR((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt__repr__cs    cCsIy||SWn4tj o(tididj oqEnXdS(Ni(R9Rtexc_infottb_nextR(RR<((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR6os  cCs|iS(N(R(R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt __reduce__scCs||jodS|djodS|djodSt|ddtt|ddddf}t|ddtt|ddddf}t||S(sMake 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. iiiRRR(N(RR5tcmp(Rto1to2tn1tn2((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt__cmps   !!cCs|i||}|djS(Ni(t_InterfaceClass__cmp(RR}tc((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt__lt__scCs|i||}|djS(Ni(R(RR}R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt__gt__s(N(RR(RRRR_R|R~tFalseRRRRt __getitem__RRhRRRRRRR6RRRR(((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRXs0  =              % RTR(szope.interfaceRrcBseZdZdZRS(sAttribute descriptions N(RR(RRR0(((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRrsRcBs)eZdZdZdZdZRS(sMethod interfaces The idea here is that you have objects that describe methods. This provides an opportunity for rich meta-data. cOst|i|idS(N(tBrokenImplementationR0R(Rtargstkw((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyR2scCs6h|id6|id6|id6|id6|id6S(Nt positionaltrequiredtoptionaltvarargstkwargs(RRRRR(R((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytgetSignatureInfos     cCsg}xT|iD]I}|i|||iijo |dcd|i| 7/usr/lib64/python2.6/site-packages/zope/interface/interface.pytgetSignatureStrings  $  (RR(RR2RR(((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRs  ic Csm|p|i}t||i}|ipd}|i}|i|}|i|}h} |t|} | djo|| }d} n| it t || ||| |_ || |_ | |_ |} |it@o|| |_| d} n d|_|it@o|| |_n d|_||_x-|iiD]\} } |i| | qIW|S(Nii((RRRt func_defaultst func_codet co_argcountt co_varnamestlenRRtzipRRRtco_flagst CO_VARARGSRRtCO_VARKEYWORDSRR0RNRtR'(tfuncR0timlevelRitmethodtdefaultstcodetnaRtopttnrtargnoRR((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyRus8               cCs"|i}t||ddd|S(NRiRi(tim_funcRu(tmethR0RiR((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt fromMethods cCs~ddkl}ddkl}|t|ddkl}|t|ddkl}l}|t ||t |dS(Ni(tclassImplements(t IAttribute(tIMethod(t IInterfacetISpecification( tzope.interface.declarationsRtzope.interface.interfacesRRrRRRRRXRB(RRRRR((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pyt_wires   (R*R.(Rv(R()Rt __future__RRtwarningsRCttypesRRtzope.interface.exceptionsRRRR tobjectR RRRR)R@R8R3RAR>t_zope_interface_coptimizationst ImportErrorRBRXRTRrRRRuRRRR*R.RvR(((s>/usr/lib64/python2.6/site-packages/zope/interface/interface.pytsL      *H ! %-