m Ec @sVdZdklZdklZdkZdklZlZdk l Z de fdYZ e Z daee d ddjo d Zn d Zd Zd Ze idZeiiedZdZdZeZdfdYZdeifdYZdefdYZ dddddddddg Z!dS(sBComponent architecture for Twisted, based on Zope3 components. Using the Zope3 API directly is strongly recommended. Everything you need is in the top-level of the zope.interface package, e.g.:: from zope.interface import Interface, implements class IFoo(Interface): pass class Foo: implements(IFoo) print IFoo.implementedBy(Foo) # True print IFoo.providedBy(Foo()) # True The one exception is L{twisted.python.components.registerAdapter}, which is still the way to register adapters (at least, if you want Twisted's global adapter registry). (sreflect(sstylesN(s interfaces declarations(sAdapterRegistrytComponentsDeprecationWarningcBstZdZRS(s#Nothing emits this warning anymore.(t__name__t __module__t__doc__(((tq/home/radix/Projects/Twisted/branches/releases/twisted-core-2.5.x-2329-2/Twisted.exp/twisted/python/components.pyR's it registeredcCs%|i|ii|hidS(s Return the adapter factory for the given parameters in the given registry, or None if there is not one. tN(tregistrytgettrequiredt selfImpliedtprovided(RR R ((Rt _registered5scCs|i|g|S(s Return the adapter factory for the given parameters in the given registry, or None if there is not one. N(RRR R (RR R ((RR <scGst}|p tdt|tipti |}nxL|D]D}t |||}|dj ot otd|fqDqDWx'|D]}|i|g|d|qWdS(s Register an adapter class. An adapter class is expected to implement the given interface, by adapting instances implementing 'origInterface'. An adapter class's __init__ method should accept one parameter, an instance implementing 'origInterface'. sYou need to pass an Interfaces'an adapter (%s) was already registered.RN(tglobalRegistrytselftinterfaceClassestAssertionErrort isinstancet origInterfacet interfacetInterfaceClasst declarationst implementedBytinterfaceClassR tfactorytNonetALLOW_DUPLICATESt ValueErrortregistertadapterFactory(RRRRRR((RtregisterAdapterDscCsYt}t|tipti|}n|i||}|djo |}n|S(sReturn registered adapter for a given class and interface. Note that is tied to the *Twisted* global registry, and will thus not find adapters registered elsewhere. N( R RRt fromInterfaceRRRRtlookup1t toInterfaceRRtdefault(RR!R"RR((RtgetAdapterFactory\s  cCs;|ti||}|djodSn ||SdS(N(tlookupRt providedBytobtifaceRR(R'R&R$R((Rt_hookls cCstidtdddS(sDEPRECATED. Does nothing. Previously handled backwards compat from a zope.interface using class to a class wanting old twisted components interface behaviors. sYcomponents.backwardsCompatImplements doesn't do anything in Twisted 2.3, stop calling it.t stackleveliN(twarningstwarnR(tklass((RtbackwardsCompatImplementswscCstidtdddS(snDEPRECATED. Does nothing. Previously converted class from __implements__ to zope implementation. sRcomponents.fixClassImplements doesn't do anything in Twisted 2.3, stop calling it.R)iN(R*R+R(R,((RtfixClassImplementsscCstS(sWReturns the Twisted global C{zope.interface.adapter.AdapterRegistry} instance. N(R (((Rt getRegistrystAdaptercBs5tZdZdZdZdZdZdZRS(s/I am the default implementation of an Adapter for some interface. This docstring contains a limerick, by popular demand:: Subclassing made Zope and TR much harder to work with by far. So before you inherit, be sure to declare it Adapter, not PyObject* @cvar temporaryAdapter: If this is True, the adapter will not be persisted on the Componentized. @cvar multiComponent: If this adapter is persistent, should it be automatically registered for all appropriate interfaces. iicCs ||_dS(sDSet my 'original' attribute to be the object I am adapting. N(toriginalR(RR1((Rt__init__scCs+t|ido|ii|SndS(sn I forward __conform__ to self.original if it has it, otherwise I simply return None. t __conform__N(thasattrRR1R3RR(RR((RR3scCs|ii||S(s1 Forward isuper to self.original N(RR1tisuperR'tadapter(RR'R6((RR5s(RRRttemporaryAdaptertmultiComponentR2R3R5(((RR0s   t ComponentizedcBswtZdZdZdZdZdZddZdZddZ d Z d Z e d Z d ZRS( sI am a mixin to allow you to be adapted in various ways persistently. I define a list of persistent adapters. This is to allow adapter classes to store system-specific state, and initialized on demand. The getComponent method implements this. You must also register adapters for this class for the interfaces that you wish to pass to getComponent. Many other classes and utilities listed here are present in Zope3; this one is specific to Twisted. icCs h|_dS(N(Rt _adapterCache(R((RR2scCst|||S(N(R#R,RR"(RR,RR"((RtlocateAdapterClassscCs|i|||dS(N(Rt setComponentRt adapterClass(RRR=((Rt setAdaptersicCs ||}|i|||S(sUtility method that calls addComponent. I take an adapter class and instantiate it with myself as the first argument. @return: The adapter instantiated. N(R=Rtadaptt addComponentt ignoreClass(RR=RAR?((Rt addAdapters cCs||iti|RBR<R@RGRNRRQR3(((RR9s         !tReprableComponentizedcBstZdZdZRS(NcCsti|dS(N(R9R2R(R((RR21scCs=dkl}dkl}|}||i||iS(N(sStringIO(spprint(t cStringIOtStringIOtpprinttsioRR:tgetvalue(RRVRWRU((Rt__repr__4s    (RRR2RY(((RRS0s RR#R/R-R.("Rttwisted.pythonRDttwisted.persistedtstylesR*tzope.interfaceRRtzope.interface.adaptertAdapterRegistrytDeprecationWarningRR RtgetattrRR RR#R R(t adapter_hooksRLR-R.R/t TypeErrort CannotAdaptR0t VersionedR9RSt__all__(R_RfR\R*R0RSR(RRRdR R.RDR#R RRR/R-R9((Rt?s.          +s