Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/zope/interface/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/zope/interface/interface.pyc


Kc@s>dZddlmZddlZddlmZddlZddlmZddl	m
Z
dZdZd	Z
eZd
ZdZdefd
YZdefdYZeZyddlmZWnek
rnXeZdefdYZeZyddlmZWnek
r1nXgZyddlmZWnek
r_nXdefdYZdeeefdYZedddZdefdYZdefdYZe d e d!Z!e e d"Z"d#Z#dd$l$m%Z%dd%l$m&Z&dd&lm'Z'dd'lm(Z(dS((s Interface object implementation
i(t
generatorsN(tFunctionType(tInvalid(troiit__interface_tagged_values__cCsGtjdj}|jti}|jdg}|j|tS(Nit
invariants(tsyst	_getframetf_localst
setdefaulttTAGGED_DATAtappendt_decorator_non_return(tcallRttagsR((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt	invariant s

cCs2tjdj}|jti}|||<tS(s;Attaches a tagged value to an interface at definition time.i(RRRR	R
R(tkeytvalueRt
tagged_values((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyttaggedValue(s
tElementcBsMeZddZdZdZdZddZdZdZ	RS(	tcCsJ|r+|jddkr+|}d}n||_||_i|_dS(s*Create an 'attribute' description
        t iN(tfindtNonet__name__t__doc__t_Element__tagged_values(tselfRR((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt__init__7s			cCs|jS(s! Returns the name of the object. (R(R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytgetNameBscCs|jS(s+ Returns the documentation for the object. (R(R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytgetDocFscCs|j|S(s* Returns the value associated with 'tag'. (R(Rttag((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytgetTaggedValueJscCs|jj||S(s* Returns the value associated with 'tag'. (Rtget(RR tdefault((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytqueryTaggedValueNscCs
|jjS(s Returns a list of all tags. (Rtkeys(R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytgetTaggedValueTagsRscCs||j|<dS(s  Associates 'value' with 'key'. N(R(RR R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytsetTaggedValueVsN(
Rt
__module__RRRR!RR$R&R'(((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR0s				tSpecificationBasePycBs)eZdZdZdZeZRS(cCst|}||jkS(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/lib/python2.7/dist-packages/zope/interface/interface.pyR*\scCst|}||jkS(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/lib/python2.7/dist-packages/zope/interface/interface.pyR.yscCs
||jkS(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/lib/python2.7/dist-packages/zope/interface/interface.pytisOrExtendss(RR(R*R.R1t__call__(((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR)Zs			!(tSpecificationBasetInterfaceBasePycBs#eZdZedZdZRS(s:Base class that wants to be replaced with a C base :)
    cCst|dd}|dk	r@|j|}|dk	r@|Sn|j|}|dk	r_|S|tk	ro|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/lib/python2.7/dist-packages/zope/interface/interface.pyR2scCsG|j|r|Sx-tD]%}|||}|dk	r|SqWdS(s(Adapt an object to the reciever
        N(R*t
adapter_hooksR(RR;thookR>((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR8s
(RR(RR9R2R8(((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR4s(t
InterfaceBase(R?t
SpecificationcBseZdZejZejZddZdZdZdZ	e
de	ZdZ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+i|_tj|_t||_dS(N(R+tweakreftWeakKeyDictionaryt
dependentsttuplet	__bases__(Rtbases((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRs	cCs$|jj|dd|j|<dS(Nii(RER"(Rt	dependent((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt	subscribescCsX|jj|dd}|s,|j|=n(|dkrH||j|<nt|dS(Nii(RER"tKeyError(RRItn((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytunsubscribes
cCs]x|jD]}|j|q
W||jd<x|D]}|j|q5W|j|dS(NRG(RGRMt__dict__RJtchanged(RRHtb((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt
__setBasess

cCs|jjddS(NRG((RNR"(R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt<lambda>%scCsy
|`Wntk
rnX|j}|jt|}y t|kr\|jtnWntk
rpnXt||_	tg|D]}t
|tr|^q|_x|D]}d||<qWx$|j
jD]}|j|qWdS(s4We, or something we depend on, have changed
        N((t_v_attrstAttributeErrorR+tclearRt	InterfaceRt	NameErrorRFt__sro__t
isinstancetInterfaceClasst__iro__RER%RO(Rtoriginally_changedtimpliedt	ancestorstancestorRI((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRO)s&

	

!
ccsSi}xF|jD];}x2|jD]$}||kr#d||<|Vq#q#WqWdS(s?Return 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()
          >>> [x.getName() for x in i]
          ['I4', 'I2', 'I3']
          >>> list(i)
          []
        iN(RGt
interfaces(RtseentbaseR0((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR`Js
cCs ||jko|p||kS(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/lib/python2.7/dist-packages/zope/interface/interface.pytextendshs(cCstj||S(N(RCtref(Rtcallback((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRCscCsy
|j}Wntk
r-i}|_nX|j|}|dkrx=|jD]/}|j|}|dk	rS|||<PqSqSWn|dkr|S|SdS(s+Query for an attribute description
        N(RSRTR"RR[tdirect(RtnameR#tattrstattrtiface((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR"s


(N(RR(RR3R1R*RRJRMt_Specification__setBasestpropertyRGROR`tTrueRdRRCR"(((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRBs'								!	-RZcBseZdZdddddZdZdZdZedZ	dZ
edZdZeZ
d	Zd
ZddZdZdd
ZdZdZdZdZdZdZdZdZRS(s0Prototype (scarecrow) Interfaces Implementation.cCs`|dkri}n|dkr|jd}t|trI|d=qytjdjd}Wqttfk
r|qXn||_	|jd}|dk	rt|t
s|dkr|}n|d=qn|dkrd}ntj||||j
td}|dk	rKx-|jD]\}}	|j||	q(Wnx,|D]$}
t|
tsRtdqRqRWtj||x|jD]\}}|dkrqnt|t
r||_|js6||_q6qt|trt||d|||<q|tkr&||=qtd	|qW||_d
|j	|jf|_dS(NR(iRRRsExpected base interfacest
__locals__RhsConcrete attribute, s%s.%s(RR"RYtstrRRt	f_globalsRTRKR(t	AttributeRRtpopR
titemsR'RZR:RBR0RRtfromFunctionRtInvalidInterfacet_InterfaceClass__attrst__identifier__(RRhRHRiRR(tdttagged_dataRtvalRbRj((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRsT	
		
	
		
	ccs	|VdS(sOReturn an iterator for the interfaces in the specification

        for example::

          >>> from zope.interface import Interface
          >>> class I1(Interface): pass
          ...
          >>>
          >>> i = I1.interfaces()
          >>> [x.getName() for x in i]
          ['I1']
          >>> list(i)
          []
        N((R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR`scCs|jS(N(RG(R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytgetBasesscCs||kp|j|S(sSame interface or extends?(Rd(Rtother((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytisEqualOrExtendedBy	scCs_|s|jjS|jj}x0|jD]%}|jtj|j|q,W|jS(s4Return the attribute names defined by the interface.(RwR%tcopyRGtupdatetdicttfromkeystnames(RtalltrRb((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR
s
#cCst|jdtS(NR(titerRRn(R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt__iter__scCsp|s|jjSi}x:|jdddD]"}|jt|j|q0W|j|j|jS(s=Return attribute names and descriptions defined by interface.Ni(RwRtRGRRtnamesAndDescriptions(RRRRb((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRs
 cCs/|j|}|dk	r|St|dS(s4Return the attribute description for the given name.N(R"RRK(RRhR((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytgetDescriptionFor)scCs|j|dk	S(N(R"R(RRh((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt__contains__3scCs|jj|S(N(RwR"(RRh((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRg6scCs|j||S(N(R"(RRhR#((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytqueryDescriptionFor9scBsRe|dr|jSi}d|j|U||j}|j|||_|S(s6Return a defered class corresponding to the interface.t	_deferredsclass %s: pass(thasattrRRt_InterfaceClass__d(Rtklass((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytdeferred<s

	cCsx]|jdgD]I}y||Wqtk
r[}|dkrKq\|j|qXqWxK|jD]@}y|j||Wqjtk
r|dkrqqjXqjW|rt|ndS(s&validate object to defined invariants.RN(R$RRRRGtvalidateInvariants(RR;terrorsR
teRb((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRJs
cCsdS(sRetrieve a named interface.N(R(RR,Rh((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt
_getInterface]scCsvxN|jjD]=\}}t|tr||jkrt|||qqWx|jD]}|j|q[WdS(N(RwRtRYtMethodRNtsetattrRGR(RRtktvRP((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt__das
cCsny|jSWn\tk
ri|j}|j}|rFd||f}nd|jj|f}||_|SXdS(Ns%s.%ss<%s %s>(t_v_reprRTRR(t	__class__(RRhtmR((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt__repr__is
			cCsEy||SWn0tk
r@tjdjdk	rAqAnXdS(Ni(R:Rtexc_infottb_nextR(RR=((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR7us

cCs|jS(N(R(R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt
__reduce__scCs||krdS|dkr dS|dkr0dSt|ddtt|ddddf}t|ddtt|ddddf}||k||kS(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(RR6(Rto1to2tn1tn2((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt__cmps!!cCs|j||}|dkS(Ni(t_InterfaceClass__cmp(RR}tc((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt__lt__scCs|j||}|dkS(Ni(R(RR}R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt__gt__s(N(RR(RRRR`R|R~tFalseRRRRt__getitem__RRgRRRRRRR7RRRR(((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRZs0	@				
										%	RVR(szope.interfaceRrcBseZdZdZRS(sAttribute descriptions
    N(RR(RRR0(((s</usr/lib/python2.7/dist-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|j|jdS(N(tBrokenImplementationR0R(Rtargstkw((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyR2scCs6i|jd6|jd6|jd6|jd6|jd6S(Nt
positionaltrequiredtoptionaltvarargstkwargs(RRRRR(R((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytgetSignatureInfos




cCsg}xR|jD]G}|j|||jjkr|dcd|j|
7<qqW|jr{|jd|jn|jr|jd|jnddj|S(Nit=t*s**s(%s)s, (RRRR%RRtjoin(RtsigR((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pytgetSignatureStrings
#		(RR(RR2RR(((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRs		icCse|p|j}t||j}|jp-d}|j}|j|}|j|}i}	|t|}
|
dkr||
}d}
n|	jt	t
||
||| |_||
 |_|	|_
|}|jt@r|||_|d}n	d|_|jt@r|||_n	d|_||_x-|jjD]\}}
|j||
qAW|S(Nii((RRRt
func_defaultst	func_codetco_argcounttco_varnamestlenRRtzipRRRtco_flagst
CO_VARARGSRRtCO_VARKEYWORDSRR0RNRtR'(tfuncR0timlevelRhtmethodtdefaultstcodetnaRtopttnrtargnoRR((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyRus6	

	 

	


	
		cCs"|j}t||ddd|S(NRiRh(tim_funcRu(tmethR0RhR((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt
fromMethods	cCsddlm}ddlm}|t|ddlm}|t|ddlm}|t|ddlm	}|t
|dS(Ni(tclassImplements(t
IAttribute(tIMethod(t
IInterface(tISpecification(tzope.interface.declarationsRtzope.interface.interfacesRRrRRRRZRRB(RRRRR((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt_wire!s


(R.(R*(Rv(R()Rt
__future__RRttypesRRCtzope.interface.exceptionsRtzope.interface.roRRRR
tobjectRRRRR)R3t_zope_interface_coptimizationstImportErrorR9R4RAR?RBRZRVRrRRRuRRRR.R*RvR(((s</usr/lib/python2.7/dist-packages/zope/interface/interface.pyt<module>sX			*H
	"

%-