Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/spread/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/spread/util.pyc


[XMc@sdZddlmZddlmZddlmZddlmZddlm	Z	ddl
mZddd	YZd
ddYZ
ddd
YZdddYZdefdYZdefdYZdejfdYZdZdS(s
Utility classes for spread.
i(tdefer(tFailure(tpb(tbasic(t
interfaces(t
implementstLocalMethodcBseZdZdZRS(cCs||_||_dS(N(tlocaltname(tselfRR((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyt__init__s	cOs|jj|j||S(N(Rt
callRemoteR(R	targstkw((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyt__call__s(t__name__t
__module__R
R(((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyRs	t
LocalAsRemotecBs&eZdZdZdZdZRS(sN
    A class useful for emulating the effects of remote behavior locally.
    icOst|d|r-t|d|||Sy-t|d|}tj|||SWn0t}|jr|jntj|SXdS(sx
        Call a specially-designated local method.

        self.callRemote('x') will first try to invoke a method named
        sync_x and return its result (which should probably be a
        Deferred).  Second, it will look for a method called async_x,
        which will be called and then have its result (or Failure)
        automatically wrapped in a Deferred.
        tsync_tasync_N(thasattrtgetattrRtsucceedRtreportAllTracebackstprintTracebacktfail(R	RRR
tmethodtf((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR#s
		
cCs
t||S(N(R(R	R((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytremoteMethod8s(RRt__doc__RRR(((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyRs	tLocalAsyncForwardercBs,eZdZddZdZdZRS(sD
    A class useful for forwarding a locally-defined interface.
    icCs4|j|st||_||_||_dS(N(t
providedBytAssertionErrort	forwardedtinterfaceClasstfailWhenNotImplemented(R	R!R"R#((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
As		cOst|j|||S(N(RR!(R	RRR
((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyt_callMethodGscOse|jj|r1tj|j|||}|S|jrTtjttd|Stj	dSdS(NsNo Such Method in Interface: %s(R"tqueryDescriptionForRt
maybeDeferredR$R#RRtNotImplementedErrorRtNone(R	RRR
tresult((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyRJs	(RRRR
R$R(((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR<s	tPagercBs>eZdZddZdZdZdZdZRS(s5
    I am an object which pages out information.
    cOsYt|r*||_||_||_n	d|_d|_||_|jj|dS(s
        Create a pager with a Reference to a remote collector and
        an optional callable to invoke upon completion.
        iN(	tcallabletcallbacktcallbackArgstcallbackKeywordR(t_stillPagingt	collectortbrokertregisterPageProducer(R	R0R,RR
((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
Zs					cCsK|jsD|jjd|jdk	rD|j|j|jqDn|jS(s5
        (internal) Method called by Broker.
        tendedPagingN(R/R0RR,R(R-R.(R	((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytstillPagingis
	cCs|jjd|jdS(s5
        (internal) Method called by Broker.
        tgotPageN(R0RtnextPage(R	((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytsendNextPagesscCs
tdS(sO
        Override this to return an object to be sent to my collector.
        N(R'(R	((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR6yscCs
d|_dS(s4
        Call this when you're done paging.
        iN(R/(R	((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyt
stopPagingsN(	RRRR(R
R4R7R6R8(((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR*Vs	
		tStringPagercBs&eZdZdddZdZRS(s:
    A simple pager that splits a string into chunks.
    i cOs8||_d|_||_tj|||||dS(Ni(tstringtpointert	chunkSizeR*R
(R	R0tstR<R,RR
((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
s			cCsX|j|j|j|j!}|j|j7_|jt|jkrT|jn|S(N(R:R;R<tlenR8(R	tval((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR6s

N(RRRR(R
R6(((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR9st	FilePagercBsTeZdZeejddZdZdZ	dZ
dZdZRS(sC
    Reads a file in chunks and sends the chunks as they come.
    cOs3g|_tj||||||j|dS(N(tchunksR*R
tstartProducing(R	R0tfdR,RR
((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
s	cs8tjj|_jjfddS(Ncs
jS(N(R8(tx(R	(s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyt<lambda>s(Rt
FileSendertbeginFileTransfertdeferredtaddBoth(R	RC((R	s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyRBscCs#||_|s|jjndS(N(tproducertresumeProducing(R	RJt	streaming((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytregisterProducers	cCs
d|_dS(N(R(RJ(R	((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytunregisterProducerscCs|jj|dS(N(RAtappend(R	tchunk((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytwritescCsC|js
dS|jjd}|jj|jjd|dS(sD
        Get the first chunk read and send it to collector.
        NiR5(RAtpopRJRKR0R(R	R?((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR7s
	
N(
RRRRRt	IConsumerR(R
RBRMRNRQR7(((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR@s
				tCallbackPageCollectorcBs)eZdZdZdZdZRS(s
    I receive pages from the peer. You may instantiate a Pager with a
    remote reference to me. I will call the callback with a list of pages
    once they are all received.
    cCsg|_||_dS(N(tpagesR,(R	R,((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
s	cCs|jj|dS(N(RURO(R	tpage((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytremote_gotPagescCs|j|jdS(N(R,RU(R	((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytremote_endedPagings(RRRR
RWRX(((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyRTs		cOs/tj}|j|t|j|||S(sr
    A utility method that will call a remote method which expects a
    PageCollector as the first argument.
    (RtDeferredRRTR,(t
referenceablet
methodNameRR
td((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pytgetAllPagessN(((((Rttwisted.internetRttwisted.python.failureRttwisted.spreadRttwisted.protocolsRRtzope.interfaceRRRRR*R9R@t
ReferenceableRTR](((s7/usr/lib/python2.7/dist-packages/twisted/spread/util.pyt<module>	s	0&