Your IP : 172.28.240.42


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


0Nc@sRdZddlZddlmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
mZmZmZddlmZmZddlmZd	ejfd
YZdejfdYZd
ejfdYZdejfdYZdejfdYZdejfdYZdfdYZdeej fdYZ!dfdYZ"deje"fdYZ#de"fdYZ$de%fd YZ&d!eej'fd"YZ(d#eje$e&fd$YZ)d%eej*fd&YZ+d'eje$e&fd(YZ,d)e+e%fd*YZ-d+e,fd,YZ.d-eej/fd.YZ0d/eje$e&fd0YZ1d1e%fd2YZ2d3ejfd4YZ3d5ejfd6YZ4d7e	j5fd8YZ6d9e	j7fd:YZ8d;ejfd<YZ9d=ejfd>YZ:dS(?s+
Test cases for twisted.protocols package.
iN(tverifyObject(tunittest(tbasictwiretportforward(treactortprotocoltdeferttaskterrortaddress(tIProtocolFactorytILoggingContext(t
proto_helperst
LineTestercBsJeZdZdZdZddZdZdZdZ	dZ
RS(	s
    A line receiver that parses data received and make actions on some tokens.

    @type delimiter: C{str}
    @ivar delimiter: character used between received lines.
    @type MAX_LENGTH: C{int}
    @ivar MAX_LENGTH: size of a line when C{lineLengthExceeded} will be called.
    @type clock: L{twisted.internet.task.Clock}
    @ivar clock: clock simulating reactor callLater. Pass it to constructor if
        you want to use the pause/rawpause functionalities.
    s
i@cCs
||_dS(s@
        If given, use a clock to make callLater calls.
        N(tclock(tselfR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt__init__#scCs
g|_dS(s;
        Create/clean data received on connection.
        N(treceived(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytconnectionMade*scCs(|jj||dkr)|jn|dkrX|j|jjd|jn|dkr|j|j|jjd|jjd|jn|dkr|jnj|d dkrt|d|_	nD|j
dr|jj|t
n|j
d	r$|jjnd
S(s|
        Receive line and make some action for some tokens: pause, rawpause,
        stop, len, produce, unproduce.
        ttpauseitrawpausetstopislen tproducet	unproduceN(Rtappendt
setRawModetpauseProducingRt	callLatertresumeProducingt
stopProducingtinttlengtht
startswitht	transporttregisterProducertFalsetunregisterProducer(Rtline((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytlineReceived1s&




cCsl||j ||j}}|jt||_|jd||jd<|jdkrh|j|ndS(sj
        Read raw data, until the quantity specified by a previous 'len' line is
        reached.
        iiN(R!tlenRtsetLineMode(Rtdatatrest((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytrawDataReceivedKs
cCs8t||jdkr4|j||jdndS(s<
        Adjust line mode when long lines received.
        iN(R)t
MAX_LENGTHR*(RR'((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytlineLengthExceededWsN(t__name__t
__module__t__doc__t	delimiterR.tNoneRRR(R-R/(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs			tLineOnlyTestercBs,eZdZdZdZdZdZRS(s)
    A buffering line only receiver.
    s
i@cCs
g|_dS(s;
        Create/clean data received on connection.
        N(R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRgscCs|jj|dS(s%
        Save received data.
        N(RR(RR'((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR(ns(R0R1R2R3R.RR((((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR5`s
	tFactoryTestscBs eZdZdZdZRS(s(
    Tests for L{protocol.Factory}.
    cCs<tj}|jtt||jtt|dS(sp
        L{protocol.Factory} instances provide both L{IProtocolFactory} and
        L{ILoggingContext}.
        N(RtFactoryt
assertTrueRRR(Rtfactory((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_interfaceszscCs6dtjfdY}|jd|jdS(sV
        L{protocol.Factory.logPrefix} returns the name of the factory class.
        tSomeKindOfFactorycBseZRS((R0R1(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR;sN(RR7tassertEqualt	logPrefix(RR;((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_logPrefixs(R0R1R2R:R>(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR6vs	
tWireTestCasecBs2eZdZdZdZdZdZRS(s
    Test wire protocols.
    cCstj}tj}|j||jd|jd|jd|jd|jd|j|jddS(sT
        Test wire.Echo protocol: send some data and check it send it back.
        thellotworldthowtaretyouthelloworldhowareyouN(R
tStringTransportRtEchotmakeConnectiontdataReceivedR<tvalue(Rttta((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt	test_echos





cCs?tj}tj}|j||j|jddS(s)
        Test wire.Who protocol.
        sroot
N(R
RFRtWhoRHR<RJ(RRKRL((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_whos
cCs?tj}tj}|j||j|jddS(s*
        Test wire.QOTD protocol.
        s'An apple a day keeps the doctor away.
N(R
RFRtQOTDRHR<RJ(RRKRL((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt	test_QOTDs

cCstj}tj}|j||jd|jd|jd|jd|jd|j|jddS(s-
        Test wire.Discard protocol.
        R@RARBRCRDRN(R
RFRtDiscardRHRIR<RJ(RRKRL((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_discards





(R0R1R2RMRORQRS(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR?s
		
	tLineReceiverTestCasec
BseZdZdZdddddddd	d
ddd
dg
ZdZdZdddgZedgZdZ	dZ
dddddgZddddddgZdZ
dZdddgZdZdZdZRS(s=
    Test LineReceiver, using the C{LineTester} wrapper.
    slen 10

0123456789len 5

1234
len 20
foo 123

0123456789
012345678len 0
foo 5

1234567890123456789012345678901234567890123456789012345678901234567890
len 1

aslen 10t
0123456789slen 5s1234
slen 20sfoo 123s0123456789
012345678slen 0sfoo 5Rt67890slen 1RLcCsxtddD]}tj}t}|jtj|xNtt|j|dD]/}|j|||d|!}|j	|q_W|j
|j|jqWdS(sl
        Test buffering for different packet size, checking received matches
        expected data.
        ii
N(
trangeR
tStringIOWithoutClosingRRHRtFileWrapperR)tbufferRIR<toutputR(Rtpacket_sizeRKRLtits((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt
testBuffers	$s!twiddle1
twiddle2
pause
twiddle3
ttwiddle1ttwiddle2Rttwiddle3cCsxtddD]}tj}tj}t|}|jtj|xNtt	|j
|dD]/}|j
|||d|!}|j|qnW|j|j
|j|jd|j|j|jqWdS(so
        Test pause inside data receiving. It uses fake clock to see if
        pausing/resuming work.
        ii
iN(RWR
RXRtClockRRHRRYR)t	pause_bufRIR<t
pause_output1Rtadvancet
pause_output2(RR\RKRRLR]R^((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_pausings$
s/twiddle1
twiddle2
len 5
rawpause
12345twiddle3
Rt12345cCsxtddD]}tj}tj}t|}|jtj|xNtt	|j
|dD]/}|j
|||d|!}|j|qnW|j|j
|j|jd|j|j|jqWdS(s7
        Test pause inside raw date receiving.
        ii
iN(RWR
RXRRcRRHRRYR)trawpause_bufRIR<trawpause_output1RRftrawpause_output2(RR\RKRRLR]R^((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_rawPausings$
s"twiddle1
twiddle2
stop
more
stuff
RcCsxtddD]}tj}t}|jtj|xNtt|j|dD]/}|j|||d|!}|j	|q_W|j
|j|jqWdS(s-
        Test stop inside producing.
        ii
N(
RWR
RXRRHRRYR)tstop_bufRIR<tstop_outputR(RR\RKRLR]R^((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_stopProducing$s	$cCs[t}tj}|jtj||jd|j|jddddgdS(s6
        Test produce/unproduce in receiving.
        s&produce
hello world
unproduce
goodbye
Rshello worldRtgoodbyeN(	RR
RXRHRRYRIR<R(RRLRK((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_lineReceiverAsProducer2s	
cCsdtjfdY}|}|jd|j|jd|j|jd|jd|j|jd|j|jdd	S(
s
        L{LineReceiver.clearLineBuffer} removes all buffered data and returns
        it as a C{str} and can be called from beneath C{dataReceived}.
        tClearingReceivercBseZdZRS(cSs||_|j|_dS(N(R'tclearLineBufferR,(RR'((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR(Ds	(R0R1R((((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRsCss
foo
bar
baztfoosbar
bazsquux
tquuxRN(RtLineReceiverRIR<R'R,(RRsR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_clearLineBuffer>s	

(R0R1R2RZR[R_RdReRgRhRjRkRlRmRnRoRpRrRx(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRTs(		
					tLineOnlyReceiverTestCasecBs&eZdZdZdZdZRS(s#
    Test line only receiveer.
    s7foo
    bleakness
    desolation
    plastic forks
    cCsjtj}t}|j|x|jD]}|j|q,W|j|j|jjdd dS(sW
        Test buffering over line protocol: data received should match buffer.
        s
iN(	R
RFR5RHRZRIR<Rtsplit(RRKRLtc((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_buffer_s	
cCsLtj}t}|j||jdd}|j|tjdS(sO
        Test sending a line too long: it should close the connection.
        txiN(R
RFR5RHRItassertIsInstanceR	tConnectionLost(RRKRLtres((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_lineTooLongks
	
(R0R1R2RZR|R(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRyUs	t	TestMixincBs/eZdZdZdZdZdZRS(cCs
g|_dS(N(R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRyscCs|jj|dS(N(RR(RR^((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytstringReceived}si2icCs
d|_dS(Ni(tclosed(Rtreason((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytconnectionLosts(R0R1RRR.RR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRws
		t
TestNetstringcBseZdZRS(cCs$|jj||jj|dS(N(RRR#twrite(RR^((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs(R0R1R(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRstLPTestCaseMixincBs&eZgZdZdZdZRS(cCs)tj}|j}|j||S(s
        Return a new instance of C{self.protocol} connected to a new instance
        of L{proto_helpers.StringTransport}.
        (R
RFRRH(RRKRL((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytgetProtocols
cCsUxN|jD]C}|j}x|D]}|j|q#W|j|jjq
WdS(sO
        Assert that illegal strings cause the transport to be closed.
        N(tillegalStringsRRIR8R#t
disconnecting(RR^trR{((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_illegals

N(R0R1RR4RRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs	tNetstringReceiverTestCasecBseZddddddddgZdd	d
dgZeZdZd
ZdZdZ	dZ
dZdZdZ
dZdZdZdZdZdZdZdZdZdZdZdZd Zd!Zd"ZRS(#R@RARBRCtyou123s:todayRLit9999999999999999999999tabcs4:abcdes751:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab,cCs2tj|_t|_|jj|jdS(N(R
RFR#RtnetstringReceiverRH(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytsetUpscCsxtddD]}tj}t}d|_|j|x|jD]}|j|qKW|j}xQtt	||dD]5}||||d|!}|r|j
|qqW|j|j|jqWdS(sI
        Strings can be received in chunks of different lengths.
        ii
iN(
RWR
RFRR.RHtstringst
sendStringRJR)RIR<R(RR\RKRLR^toutR]((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR|s		
!c	CsRgidd6dd6dddgddg}t}tj}d|_|j|x|D]}|j||j}|j||jd }||jddd
!}|j	t
|tt||j	|t|q^W|j
d|jg}|j	t|d|j	|ddd|j	|ddtdS(s
        L{basic.NetstringReceiver.sendString} will send objects that are not
        strings by sending their string representation according to str().
        RLitbiR{iitfinetandsyou?idt:itoffendingFunctionsiitmessagesaData passed to sendString() must be a string. Non-string support is deprecated since Twisted 10.0tcategoryN(iRRsyou?(RR
RFR.RHRRJtcleartfindR<R R)tstrt
flushWarningsttest_sendNonStringstDeprecationWarning(	Rt
nonStringsRLRKR^RR!R+twarnings((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs.#			



"	cCs-|jjd|j|jjdgdS(sE
        Empty netstrings (with length '0') can be received.
        s0:,RN(RRIR<R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receiveEmptyNetstringscCs-|jjd|j|jjdgdS(s;
        One-character netstrings can be received.
        s1:a,RLN(RRIR<R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receiveOneCharacterscCs-|jjd|j|jjdgdS(s;
        Two-character netstrings can be received.
        s2:ab,tabN(RRIR<R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receiveTwoCharactersscCs-|jjd|j|jjdgdS(s
        Netstrings with embedded netstrings. This test makes sure that
        the parser does not become confused about the ',' and ':'
        characters appearing inside the data portion of the netstring.
        s4:1:a,,s1:a,N(RRIR<R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receiveNestedNetstring	scCs'|jjd|j|jjdS(sL
        Netstrings containing more data than expected are refused.
        s2:aaa,N(RRIR8R#R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_moreDataThanSpecifiedscCs'|jjd|j|jjdS(s
        Netstrings that should be empty according to their length
        specification are refused if they contain data.
        s0:a,N(RRIR8R#R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt$test_moreDataThanSpecifiedBorderCasescCs'|jjd|j|jjdS(s`
        Netstrings without leading digits that specify the length
        are refused.
        s:aaa,N(RRIR8R#R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_missingNumber$scCs'|jjd|j|jjdS(sg
        Netstrings without a colon between length specification and
        data are refused.
        s3aaa,N(RRIR8R#R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_missingColon-scCs'|jjd|j|jjdS(sY
        Netstrings that have no leading digits nor a colon are
        refused.
        saaa,N(RRIR8R#R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_missingNumberAndColon6scCs'|jjd|j|jjdS(sA
        Netstrings consisting only of data are refused.
        taaaN(RRIR8R#R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt
test_onlyData?scCsS|jjd|jjd|j|jjdg|j|jjdS(s=
        Netstrings can be received in two portions.
        s4:aasaa,taaaaN(RRIR<RR8t_payloadComplete(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receiveNetstringPortions_1GscCsJx*ddddgD]}|jj|qW|j|jjdgdS(s
        Netstrings can be received in more than two portions, even if
        the length specification is split across two portions.
        t1s0:01234t56789t,RUN(RRIR<R(Rtpart((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receiveNetstringPortions_2QscCs>xdD]}|jj|qW|j|jjdgdS(sE
        Netstrings can be received one character at a time.
        s2:ab,RN(RRIR<R(RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receiveNetstringPortions_3[s
cCso|jjd|j|jj|j|jjdg|jjd|j|jjddgdS(s
        A stream of two netstrings can be received in two portions,
        where the first portion contains the complete first netstring
        and the length specification of the second netstring.
        s1:a,1RLs:b,RN(RRIR8RR<R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receiveTwoNetstringsds
cCsE|jjd}|jjd|d|f|j|jjdS(ss
        Netstrings with a length specification exceeding the specified
        C{MAX_LENGTH} are refused.
        is%s:%sRLN(RR.RIR8R#R(RttooLong((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_maxReceiveLimitqscCs3d|j_|jj|j|jjddS(sw
        C{_consumeLength} returns the expected length of the
        netstring, including the trailing comma.
        s12:i
N(Rt_remainingDatat_consumeLengthR<t_expectedPayloadSize(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_consumeLength|s
cCs?d|j_d|j_|jj|j|jjddS(s
        C{_consumeLength} works as expected if the length specification
        contains the value of C{MAX_LENGTH} (border case).
        s12:ii
N(RRR.RR<R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_consumeLengthBorderCase1s
cCs5d|j_d|j_|jtj|jjdS(s
        C{_consumeLength} raises a L{basic.NetstringParseError} if
        the length specification exceeds the value of C{MAX_LENGTH}
        by 1 (border case).
        s12:iN(RRR.tassertRaisesRtNetstringParseErrorR(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_consumeLengthBorderCase2scCs5d|j_d|j_|jtj|jjdS(s
        C{_consumeLength} raises a L{basic.NetstringParseError} if
        the length specification exceeds the value of C{MAX_LENGTH}
        by more than 1.
        s1000:iN(RRR.RRRR(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_consumeLengthBorderCase3scCstjtjtjtjf|jd|jg}|jt|dx"|D]}|j|dt	qQW|j|ddd|j|ddd|j|d	dd
|j|dddd
S(s
        Accessing one of the old module attributes used by the
        NetstringReceiver parser emits a deprecation warning.
        RiRiRsktwisted.protocols.basic.LENGTH was deprecated in Twisted 10.2.0: NetstringReceiver parser state is private.isitwisted.protocols.basic.DATA was deprecated in Twisted 10.2.0: NetstringReceiver parser state is private.isjtwisted.protocols.basic.COMMA was deprecated in Twisted 10.2.0: NetstringReceiver parser state is private.isktwisted.protocols.basic.NUMBER was deprecated in Twisted 10.2.0: NetstringReceiver parser state is private.N(
RtLENGTHtDATAtCOMMAtNUMBERRttest_deprecatedModuleAttributesR<R)R(RRtwarning((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs$	
(R0R1RRRRRR|RRRRRRRRRRRRRRRRRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs6					 				
											
	
			
		
			tIntNTestCaseMixincBsSeZdZdZdZdZdZdZdZ	dZ
dZdZRS(s4
    TestCase mixin for int-prefixed protocols.
    cCsq|j}xH|jD]=}x4tj|jt||D]}|j|q<WqW|j|j|jdS(s>
        Test receiving data find the same data send.
        N(	RRtstructtpacktstructFormatR)RIR<R(RRR^R{((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_receives
&cCsUxN|jD]C}|j}x|D]}|j|q#W|j|jgq
WdS(sK
        Send partial data, nothing should be definitely received.
        N(tpartialStringsRRIR<R(RR^RR{((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_partials

cCsI|j}|jd|j|jjtj|jdddS(s2
        Test sending data over protocol.
        RiNtbbbbbbbbbbbbbbbbR(RRR<R#RJRRR(RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt	test_sends
cCsZg}|j}|j|_d|_|jtj|jd|j|dgdS(s
        When a length prefix is received which is greater than the protocol's
        C{MAX_LENGTH} attribute, the C{lengthLimitExceeded} method is called
        with the received length prefix.
        i
iN(	RRtlengthLimitExceededR.RIRRRR<(RR!R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_lengthLimitExceededs	cCsL|j}d|_|jtj|jdd|j|jgdS(s
        If a length prefix for a string longer than C{MAX_LENGTH} is delivered
        to C{dataReceived} at the same time as the entire string, the string is
        not passed to C{stringReceived}.
        i
iR}Ntxxxxxxxxxxx(RR.RIRRRR<R(RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_longStringNotDelivereds
	N(
R0R1R2R4RRRRRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs			
	tRecvdAttributeMixincBs;eZdZdZdZdZdZdZRS(s
    Mixin defining tests for string receiving protocols with a C{recvd}
    attribute which should be settable by application code, to be combined with
    L{IntNTestCaseMixin} on a L{TestCase} subclass
    cCstj|jt||S(sg
        Return C{data} prefixed with message length in C{protocol.structFormat}
        form.
        (RRRR)(RRR+((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pytmakeMessagescsg|jfd}|_tjjdd}tjjdd}j|||j|gdS(	s
        In stringReceived, recvd contains the remaining data that was passed to
        dataReceived that was not part of the current message.
        csjjdS(N(Rtrecvd(treceivedString(Rtresult(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR$siRLRiNtaaaaatbbbb(RRRRRRItassertEquals(RRtcompleteMessagetincompleteMessage((RRs?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_recvdContainsRemainingDatas	cs|jgd}|j|fd}|_d}d	}|j|}|j|}j|||j||gdS(
s
        In stringReceived, if recvd is changed, messages should be parsed from
        it rather than the input to dataReceived.
        R{ics#s_nj|dS(N(RR(R(tmessageCRR(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR7sRLRNtcccccRtbbbbb(RRRRIR(RtpayloadCRtpayloadAtpayloadBtmessageAtmessageB((RRRs?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_recvdChanged.s	cs|jg}dx7|jD],}|j|j||jq"Wgfd}|_jdj|jd|j|j|jjddS(s
        Data already parsed by L{IntNStringReceiver.dataReceived} is not
        reparsed if C{stringReceived} consumes some of the
        L{IntNStringReceiver.recvd} buffer.
        tcs'j|jt_dS(N(RRR)(R(tSWITCHRtproto(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRRs
RsN(	RRRRRRItjoinR<R(RtmixR^R((RRRs?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_switchingDs	
cs|jd}t|d_|j|}gfd}|_j||jdt||jd|dS(s
        The L{IntNStringReceiver.recvd} buffer contains all data not yet
        processed by L{IntNStringReceiver.dataReceived} if the
        C{lengthLimitExceeded} event occurs.
        stoo longics!j|jjdS(N(RR(R!(RR(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRls
iN(RR)R.RRRIR<(RRRR((RRs?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_recvdInLengthLimitExceeded`s	
(R0R1R2RRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs				t	TestInt32cBseZdZRS(s
    A L{basic.Int32StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    (R0R1R2(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRwst
Int32TestCasecBsAeZdZeZdd	gZdgZdddgZdZRS(
s/
    Test case for int32-prefixed protocol
    RLRis
aaaaaatshello thereRcCsY|j}|jd|j|jjd|jd|j|jdgdS(s?
        Test specific behavior of the 32-bits length.
        RutfootubartubarN(RRR<R#RJRIR(RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt	test_datas


R(	R0R1R2RRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs	t	TestInt16cBseZdZRS(s
    A L{basic.Int16StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    (R0R1R2(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRst
Int16TestCasecBsJeZdZeZdd
gZdgZdddgZdZd	Z	RS(s/
    Test case for int16-prefixed protocol
    RLRisaaaaaatshello thereRcCsY|j}|jd|j|jjd|jd|j|jdgdS(s?
        Test specific behavior of the 16-bits length.
        RutfootubarRN(RRR<R#RJRIR(RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs


cCs?|j}dd|jdd}|jt|j|dS(sA
        Send too much data: that should cause an error.
        RiiiN(RtprefixLengthRtAssertionErrorR(RRttooSend((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_tooLongSendsR(
R0R1R2RRRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs		tNewStyleTestInt16cBseZdZRS(s0
    A new-style class version of TestInt16
    (R0R1R2(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRstNewStyleInt16TestCasecBseZdZeZRS(sn
    This test case verifies that IntNStringReceiver still works when inherited
    by a new-style class.
    (R0R1R2RR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRstTestInt8cBseZdZRS(s
    A L{basic.Int8StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    (R0R1R2(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRstInt8TestCasecBsJeZdZeZdd
gZdgZdddgZdZd	Z	RS(s.
    Test case for int8-prefixed protocol
    RLRitaaaaaastdzadzRcCsY|j}|jd|j|jjd|jd|j|jdgdS(s>
        Test specific behavior of the 8-bits length.
        RusfoosubarRN(RRR<R#RJRIR(RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs


cCs?|j}dd|jdd}|jt|j|dS(sA
        Send too much data: that should cause an error.
        RiiiN(RRRRR(RRR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRsR(
R0R1R2RRRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR	s		tOnlyProducerTransportcBs8eZeZeZdZdZdZdZRS(cCs
g|_dS(N(R+(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRscCs
t|_dS(N(tTruetpaused(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRscCs
t|_dS(N(R%R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRscCs|jj|dS(N(R+R(Rtbytes((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs(	R0R1R%RRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs			tConsumingProtocolcBseZdZRS(cCs|jj||jdS(N(R#RR(RR'((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR(s(R0R1R((((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRstProducerTestCasecBseZdZRS(cCst}t}|j||jd|j|j|j|j|j|j|jd|j|jdg|j|j|j|j|j	|j|j|j|j|jd|j|jddg|j|j|j|j|j	|jd|j|jdddg|j|j|j|j|j	|j|jddddg|j|j|j|j|j	|j|jddddg|j|j|j|jdS(	Nshello, sworld
shello, worldshello
world
R@s	goodbye
RARq(
RRRHRItfailIfR+RR<t
failUnlessR(RtpRK((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttestPauseResumes>		








(R0R1R(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRstTestableProxyClientFactorycBseZdZdZRS(s
    Test proxy client factory that keeps the last created protocol instance.

    @ivar protoInstance: the last instance of the protocol.
    @type protoInstance: L{portforward.ProxyClient}
    cCs"tjj||}||_|S(sE
        Create the protocol instance and keeps track of it.
        (RtProxyClientFactoryt
buildProtocolt
protoInstance(RtaddrR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyROs	(R0R1R2R(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRGstTestableProxyFactorycBseZdZdZRS(sl
    Test proxy factory that keeps the last created protocol instance.

    @ivar protoInstance: the last instance of the protocol.
    @type protoInstance: L{portforward.ProxyServer}

    @ivar clientFactoryInstance: client factory used by C{protoInstance} to
        create forward connections.
    @type clientFactoryInstance: L{TestableProxyClientFactory}
    cs@tjj|}t_fd|_|_|S(s
        Create the protocol instance, keeps track of it, and makes it use
        C{clientFactoryInstance} as client factory.
        csjS(N(tclientFactoryInstance((R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt<lambda>ms(RtProxyFactoryRRRtclientProtocolFactoryR(RRR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRes
	(R0R1R2R(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRYs
tPortforwardingcBs2eZdZdZdZdZdZRS(s
    Test port forwarding.
    cCs+tj|_tj|_g|_dS(N(RRGtserverProtocolRtProtocoltclientProtocolt	openPorts(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRxscCsy|jjjjWntk
r*nXy |jjj}|jjWntk
r^nXy|jjjWntk
rnXy|jjjWntk
rnXtj	g|j
D]}tj|j^qS(N(
tproxyServerFactoryRR#tloseConnectiontAttributeErrorRR#R!Rt
gatherResultsR$t
maybeDeferredt
stopListening(RtpiR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttearDown~s&



cs$tj}fd|_tjd|dd}jj|td|jj_	tjdj	dd}jj|dgt
jfd}|j_
fd}|j_tj}fd|_tjd|jj|S(	s=
        Test port forwarding through Echo protocol.
        csjS(N(R!((R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRsit	interfaces	127.0.0.1icsPj|tkrLjdjdjdndS(NRR}(textendR)R<RtcallbackR4(R+(RtdRtnBytes(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttestDataReceiveds
csjjjddS(NR}(R#R#R((RR1(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttestConnectionMadescsjS(N(R#((R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyRs(Rt
ServerFactoryRt	listenTCPR$RRtgetHosttportR%RtDeferredR#RIRt
ClientFactoryt
connectTCP(RtrealServerFactorytrealServerPorttproxyServerPortR2R3t
clientFactory((RRR1R0s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_portforwards,		cCstjddd}tjddj|}tj}||_tj}|j	||j
t|jd|jd\}}}}}	|j
|tj|j|}
tj}|
j	||j|j||j|j||j|j|j|jdS(sm
        The proxy client registers itself as a producer of the proxy server and
        vice versa.
        tTCPs	127.0.0.1iiN(R
tIPv4AddressRRRR
t
MemoryReactorRRFRHR<R)t
tcpClientsR~RtassertIdenticaltproducerR8t	streaming(RRtserverRtserverTransportthostR7R>ttimeoutt_tclienttclientTransport((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_registerProducerss 	

(R0R1R2RR,R?RN(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyR ss
			)tStringTransportTestCasecBseZdZdZRS(sA
    Test L{proto_helpers.StringTransport} helper behaviour.
    cCs&tj}|jt|jddS(sY
        Test that L{proto_helpers.StringTransport} doesn't accept unicode data.
        ufooN(R
RFRt	TypeErrorR(RR^((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyttest_noUnicodes(R0R1R2RQ(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyROs(;R2Rtzope.interface.verifyRt
twisted.trialRttwisted.protocolsRRRttwisted.internetRRRRR	R
ttwisted.internet.interfacesRRttwisted.testR
RwRtLineOnlyReceiverR5tTestCaseR6R?RTRyRtNetstringReceiverRRRRtobjectRtInt32StringReceiverRRtInt16StringReceiverRRRRtInt8StringReceiverRR	RRRRRRRR RO(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_protocols.pyt<module>sF.M9"Fi					2o