ϪfdZddlZddlZddlmZddlmZmZmZddl m Z ddl m Z m Z ddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZGddej8ZGddej8ZGddej>Z GddejBZ"Gddej8Z#GddejBZ$GddejBZ%GddZ&Gdde&ejNZ(Gd d!Z)Gd"d#ejBe)Z*Gd$d%e)Z+Gd&d'Z,Gd(d)e&ejZZ.Gd*d+ejBe+e,Z/Gd,d-e&ej`Z1Gd.d/ejBe+e,Z2Gd0d1e&ejfZ4Gd2d3ejBe+e,Z5Gd4d5Z6Gd6d7ej8Z7Gd8d9ejBZ8Gd:d;ejrZ:y)? "KKK1q5K2GHq! "   T[[!** 5 6rs!twiddle1 twiddle2 pause twiddle3 )twiddle1twiddle2r:twiddle3c6tddD] }tj}tj}t |}|j tj|tt|j|zdzD]+}|j||z|dz|z}|j|-|j|j|j|jd|j|j |j y)zo Test pause inside data receiving. It uses fake clock to see if pausing/resuming work. r#r\rN)r]rr^r Clockr/r_rr`rLpauseBufrbrc pauseOutput1r6advance pauseOutput2rrfrgr2rhrirjs r test_pausingzLineReceiverTests.test_pausings !B< MM!    T111:: > ?rs"twiddle1 twiddle2 stop more stuff )rlrmr<ctddD]}tj}t}|j t j |tt|j|zdzD]+}|j||z|dz|z}|j|-|j|j|jy)z- Test stop inside producing. r#r\N) r]rr^r/r_rr`rLstop_bufrbrc stop_outputr6res rtest_stopProducingz$LineReceiverTests.test_stopProducings!B< ;K446A A  X11!4 53t}}-s hello worldr?goodbyeN) r/rr^r_rr`rbrcr6)rrhrgs rtest_lineReceiverAsProducerz-LineReceiverTests.test_lineReceiverAsProducersW L  0 0 2 --a01 DE  JJN rclGddtj}|}|jd|j|jd|j|j d|jd|j|jd|j|j dy ) z L{LineReceiver.clearLineBuffer} removes all buffered data and returns it as a C{bytes} and can be called from beneath C{dataReceived}. ceZdZdZy)@LineReceiverTests.test_clearLineBuffer..ClearingReceiverc<||_|j|_yr)r clearLineBufferrMrs rr!zMLineReceiverTests.test_clearLineBuffer..ClearingReceiver.lineReceiveds   002 rN)r(r)r*r!r-rrClearingReceiverrs 3rrs foo bar bazfoosbar bazsquux squuxrN)r LineReceiverrbrcr rM)rrrs rtest_clearLineBufferz&LineReceiverTests.test_clearLineBuffers  3u11 3 $%23 /  6 k* 0 ,rc4t}tj}|jt j |t j}|jd|z|jd|zdj|jy)zC Test switching modes many times on the same data. sx xxrN) rrr^r_rr`sysgetrecursionlimitrbrcjoinr)rprotorGlimits rtest_stackRecursionz%LineReceiverTests.test_stackRecursion*st#$!88:  X11)<=%%' 7U?+ sxx '<=rctj}tj}|j ||j d|j dzzdz|j|jyzx C{LineReceiver} disconnects the transport if it receives a line longer than its C{MAX_LENGTH}. rr# rN r rrStringTransportr_rbrO assertTrue disconnectingrrrGs rtest_maximumLineLengthz(LineReceiverTests.test_maximumLineLength5c ""$!113  Y' 45#3#3a#788CD  //0rct}d|_tj}|j |d|jdz z}|j ||j |j dd|j |j dd|z|j|j|jt|jd|j||jdy)a~ C{LineReceiver} doesn't disconnect the transport when it receives a finished line as long as its C{MAX_LENGTH}, when the second-to-last packet ended with a pattern that could have been -- and turns out to have been -- the start of a delimiter, and that packet causes the total input to exceed C{MAX_LENGTH} + len(delimiter). r=rr#NrKr) r/rOrrr_rbr, assertFalserrcrLr6)rrrgr s r&test_maximumLineLengthPartialDelimiterz8LineReceiverTests.test_maximumLineLengthPartialDelimiter@s   ) ) + Qu''!+, 4  5??3B/0 5??23/$67 ) U^^,a0 u~~a01rcBtj}d|_tj}|j ||j d|jz|jdt|jdz z|j|jy)aO C{LineReceiver} doesn't disconnect the transport it if receives a non-finished line whose length, counting the delimiter, is longer than its C{MAX_LENGTH} but shorter than its C{MAX_LENGTH} + len(delimiter). (When the first part that exceeds the max is the beginning of the delimiter.) s rNr#) r rr,rrr_rbrOrLrrrs r(test_notQuiteMaximumLineLengthUnfinishedz:LineReceiverTests.test_notQuiteMaximumLineLengthUnfinishedVs""$"!113  Y'  E$$ $8R#eoo:NQR:R(S S  001rctj}d|_tj}|j ||j |jd}|j|ty)zf C{LineReceiver.dataReceived} forwards errors returned by C{rawDataReceived}. ctdS)Noops) RuntimeErrorr&s rz5LineReceiverTests.test_rawDataError..os \&-ArsdataN) r rr'rrr_rrbassertIsInstancer)rrrGwhys rtest_rawDataErrorz#LineReceiverTests.test_rawDataErrorisb ""$ A!113  Y'   ) c<0rcntj}|jt|jdy)z When L{LineReceiver.rawDataReceived} is not overridden in a subclass, calling it raises C{NotImplementedError}. fooN)r r assertRaisesNotImplementedErrorr'rrs r"test_rawDataReceivedNotImplementedz4LineReceiverTests.test_rawDataReceivedNotImplementedvs+ ""$ -u/D/DeLrcntj}|jt|jdy)z When L{LineReceiver.lineReceived} is not overridden in a subclass, calling it raises C{NotImplementedError}. rN)r rrrr!rs rtest_lineReceivedNotImplementedz1LineReceiverTests.test_lineReceivedNotImplemented~s+ ""$ -u/A/A5IrN)r(r)r*r+rardrkrqrrrtrvrxryrzr{r}r~rrrrrrrrrrr-rrrWrWs F$F 68H7L;-/L<"JKLOO? :H5K ;  -, > 12,2& 1MJrrWc"eZdZdZdZdZdZy)ExcessivelyLargeLineCatcherz Helper for L{LineReceiverLineLengthExceededTests}. @ivar longLines: A L{list} of L{bytes} giving the values C{lineLengthExceeded} has been called with. cg|_yr) longLinesrs rr7z*ExcessivelyLargeLineCatcher.connectionMades rcy)z/ Disregard any received lines. Nr-rs rr!z(ExcessivelyLargeLineCatcher.lineReceivedsrc:|jj|y)zF Record any data that exceeds the line length limits. N)rrr%s rrPz.ExcessivelyLargeLineCatcher.lineLengthExceededs d#rN)r(r)r*r+r7r!rPr-rrrrs $rrc:eZdZdZdZdZdZdZdZdZ dZ y ) #LineReceiverLineLengthExceededTestszO Tests for L{twisted.protocols.basic.LineReceiver.lineLengthExceeded}. ct|_d|j_tj|_|jj |j y)N)rrrOrrrGr_rs rsetUpz)LineReceiverLineLengthExceededTests.setUps>02 ! &668 !!$..1rcd|jjdzdzz}|jj||j|g|jjy)z If more bytes than C{LineReceiver.MAX_LENGTH} arrive containing no line delimiter, all of the bytes are passed as a single string to L{LineReceiver.lineLengthExceeded}. rN)rrOrbrcrr excessives rtest_longUnendedLinez8LineReceiverLineLengthExceededTests.test_longUnendedLinesP DJJ11A59:   * )djj&:&:;rcd|jjdzdzz}|jjd|jjz|z|j |g|jj y)a* If L{LineReceiver.dataReceived} is called with bytes representing a short line followed by bytes that exceed the length limit without a line delimiter, L{LineReceiver.lineLengthExceeded} is called with all of the bytes following the short line's delimiter. rrN)rrOrbr,rcrrs rtest_longLineAfterShortLinez?LineReceiverLineLengthExceededTests.test_longLineAfterShortLinesdDJJ11A59:  tzz';'; ;i GH )djj&:&:;rc|jjjd|jjdzdzzgdz}|jj ||j |g|jj y)a If L{LineReceiver.dataReceived} is called with more than C{LineReceiver.MAX_LENGTH} bytes containing a line delimiter somewhere not in the first C{MAX_LENGTH} bytes, the entire byte string is passed to L{LineReceiver.lineLengthExceeded}. rrN)rr,rrOrbrcrrs rtest_longLineWithDelimiterz>LineReceiverLineLengthExceededTests.test_longLineWithDelimitersrJJ((-- TZZ**Q.2 3 4q 8   * )djj&:&:;rcd|jjdzdzz|jjzdz}|jj||j |g|jj y)a If L{LineReceiver.dataReceived} is called with more than C{LineReceiver.MAX_LENGTH} bytes containing multiple line delimiters somewhere not in the first C{MAX_LENGTH} bytes, the entire byte string is passed to L{LineReceiver.lineLengthExceeded}. rrN)rrOr,rbrcrrs rtest_multipleLongLinesz:LineReceiverLineLengthExceededTests.test_multipleLongLinesseTZZ22Q6:;djj>R>RRVWW   * )djj&:&:;rctj}tj}|j ||j d|j dzzdz|j|jyrrrs rrz:LineReceiverLineLengthExceededTests.test_maximumLineLengthrrctj}tj}|j ||j d|j t|jzz|j|jy)z C{LineReceiver} disconnects the transport it if receives a non-finished line longer than its C{MAX_LENGTH}. rN) r rrrr_rbrOrLr,rrrs rtest_maximumLineLengthRemainingzCLineReceiverLineLengthExceededTests.test_maximumLineLengthRemainingsg ""$!113  Y' 45#3#3c%//6J#JKL  //0rN) r(r)r*r+rrrrrrrr-rrrrs*2 < < < < 1 1rrc&eZdZdZdZdZdZdZy)LineOnlyReceiverTestsz@ Tests for L{twisted.protocols.basic.LineOnlyReceiver}. s7foo bleakness desolation plastic forks c(tj}t}|j|t |j D]}|j ||j|j|j jdddy)zW Test buffering over line protocol: data received should match buffer. rNrK) rrrRr_r rarbrcr6split)rrgrhcs rrkz!LineOnlyReceiverTests.test_buffersv  ) ) +   4;;' A NN1   T[[%6%6u%=cr%BCrc t}tj}|j||j d|j t |jzdzzdz|j|jy)z C{LineOnlyReceiver} disconnects the transport if it receives a line longer than its C{MAX_LENGTH} + len(delimiter). rr#rN) rRrrr_rbrOrLr,rrrs r!test_greaterThanMaximumLineLengthz7LineOnlyReceiverTests.test_greaterThanMaximumLineLengthsp  !113  Y'  E$$s5??';;a? @8 K   //0rcntj}|jt|jdy)z When L{LineOnlyReceiver.lineReceived} is not overridden in a subclass, calling it raises C{NotImplementedError}. rN)r LineOnlyReceiverrrr!rs rrz5LineOnlyReceiverTests.test_lineReceivedNotImplementeds+ &&( -u/A/A5IrN)r(r)r*r+rarkrrr-rrrrsF D 1Jrrc4eZdZdZdZdZdZefdeddfdZ y) TestMixincg|_yrr5rs rr7zTestMixin.connectionMades  rc:|jj|yrrUrrjs rstringReceivedzTestMixin.stringReceiveds Qr2rreasonreturnNcd|_y)Nr#)closed)rrs rconnectionLostzTestMixin.connectionLost#s  r) r(r)r*r7rrOrr rrr-rrrrs. J F/=W$rrceZdZdZy) TestNetstringcp|jj||jj|yr)r6rrGwriters rrzTestNetstring.stringReceived(s& Q QrN)r(r)r*rr-rrrr's rrcBeZdZUgZeeeed<dZded<dZ dZ y)LPTestCaseMixinillegalStringsN!Optional[Type[protocol.Protocol]]rcptj}|j}|j||S)z Return a new instance of C{self.protocol} connected to a new instance of L{proto_helpers.StringTransport}. )rrrr_)rrgrhs r getProtocolzLPTestCaseMixin.getProtocol1s0  ) ) + MMO rc|jD]X}|j}t|D]}|j||j |j j Zy)zO Assert that illegal strings cause the transport to be closed. N)rrr rbrrGrrrjrrs r test_illegalzLPTestCaseMixin.test_illegal;s\$$ 7A  "Aq\ "q! " OOAKK55 6  7r) r(r)r*rrrbytes__annotations__rrrr-rrrr-s*,.NHT%[).48H187rrceZdZdZgdZgdZeZdZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZy)NetstringReceiverTestszA Tests for L{twisted.protocols.basic.NetstringReceiver}. )helloworldshowsaresyou123s:todaysaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)s9999999999999999999999sabcs4:abcdes751:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab,ctj|_t|_|jj |jyr)rrrGrnetstringReceiverr_rs rrzNetstringReceiverTests.setUpVs4&668!. --dnn=rctddD]}tj}t}d|_|j ||j D]}|j||j}tt||zdzD]$}|||z|dz|z}|s|j|&|j|j|j y)zI Strings can be received in chunks of different lengths. r#r\iN) r]rrrrOr_strings sendStringvaluerLrbrcr6)rrfrgrhrjoutris rrkz"NetstringReceiverTests.test_buffer[s!B< 7K--/AAAL  Q \\  Q '')C3s8{2Q67 &K1q5K*?@NN1% &   QZZ 6 7rc|jjd|j|jjdgy)zE Empty netstrings (with length '0') can be received. s0:,rNrrbrcr6rs rtest_receiveEmptyNetstringz1NetstringReceiverTests.test_receiveEmptyNetstringms6 ++F3 //883%@rc|jjd|j|jjdgy)z; One-character netstrings can be received. 1:a,rZNrrs rtest_receiveOneCharacterz/NetstringReceiverTests.test_receiveOneCharacterts6 ++G4 //884&Arc|jjd|j|jjdgy)z; Two-character netstrings can be received. s2:ab,abNrrs rtest_receiveTwoCharactersz0NetstringReceiverTests.test_receiveTwoCharacters{s6 ++H5 //885'Brc|jjd|j|jjdgy)z 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,,rNrrs rtest_receiveNestedNetstringz2NetstringReceiverTests.test_receiveNestedNetstrings6 ++J7 //887)Drc|jjd|j|jjy)zL Netstrings containing more data than expected are refused. s2:aaa,NrrbrrGrrs rtest_moreDataThanSpecifiedz1NetstringReceiverTests.test_moreDataThanSpecifieds. ++I6 445rc|jjd|j|jjy)z Netstrings that should be empty according to their length specification are refused if they contain data. s0:a,Nr rs r$test_moreDataThanSpecifiedBorderCasez;NetstringReceiverTests.test_moreDataThanSpecifiedBorderCase. ++G4 445rc|jjd|j|jjy)z` Netstrings without leading digits that specify the length are refused. s:aaa,Nr rs rtest_missingNumberz)NetstringReceiverTests.test_missingNumber. ++H5 445rc|jjd|j|jjy)zg Netstrings without a colon between length specification and data are refused. s3aaa,Nr rs rtest_missingColonz(NetstringReceiverTests.test_missingColonrrc|jjd|j|jjy)zY Netstrings that have no leading digits nor a colon are refused. saaa,Nr rs rtest_missingNumberAndColonz1NetstringReceiverTests.test_missingNumberAndColonr rc|jjd|j|jjy)zA Netstrings consisting only of data are refused. saaaNr rs r test_onlyDataz$NetstringReceiverTests.test_onlyDatas. ++F3 445rc|jjd|jjd|j|jjdg|j |jj y)z= Netstrings can be received in two portions. s4:aasaa,saaaaN)rrbrcr6r_payloadCompleters rtest_receiveNetstringPortions_1z6NetstringReceiverTests.test_receiveNetstringPortions_1se ++G4 ++F3 //887)D ..??ABrcdD]}|jj||j|jjdgy)z Netstrings can be received in more than two portions, even if the length specification is split across two portions. )1s0:01234s56789,rXNrrparts rtest_receiveNetstringPortions_2z6NetstringReceiverTests.test_receiveNetstringPortions_2sE 7 6D  " " / / 5 6 //88=/JrcdD]}|jj||j|jjdgy)zE Netstrings can be received one character at a time. )2:rZbrrNrrs rtest_receiveNetstringPortions_3z6NetstringReceiverTests.test_receiveNetstringPortions_3sE3 6D  " " / / 5 6 //885'Brc`|jjd|j|jj|j |jj dg|jjd|j |jj ddgy)z 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,1rZs:b,r#N)rrbrrrcr6rs rtest_receiveTwoNetstringsz0NetstringReceiverTests.test_receiveTwoNetstringss ++H5 ..??AB //884&A ++F3 //884,Grc|jjdz}|jjdjt |dd|zf|j |j jy)zs Netstrings with a length specification exceeding the specified C{MAX_LENGTH} are refused. r#rr"rZN)rrOrbrrrrGr)rtooLongs rtest_maxReceiveLimitz+NetstringReceiverTests.test_maxReceiveLimitsa ((33a7 ++ HHeGndD7N; <  445rcd|j_|jj|j|jjdy)zw C{_consumeLength} returns the expected length of the netstring, including the trailing comma. 12: N)r_remainingData_consumeLengthrc_expectedPayloadSizers rtest_consumeLengthz)NetstringReceiverTests.test_consumeLengths@ 17- --/ //DDbIrcd|j_d|j_|jj|j |jj dy)z C{_consumeLength} works as expected if the length specification contains the value of C{MAX_LENGTH} (border case). r+ r,N)rr-rOr.rcr/rs rtest_consumeLengthBorderCase1z4NetstringReceiverTests.test_consumeLengthBorderCase1sN 17-,.) --/ //DDbIrcd|j_d|j_|jtj |jj y)z C{_consumeLength} raises a L{basic.NetstringParseError} if the length specification exceeds the value of C{MAX_LENGTH} by 1 (border case). r+ Nrr-rOrr NetstringParseErrorr.rs rtest_consumeLengthBorderCase2z4NetstringReceiverTests.test_consumeLengthBorderCase2sE 17-,.)   % %t'='='L'L rcd|j_d|j_|jtj |jj y)z C{_consumeLength} raises a L{basic.NetstringParseError} if the length specification exceeds the value of C{MAX_LENGTH} by more than 1. s1000:r5Nr6rs rtest_consumeLengthBorderCase3z4NetstringReceiverTests.test_consumeLengthBorderCase3 sE 19-,.)   % %t'='='L'L rcntj}|jt|jdy)z When L{NetstringReceiver.stringReceived} is not overridden in a subclass, calling it raises C{NotImplementedError}. rN)r NetstringReceiverrrrrs r!test_stringReceivedNotImplementedz8NetstringReceiverTests.test_stringReceivedNotImplementeds+ '') -u/C/CUKrN)r(r)r*r+rrrrrrkrrrrr r rrrrrrr$r&r)r0r3r8r:r=r-rrrrFsUGNH> 7$ABCE666666CKC H 6JJ    LrrceZdZUdZdZded<dZeee ed<dZ eee ed<dZ eee ed<dZ d Z d Zd Zd Zd Zy)IntNTestCaseMixinz4 TestCase mixin for int-prefixed protocols. NrrrrpartialStringsc (|j}|jD]M}ttj|j t ||zD]}|j|O|j|j|jy)z> Test receiving data find the same data send. N) rrr structpack structFormatrLrbrcr6)rrrjrs r test_receivezIntNTestCaseMixin.test_receive(sw     "Av{{1>>3q6BQFG "q! " " T\\2rc|jD]O}|j}t|D]}|j||j |j gQy)zK Send partial data, nothing should be definitely received. N)r@rr rbrcr6rs r test_partialzIntNTestCaseMixin.test_partial2sZ$$ -A  "Aq\ "q! "   QZZ ,  -rc|j}|jd|j|jj t j |jddzy)z2 Test sending data over protocol. bbbbbbbbbbbbbbbbN)rrrcrGrrBrCrDrrs r test_sendzIntNTestCaseMixin.test_send<sR     Y  KK   Q^^R!@9!L rcg}|j}|j|_d|_|j t j |jd|j|dgy)z 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. r\r5N) rrlengthLimitExceededrOrbrBrCrDrc)rrErs rtest_lengthLimitExceededz*IntNTestCaseMixin.test_lengthLimitExceededFsW      &   v{{1>>267 "&rc|j}d|_|jtj|j ddz|j |jgy)z 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}. r\r5s xxxxxxxxxxxN)rrOrbrBrCrDrcr6rKs rtest_longStringNotDeliveredz-IntNTestCaseMixin.test_longStringNotDeliveredSsM      v{{1>>26BC R(rcntj}|jt|jdy)z When L{IntNStringReceiver.stringReceived} is not overridden in a subclass, calling it raises C{NotImplementedError}. rN)r IntNStringReceiverrrrrs rr=z3IntNTestCaseMixin.test_stringReceivedNotImplemented^s+ ((* -u/C/CUKr)r(r)r*r+rrrrrrrr@rErGrLrOrQr=r-rrr?r?sl59H18%)GXd5k "),0NHT%[)0,0NHT%[)03-  ' )Lrr?c.eZdZdZdZdZdZdZdZy)RecvdAttributeMixinz 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 cZtj|jt||zS)zg Return C{data} prefixed with message length in C{protocol.structFormat} form. )rBrCrDrL)rrr&s r makeMessagezRecvdAttributeMixin.makeMessagens$ {{800#d).stringReceived}s MM!'' "raaaaasbbbbN)rrrBrCrDrbrc)rrcompleteMessageincompleteMessagerr]s @@rtest_recvdContainsRemainingDataz3RecvdAttributeMixin.test_recvdContainsRemainingDataus      #* ++anna8HE"KK:hG )::; "3!45rc |jg d}|j| fd}|_d}d}|j|}|j|}j||z|j ||gy)z In stringReceived, if recvd is changed, messages should be parsed from it rather than the input to dataReceived. scccccc:s_j|yr)r[r)r\messageCrr]s rrz=RecvdAttributeMixin.test_recvdChanged..stringReceiveds" MM. )rr_sbbbbbN)rrWrrbrc) rpayloadCrpayloadApayloadBmessageAmessageBrerr]s @@@rtest_recvdChangedz%RecvdAttributeMixin.test_recvdChangeds    ##Ax0 * *##Ax0##Ax0 x(*+ (H!56rc|jg}d|jD]4}|j|j||j6gfd}|_j dj |j d|j|j|jjdy)z Data already parsed by L{IntNStringReceiver.dataReceived} is not reparsed if C{stringReceived} consumes some of the L{IntNStringReceiver.recvd} buffer. scbj|jtd_yr)rr[rL)r\SWITCHrr]s rrz:RecvdAttributeMixin.test_switching..stringReceiveds% MM. )++c&km4EKrrN) rrrrWrrbrrcr[)rmixrjrrnrr]s @@@rtest_switchingz"RecvdAttributeMixin.test_switchings   "$ A JJt''q1 2 JJv   5 . 388C=) 7# . g.rc|jd}t|dz _|j|}gfd}|_j ||j dt||j d|y)z The L{IntNStringReceiver.recvd} buffer contains all data not yet processed by L{IntNStringReceiver.dataReceived} if the C{lengthLimitExceeded} event occurs. stoo longr#c^j|jjyrrZ)rErr]s rrNzPRecvdAttributeMixin.test_recvdInLengthLimitExceeded..lengthLimitExceededs MM& ! MM%++ &rrN)rrLrOrWrNrbrc)rDATAmessagerNrr]s @@rtest_recvdInLengthLimitExceededz3RecvdAttributeMixin.test_recvdInLengthLimitExceededs   "t9q=""5$/ '%8! 7# CI. G,rN) r(r)r*r+rWrbrkrqrvr-rrrUrUgs! D6$7./8-rrUceZdZdZy) TestInt32z A L{basic.Int32StringReceiver} storing received strings in an array. @ivar received: array holding received strings. Nr(r)r*r+r-rrrxrxrrxc0eZdZdZeZddgZdgZgdZdZ y) Int32Testsz/ Test case for int32-prefixed protocol rZrIs aaaaaa)s hello thererc|j}|jd|j|jj d|j d|j|j dgy)z? Test specific behavior of the 32-bits length. rsfoosubarubarNrrrcrGrrbr6rKs r test_datazInt32Tests.test_datas_     V **,.DE ./ gY/rN) r(r)r*r+rxrrrr@rr-rrr|r|s*HYG/0N;N0rr|ceZdZdZy) TestInt16z A L{basic.Int16StringReceiver} storing received strings in an array. @ivar received: array holding received strings. Nryr-rrrrrzrrc6eZdZdZeZddgZdgZgdZdZ dZ y) Int16Testsz/ Test case for int16-prefixed protocol rZrIsaaaaaa)r}rc|j}|jd|j|jj d|j d|j|j dgy)z? Test specific behavior of the 16-bits length. rsfoosubarrNrrKs rrzInt16Tests.test_datas]     V **,n= ' gY/rc|j}dd|jdzzdzz}|jt|j|yzA Send too much data: that should cause an error. r#rr#Nr prefixLengthrAssertionErrorrrrtooSends rtest_tooLongSendzInt16Tests.test_tooLongSend E    ! 23a78 .!,,@rN) r(r)r*r+rrrrr@rrr-rrrrs0HYG'(N3N0ArrceZdZdZy)TestInt8z A L{basic.Int8StringReceiver} storing received strings in an array. @ivar received: array holding received strings. Nryr-rrrrrzrrc6eZdZdZeZddgZdgZgdZdZ dZ y) Int8Testsz. Test case for int8-prefixed protocol rZrIsaaaaaa)sdzadzrc|j}|jd|j|jj d|j d|j|j dgy)z> Test specific behavior of the 8-bits length. rsfoosubarrNrrKs rrzInt8Tests.test_data%s]     V **,j9 {# gY/rc|j}dd|jdzzdzz}|jt|j|yrrrs rrzInt8Tests.test_tooLongSend/rrN) r(r)r*r+rrrrr@rrr-rrrrs0HYG'(N-N0Arrc0eZdZdZdZdZdZdZdZdZ y)OnlyProducerTransportzm Transport which isn't really a transport, just looks like one to someone not looking very hard. Fcg|_yrrrs rrzOnlyProducerTransport.__init__As  rcd|_y)NTpausedrs rr@z$OnlyProducerTransport.pauseProducingDs  rcd|_y)NFrrs rrBz%OnlyProducerTransport.resumeProducingGs  rc:|jj|yr)r&r)rrs rrzOnlyProducerTransport.writeJs rN) r(r)r*r+rrrr@rBrr-rrrr8s' FM rrceZdZdZdZy)ConsumingProtocolzC Protocol that really, really doesn't want any more bytes. cZ|jj||jyr)rGrr@rs rr!zConsumingProtocol.lineReceivedSs  T" rN)r(r)r*r+r!r-rrrrNs rrceZdZdZdZy) ProducerTestszM Tests for L{basic._PausableMixin} and L{basic.LineReceiver.paused}. ct}t}|j||jd|j |j g|j |j|j |j|jd|j |j dg|j|j|j|j|j|j |j dg|j |j|j |j|jd|j |j ddg|j|j|j|j|j|j |j gd|j|j|j|j|jd|j |j gd|j|j|j|j|j|j |j gd|j|j|j|j|j|j |j gd|j |j|j |jy ) a? When L{basic.LineReceiver} is paused, it doesn't deliver lines to L{basic.LineReceiver.lineReceived} and delivers them immediately upon being resumed. L{ConsumingProtocol} is a L{LineReceiver} that pauses itself after every line, and writes that line to its transport. shello, sworld hello, worldshello world r)rrrs goodbye )rrrrN) rrr_rbrcr&rrrrB)rprgs rtest_pauseResumezProducerTests.test_pauseResume]sN   ! #  z" $ " " |$ /!23 ! !  /!23 " " ,- /8!<= ! !  !FG ! ! ~& !FG ! !  !RS ! !  !RS " "rN)r(r)r*r+rr-rrrrXs A#rrc4eZdZdZdZdZdZdZdZdZ y) FileSenderTestsz( Tests for L{basic.FileSender}. cjtj}|jtt|y)zP L{basic.FileSender} implements the L{IPullProducer} interface. N)r FileSenderrrr )rsenders rtest_interfacezFileSenderTests.test_interfaces%!!#  Y78rctd}tj}tj}|j |||j |j||j|jy)z When L{basic.FileSender.beginFileTransfer} is called, it registers itself with provided consumer, as a non-streaming producer. Test contentN) rrrr rbeginFileTransferrcproducerr streaming)rsourceconsumerrs rtest_producerRegisteredz'FileSenderTests.test_producerRegisteredsd ) 002!!#  2 **F3 ++,rctd}tj}tj}|j ||}|j |j |j|j|jd|j||jd|jy)z L{basic.FileSender} sends the content of the given file using a C{IConsumer} interface via C{beginFileTransfer}. It returns a L{Deferred} which fires with the last byte sent. rtN) rrrr rrrB assertIsNonerrcsuccessResultOfrrrrrds r test_transferzFileSenderTests.test_transfers ) 002!!#  $ $VX 6   (++, t33A67 (..*:;rc^td}tj}tj}d|_|j ||}|j|jd|j|j|jd|j|j|jd|j|j|jd|j||jd|jy)zj L{basic.FileSender} reads at most C{CHUNK_SIZE} every time it resumes producing. rr=sTestsTest conrN) rrrr r CHUNK_SIZErrBrcrrrs rtest_transferMultipleChunksz+FileSenderTests.test_transferMultipleChunkss ) 002!!#  $ $VX 6  (.."23  hnn&67  (..*:;  t33A67 (..*:;rcXd}td}tj}tj}|j |||}|j |j |jd|j||jd|jy)z L{basic.FileSender.beginFileTransfer} takes a C{transform} argument which allows to manipulate the data on the fly. c"|jSr)swapcase)chunks r transformz=FileSenderTests.test_transferWithTransform..transforms>># #rrTs tEST CONTENTN) rrrr rrrBrcrr)rrrrrrs rtest_transferWithTransformz*FileSenderTests.test_transferWithTransforms  $) 002!!#  $ $VXy A   t33A67 (..*:;rcDtd}tj}tj}|j ||}|j |j|}|jt|jdt|jy)z The C{Deferred} returned by L{basic.FileSender.beginFileTransfer} fails with an C{Exception} if C{stopProducing} when the transfer is not complete. rz#Consumer asked us to stop producingN) rrrr rrrCfailureResultOftrap Exceptionrcstrr)rrrrrfailures rtest_abortedTransferz$FileSenderTests.test_abortedTransfers~ ) 002!!#  $ $VX 6&&q) Y >GMM@RSrN) r(r)r*r+rrrrrrr-rrrrs&9 -<$<.<(Trr);r+rBriortypingrrrzope.interface.verifyrtwisted.internetrr twisted.internet.interfacesr twisted.internet.protocolr twisted.protocolsr twisted.python.compatr twisted.python.failurer twisted.testr twisted.trialrrrr/rrRSynchronousTestCaserWrrrrr<rrrr?rUInt32StringReceiverrxr|Int16StringReceiverrrInt8StringReceiverrrrrrTestCaserr-rrrs  ''.+14#+*&"#++#0E:##E:P#U++#*uJ44uJp$%"4"4$.L1(*F*FL1^)JH88)JX   Iu66 772ULX99?ULpFLFLRg-g-T 5440--/@BU0* 544A--/@BUA:y%22A,,.?ATA:  ,**F#H00F#RdTh''dTr