Your IP : 172.28.240.42


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

ó
[³XMc@sSdZddlmZddlmZdd	d„ƒYZdefd„ƒYZdS(
s
Producer-Consumer Proxy.
iÿÿÿÿ(t
implements(t
interfacestBasicProducerConsumerProxycBsœeZdZeejejƒd
Zd
Z	d
Z
eZe
Ze
Ze
Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd	„ZRS(sa
    I can act as a man in the middle between any Producer and Consumer.

    @ivar producer: the Producer I subscribe to.
    @type producer: L{IProducer<interfaces.IProducer>}
    @ivar consumer: the Consumer I publish to.
    @type consumer: L{IConsumer<interfaces.IConsumer>}
    @ivar paused: As a Producer, am I paused?
    @type paused: bool
    cCs8g|_|dk	r4||_|j||jƒndS(N(t_buffertNonetconsumertregisterProducertiAmStreaming(tselfR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyt__init__#s		cCs&t|_|jr"|jjƒndS(N(tTruetpausedtproducertpauseProducing(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR
+s		cCsst|_|jr;|jjdj|jƒƒg|j(n|jsPt|_n|j	dk	ro|j	jƒndS(Nt(tFalseRRRtwritetjoinRR
toutstandingPullRRtresumeProducing(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR0s		
	cCs;|jdk	r|jjƒn|jdk	r7|`ndS(N(RRt
stopProducingR(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR=scCs_|js|jr0|jr0|jj|ƒn+|jdk	r[|jj|ƒt|_ndS(N(	RRRRtappendRRRR(Rtdata((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyREs
cCs-|jdk	r|jjƒn|jƒdS(N(RRtfinishtunregisterProducer(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyRNscCs||_||_dS(N(RtproducerIsStreaming(RRt	streaming((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyRSs	cCs;|jdk	r|`|`n|jr7|jjƒndS(N(RRRRR(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyRWs
		cCsd|jt|ƒ|jfS(Ns<%s@%x around %s>(t	__class__tidR(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyt__repr__^sN(t__name__t
__module__t__doc__RRt	IProducert	IConsumerRRRRR
RRRRtstoppedR	R
RRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyRs$
			
						tProducerConsumerProxycBs^eZdZdddZeZeZd„Zd„Zd„Z	d„Z
d„Zd„ZRS(	s˜ProducerConsumerProxy with a finite buffer.

    When my buffer fills up, I have my parent Producer pause until my buffer
    has room in it again.
    icCs
t|_dS(N(R
R(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR
nscCs^t|_|jr‚dj|jƒ}|j|ƒ}|t|ƒkru||}|jsetdƒ‚|g|j(qˆg|j(nd}|jrÀ|rÀ|jrÀ|j	dk	rÀ|j	jƒn|jsÖ||_n|j
dk	rZtg|jD]}t|ƒ^qòƒ}|jr>||jkr>t|_|j
jƒqZ|jrZ|j
jƒqZndS(NRs.Streaming producer did not write all its data.i(RRRRt_writeSomeDatatlenRtAssertionErrortunregisteredRRRRRtsumtproducerPausedt
bufferSizeR(RRt	bytesSenttunsenttst
bytesBuffered((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyRss.		

	
	
(		cCs|js|jr0|jr0|jj|ƒn|jdk	r¯|jsUtdƒ‚|j|ƒ}t	|_|t
|ƒks¯|js•tdƒ‚|jj||ƒq¯n|jdk	r|jrt
g|jD]}t
|ƒ^qÔƒ}||jkr|jjƒt|_qndS(Ns9Writing fresh data to consumer before my buffer is empty!s.Streaming producer did not write all its data.(RRRRRRRR'R%RR&RRR)R+R
R
R*(RRR,R.R/((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR›s 
		
	(
cCs3t|_tj|||ƒ|s/|jƒndS(N(RR(RRR(RRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR¶s	cCsN|jdk	r|`|`nt|_|jrJ|jrJ|jjƒndS(N(RRRR
R(RRR(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR¼s		cCs-|jdkrdS|jj|ƒt|ƒS(s`Write as much of this data as possible.

        @returns: The number of bytes written.
        iN(RRRR&(RR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR%Äsi(
RRR R+RR*R(R
RRRRR%(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyR$bs		(			N((R tzope.interfaceRttwisted.internetRRR$(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/pcp.pyt<module>sT