Ϫf}DddlZddlmZmZddlmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZddlmZddlmZddlmZddlmZmZddlmZd Zd Zd Zd Z e!Z"d Z#dZ$e$ddgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgd gejJd!"Z&e$d#ddd$gdd%gd&d'gd(d)gdd*gd+d,gd-d.gd/d0gd1d2gd3dgd4d5gd6d7gd8d9gd:d;gdd?ggejJd@"Z'GdAdBZ(GdCdDZ)dEZ*GdFdGe)Z+[*GdHdIe+ejXZ-GdJdKe+ejXZ.GdLdMe+ejXZ/GdNdOe+ejXZ0GdPdQejXe)Z1GdRdSejXZ2y)TN)OptionalType) BLINK CS_ALTERNATECS_ALTERNATE_SPECIAL CS_DRAWINGCS_UKCS_USG0G1 UNDERLINEClientProtocolServerProtocolmodes privateModes)Protocol)StringTransport) iterbytes) ValueConstantValues)unittestc(tt| |SN)superMock__getattribute__)mocknames A/usr/lib/python3/dist-packages/twisted/conch/test/test_insults.py_getattrr s t -d 33ct|dS)N occurrencesr rs rr#r#"s D- ((r!ct|dS)Nmethodsr$r%s rr'r'&s D) $$r!c8t|j|yr)r#append)robjs r_appendr+*sS!r!c8tt|dz|zgS)a Return the byte in 7- or 8-bit code table identified by C{column} and C{row}. "An 8-bit code table consists of 256 positions arranged in 16 columns and 16 rows. The columns and rows are numbered 00 to 15." "A 7-bit code table consists of 128 positions arranged in 8 columns and 16 rows. The columns are numbered 00 to 07 and the rows 00 to 15 (see figure 1)." p.5 of "Standard ECMA-35: Character Code Structure and Extension Techniques", 6th Edition (December 1994). )bytes bytearray)columnrows r_ecmaCodeTableCoordinater21s " Vq[C/01 22r!ct|Dcic]3\}}t|D] \}}|r|tt||z|"5}}}}}||d<ttf|Scc}}}}w)N__doc__) enumeraterr2typer)r colOffsetnamesdocjr1iattrss r_makeControlFunctionSymbolsr=Es &   As ~  At  m4Q]AFGG   E  E) vi '' s8A% CSFinalByter-)ICHDCHHPA)CUUSSEHPR)CUDCPRREP)CUFSUDA)CUBSDVPA)CNLNPVPR)CPLPPHVP)CHACTCTBC)CUPECHSM)CHTCVTMC)EDCBTHPB)ELSRSVPB)ILPTXRM)DLSDSSGR)EFSIMDDSR)EANDAQaW Symbolic constants for all control sequence final bytes that do not imply intermediate bytes. This happens to cover movement control sequences. See page 11 of "Standard ECMA 48: Control Functions for Coded Character Sets", 5th Edition (June 1991). Each L{ValueConstant} maps a control sequence name to L{bytes} )r7r8r9 C1SevenBitDCSPU1BPHPU2NBHSTSCCHNELMWSSASPAESAEPAHTSSOSHTJVTSSCIPLDCSIPLUSTRIOSCSS2PMSS3APCa Symbolic constants for all 7 bit versions of the C1 control functions See page 9 "Standard ECMA 48: Control Functions for Coded Character Sets", 5th Edition (June 1991). Each L{ValueConstant} maps a control sequence name to L{bytes} c(eZdZeZdefdZdZdZy)rNcHg|_|i}||_|tur||_yy)z @param methods: Mapping of names to return values @param callReturnValue: object __call__ should return N)r#r'defaultcallReturnValue)selfr'rs r__init__z Mock.__init__s2  ?G ' )#2D  *r!cbt|d}|tur t}t|d|||f|S)Nr__call__)r rrr+)rakw returnValues rrz Mock.__call__s7t%67 ' !&Kz;267r!cvt|d}||vrt||}n t}t|||f|S)Nr')r)r rr+)rrr' attrValues rrzMock.__getattribute__s?4+ 7?WT];IItY'(r!)__name__ __module__ __qualname__rrrrrr!rrrsO#W 3r!rceZdZdifdZy) MockMixinrc |\}}|j|||jtt|dt|\\}}} } |j|d|j| ||j| ||S)Nr) assertEquallenr#) r occurrence methodNameexpectedPositionalArgsexpectedKeywordArgsattrrcallresultargsrs r assertCallzMockMixin.assertCalls d z* [./3%0%6" !$b z* 56 01 r!N)rrrrrr!rrrs =?UW r!radef testByte%(groupName)s(self): transport = StringTransport() proto = Mock() parser = self.protocolFactory(lambda: proto) parser.factory = self parser.makeConnection(transport) bytes = self.TEST_BYTES while bytes: chunk = bytes[:%(bytesPer)d] bytes = bytes[%(bytesPer)d:] parser.dataReceived(chunk) self.verifyResults(transport, proto, parser) cbeZdZUdZeeeed<dD]\ZZ e e ee dz[[ dZ y)ByteGroupingsMixinNprotocolFactory))Pairs)Triples)Quadsr-)Quints)Sexes) groupNamebytesPerc|jt|jdd|f}|jt|gy)NrmakeConnection)rr#popr)r transportprotoparserrs r verifyResultsz ByteGroupingsMixin.verifyResultss<U!3!7!7!: F   [0" 5 6 U+,r!Nrrrrr TEST_BYTESrrr!rrrs$O-J -r!rceZdZeZdZdZy)PrintableCharactersTestssabc123ABC!@#abc123ctj||||tdD]J}|jt |j dd|df}|j t |gLtdD]T}|jt |j dd||jf}|j t |gVt |}|j||dy)Ns abc123ABC!@#rrsabc123z should have been []) rrrrr#rrALTr)rrrrcharroccss rrz&PrintableCharactersTests.verifyResultss((y%Ho. 6D__E"&&q)+>t F   [0" 5  6 i( 6D__E"&&q)+>vzz@RF   [0" 5  6 5! $)=>?r!Nrrr!rrrs$O ?J@r!rczeZdZdZeZgZdD]ZejdezdjeZ [[dZ y)ServerFunctionKeysTestsz9Test for parsing and dispatching function keys (F1 - F12)) sOPsOQsORsOSs15~s17~s18~s19~s20~s21~s23~s24~!c:tj||||tddD]Z}t|d|fz}|j t |j dd|df}|jt |g\|jt |y)Nr zF%drr) rrrangegetattrrr#rrr)rrrrfuncNumfuncArgrs rrz%ServerFunctionKeysTests.verifyResults;s((y%HQ| 6Gfewj&89G__E"&&q)+>$F   [0" 5  6 U+,r!N) rrrr4rrbyteList byteCodesr)joinrrrr!rrr#sMC$OH .  9,-.(#J)-r!rcPeZdZeZdZdZdZdZeezezezezezZ [[[[dZ y)ClientCursorMovementTestsssssctj||||dD]O\}}|jt|j dd|z|f}|j t|gQ|j t|y)N))Downr)Forwardr-UprBackwardrrrrcursor)rrrr#rrr)rrrrmethodcountrs rrz'ClientCursorMovementTests.verifyResultsQs((y%H 6MFE__E"&&q)8f+z3ClientControlSequencesTests.setUp..gs TZZr!rr) rrrrrrfactoryrrr#rr)rrs` rsetUpz!ClientControlSequencesTests.setUpds(*V $%78 "  ""4>>2  # ' ' *,zBClientControlSequencesTests.testSimpleCardinals..qs631 r!!ssBACD)rrrr)rrrr) r dataReceivedrrr#rrrr)rrmethrrs rtestSimpleCardinalsz/ClientControlSequencesTests.testSimpleCardinalsos   HH#G,  4::&9 6D( 6!hoxP  V!45 6 6 r!cv|jjdt|j}|j |j ddd}|j t||j |j ddd}|j t||j |y)Ns rsetScrollRegion)r)NNrrr#rrrrrrrs rtestScrollRegionz,ClientControlSequencesTests.testScrollRegions   !454::&!.?I V,-!.?N V,- r!cb|jjdt|j}|j |j ddd}|j t||j |j ddd}|j t||j |j dd}|j t||j |j dd}|j t||j |y)Ns #3#4#5#6rdoubleHeightLine)T)FsingleWidthLinedoubleWidthLiner r s rtestHeightAndWidthz.ClientControlSequencesTests.testHeightAndWidths   !<=4::&!.@'J V,-!.@(K V,-!.?@ V,-!.?@ V,- r!c"|jjdjtdDcgc]0}djtdDcgc] }d|z|z c}2c}}t |j }t tfD]`}tttttfD]@}|j|jdd||f}|jt |Bb|j|ycc}wcc}}w)Nr!s()sAB012rselectCharacterSet)rrrrr#rr r r r rrrrrr)rgrrwhichcharsetrs rtestCharacterSetz,ClientControlSequencesTests.testCharacterSets   HH'u-HHy7JK!gkAoKL  4::&"X 6E$  6HHQK!57G  V!45 6 6 'LsD  D D D cr|jjdt|j}|j |j dd}|j t||j |j dd}|j t||j |y)NsrshiftInshiftOutr r s r testShiftingz(ClientControlSequencesTests.testShiftings   -4::&!i8 V,-!j9 V,- r!cr|jjdt|j}|j |j dd}|j t||j |j dd}|j t||j |y)NsNOr singleShift2 singleShift3r r s rtestSingleShiftsz,ClientControlSequencesTests.testSingleShiftss   /4::&!n= V,-!n= V,- r!cr|jjdt|j}|j |j dd}|j t||j |j dd}|j t||j |y)Ns=>rapplicationKeypadModenumericKeypadModer r s rtestKeypadModez*ClientControlSequencesTests.testKeypadModes   /4::&!.EF V,-!.AB V,- r!cr|jjdt|j}|j |j dd}|j t||j |j dd}|j t||j |y)Ns78r saveCursor restoreCursorr r s r testCursorz&ClientControlSequencesTests.testCursors   /4::&!l; V,-!o> V,- r!c|jjdt|j}|j |j dd}|j t||j |y)Nscrresetr r s r testResetz%ClientControlSequencesTests.testResets[   *4::&!g6 V,- r!c|jjdt|j}|j |j dd}|j t||j |j dd}|j t||j |j dd}|j t||j |y)NsDMErindex reverseIndexnextLiner r s r testIndexz%ClientControlSequencesTests.testIndexs   !344::&!g6 V,-!n= V,-!j9 V,- r!c |jjddjdtjtj tj fDzdz|jjddjdtjtj tj fDzdzt|j}|j|jddtjtj tj gf}|jt||j|jdd tjtj tj gf}|jt||j|y) Nr;c3(K|] }d|fz yws%dNrrms rrz8ClientControlSequencesTests.testModes..P Phc3(K|] }d|fz ywr3rr4s rrz8ClientControlSequencesTests.testModes..r6r7lrsetModes resetModes) rrrrKAMIRMLNMr#rrrrr s r testModesz%ClientControlSequencesTests.testModessB   iiPuyy%))UYY.OPP Q    iiPuyy%))UYY.OPP Q  4::& HHQKuyy%))UYY&G%I  V,- HHQKEIIuyy(I'K  V,- r!c|jjdt|j}dD]=}|j |j d|}|j t|?|j |j ddd}|j t||j |y)Ns)eraseToLineEnderaseToLineBeginning eraseLineeraseToDisplayEnderaseToDisplayBeginning eraseDisplayrdeleteCharacter)rr )rrrrs r testErasurez'ClientControlSequencesTests.testErasures   !ST4::& 2D__TXXa[$7F   [0 1 2!.?F V,- r!c|jjdt|j}dD]?}|j |j dd|f}|j t|A|j |y)Nsrrr deleteLiner rrargrs rtestLineDeletionz,ClientControlSequencesTests.testLineDeletion!q   !124::& 2C__TXXa[,GF   [0 1 2 r!c|jjdt|j}dD]?}|j |j dd|f}|j t|A|j |y)NsrKr insertLiner rMs rtestLineInsertionz-ClientControlSequencesTests.testLineInsertion*rPr!cNdt|jd<|jjd|j |j j dt|j}|j|jdd}|j |dy)N)rreportCursorPositionssr) r'rrrrrvaluer#rrr s rtestCursorPositionz.ClientControlSequencesTests.testCursorPosition3s~6< 23   , --/>4::&!.DE (r!c"t|j}|jjd|j |j ddd|jjd|j |j dddy)z Contiguous non-control bytes are passed to a single call to the C{write} method of the terminal to which the L{ClientProtocol} is connected. arwrite)rZbc)r\N)r#rrrrr)rrs rtest_applicationDataBytesz5ClientControlSequencesTests.test_applicationDataBytes>sf 4::&   &  Wg6   '  Wh7r!ct|j}|jj||r4|j|j dg|j d|r4|j |d|y)NrzNo other calls should happen: )r#rrrrrr)rdatacallsrs r_applicationDataTestz0ClientControlSequencesTests._applicationDataTestJse4::&   & DOODHHQK 7%))A, 7 !?xHIr!c,|jdddgy)z Application data bytes followed by a shift-in command are passed to a call to C{write} before the terminal's C{shiftIn} method is called. sabr[)sab)rNrars r test_shiftInAfterApplicationDataz !!*/BJ.OP !! .qcV0DE r!N)rrrrrr rrrrr#r'r*r/r@rIrOrSrXr]rarergrjrlrr!rrrcst . "2     0& ) 8JRSY  r!rceZdZdZeddZeeddzZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%y$)%ServerProtocolOutputTestszh Tests for the bytes L{ServerProtocol} writes to its transport when its methods are called. r rct|_t|_|jj |jyr)rprotocolrrrrs rrzServerProtocolOutputTests.setUps,&( (* $$T^^4r!c|jjd|j|jj |j dzt jjzy)z L{ServerProtocol.cursorUp} writes the control sequence ending with L{CSFinalByte.CUU} to its transport. r1N)rqcursorUprrrWrr>rBrs r test_cursorUpz'ServerProtocolOutputTests.test_cursorUpsM q!  NN "DHHtOkoo6K6K$K r!c|jjd|j|jj |j dzt jjzy)z L{ServerProtocol.cursorDown} writes the control sequence ending with L{CSFinalByte.CUD} to its transport. rrsN)rq cursorDownrrrWrr>rErs rtest_cursorDownz)ServerProtocolOutputTests.test_cursorDownsM   #  NN "DHHtOkoo6K6K$K r!c|jjd|j|jj |j dzt jjzy)z L{ServerProtocol.cursorForward} writes the control sequence ending with L{CSFinalByte.CUF} to its transport. rrsN)rq cursorForwardrrrWrr>rHrs rtest_cursorForwardz,ServerProtocolOutputTests.test_cursorForwardsM ##A&  NN "DHHtOkoo6K6K$K r!c|jjd|j|jj |j dzt jjzy)z L{ServerProtocol.cursorBackward} writes the control sequence ending with L{CSFinalByte.CUB} to its transport. rrsN)rqrirrrWrr>rKrs rtest_cursorBackwardz-ServerProtocolOutputTests.test_cursorBackwardsM $$Q'  NN "DHHtOkoo6K6K$K r!c|jjdd|j|jj |j dzt jjzy)z L{ServerProtocol.cursorPosition} writes a control sequence ending with L{CSFinalByte.CUP} and containing the expected coordinates to its transport. rs1;1N)rqcursorPositionrrrWrr>rWrs rtest_cursorPositionz-ServerProtocolOutputTests.test_cursorPositionsP $$Q*  NN "DHHv$5 8M8M$M r!c|jj|j|jj |j t jjzy)z L{ServerProtocol.cursorHome} writes a control sequence ending with L{CSFinalByte.CUP} and no parameters, so that the client defaults to (1, 1). N)rq cursorHomerrrWrr>rWrs rtest_cursorHomez)ServerProtocolOutputTests.test_cursorHomesD   " --/KOO.9 9r7N) rr=r>r?rqr;rrrWrrr>rYr modesToSets r test_setModesz'ServerProtocolOutputTests.test_setModess| iiEII6  z*  NN " HHii9j99 :nn"" # r!chtjtjtjg}|jj ||j |jj|jdjd|Dztjjzy)z L{ServerProtocol.setPrivatesModes} writes a control sequence containing the requested private modes and ending in the L{CSFinalByte.SM}. r1c3(K|] }d|fz ywr3rr4s rrzAServerProtocolOutputTests.test_setPrivateModes..s@ @r7N) rERRORCOLUMNORIGINrqr;rrrWrrr>rY)rprivateModesToSets rtest_setPrivateModesz.ServerProtocolOutputTests.test_setPrivateModess           01  NN " HHii@.?@@ Ann"" # r!chtjtjtjg}|jj ||j |jj|jdjd|Dztjjzy)zs L{ServerProtocol.resetModes} writes the control sequence ending in the L{CSFinalByte.RM}. r1c3(K|] }d|fz ywr3rr4s rrz.rr7N) rr=r>r?rqr<rrrWrrr>rers rtest_resetModesz)ServerProtocolOutputTests.test_resetModess| iiEII6    ,  NN " HHii9j99 :nn"" # r!c|jj|j|jj |j t jjzy)zp L{ServerProtocol.singleShift2} writes an escape sequence followed by L{C1SevenBit.SS2} N)rqrrrrWrrnrrs rtest_singleShift2z+ServerProtocolOutputTests.test_singleShift2D ""$ --/JNNrhrs rtest_selectGraphicRenditionz5ServerProtocolOutputTests.test_selectGraphicRendition$sc ,,SZYH  NN " HHx5)"44 4{7L7L L r!c|jj|j|jj |j t jjzy)zz L{ServerProtocol.horizontalTabulationSet} writes the escape sequence ending in L{C1SevenBit.HTS} N)rqhorizontalTabulationSetrrrWrrnr|rs rtest_horizontalTabulationSetz6ServerProtocolOutputTests.test_horizontalTabulationSet0sD --/ --/JNNr`rs rtest_eraseToLineEndz-ServerProtocolOutputTests.test_eraseToLineEnd8sD $$& --/KNNr`rs rtest_eraseToLineBeginningz3ServerProtocolOutputTests.test_eraseToLineBeginningBsH **, --/D;>>CWCW1WXr!c|jj|j|jj |j dzt jjzy)z L{ServerProtocol.eraseLine} writes the control sequence sequence ending in L{CSFinalByte.EL} and a parameter of 2 (the entire line.) rN)rqrDrrrWrr>r`rs rtest_eraseLinez(ServerProtocolOutputTests.test_eraseLineLsH ! --/D;>>CWCW1WXr!c|jj|j|jj |j t jjzy)a L{ServerProtocol.eraseToDisplayEnd} writes the control sequence sequence ending in L{CSFinalByte.ED} and no parameters, forcing the client to default to 0 (from the active present position's current location to the end of the page.) N)rqrErrrWrr>r]rs rtest_eraseToDisplayEndz0ServerProtocolOutputTests.test_eraseToDisplayEndUsD '') --/KNNr]rs rtest_eraseToDisplayBeginningz6ServerProtocolOutputTests.test_eraseToDisplayBeginning_sH --/ --/D;>>CWCW1WXr!c|jj|j|jj |j dzt jjzy)z L{ServerProtocol.eraseDisplay} writes the control sequence sequence ending in L{CSFinalByte.ED} a parameter of 2 (the entire page) rN)rqrGrrrWrr>r]rs rtest_eraseToDisplayz-ServerProtocolOutputTests.test_eraseToDisplayisH ""$ --/D;>>CWCW1WXr!c|jjd|j|jj |j dzt jjzy)z L{ServerProtocol.deleteCharacter} writes the control sequence containing the number of characters to delete and ending in L{CSFinalByte.DCH} r-4N)rqrHrrrWrr>r@rs rtest_deleteCharacterz.ServerProtocolOutputTests.test_deleteCharacterrsM %%a(  NN "DHHtOkoo6K6K$K r!c|jjd|j|jj |j dzt jjzy)z L{ServerProtocol.insertLine} writes the control sequence containing the number of lines to insert and ending in L{CSFinalByte.IL} r5N)rqrRrrrWrr>rcrs rtest_insertLinez)ServerProtocolOutputTests.test_insertLine}J   # --/D;>>CWCW1WXr!c|jjd|j|jj |j dzt jjzy)z L{ServerProtocol.deleteLine} writes the control sequence containing the number of lines to delete and ending in L{CSFinalByte.DL} r6N)rqrLrrrWrr>rfrs rtest_deleteLinez)ServerProtocolOutputTests.test_deleteLinerr!c|jj|j|jj |j dzdzy)z With no arguments, L{ServerProtocol.setScrollRegion} writes a control sequence with no parameters, but a parameter separator, and ending in C{b'r'}. r1rNrqrrrrWrrs rtest_setScrollRegionNoArgsz4ServerProtocolOutputTests.test_setScrollRegionNoArgss> %%' --/D41GHr!c|jjd|j|jj |j dzdzy)z With just a value for its C{first} argument, L{ServerProtocol.setScrollRegion} writes a control sequence with that parameter, a parameter separator, and finally a C{b'r'}. r)firsts1;rNrrs rtest_setScrollRegionJustFirstz7ServerProtocolOutputTests.test_setScrollRegionJustFirstsD %%A%. --/E1AD1HIr!c|jjd|j|jj |j dzdzy)z With just a value for its C{last} argument, L{ServerProtocol.setScrollRegion} writes a control sequence with a parameter separator, that parameter, and finally a C{b'r'}. r)lasts;1rNrrs rtest_setScrollRegionJustLastz6ServerProtocolOutputTests.test_setScrollRegionJustLastsD %%1%- --/E1AD1HIr!c|jjdd|j|jj |j dzdzy)z When given both C{first} and C{last} L{ServerProtocol.setScrollRegion} writes a control sequence with the first parameter, a parameter separator, the last parameter, and finally a C{b'r'}. rr)rrs1;2rNrrs r test_setScrollRegionFirstAndLastz:ServerProtocolOutputTests.test_setScrollRegionFirstAndLastsF %%AA%6 --/F1BT1IJr!c|jj|j|jj |j dzt jjzy)z L{ServerProtocol.reportCursorPosition} writes a control sequence ending in L{CSFinalByte.DSR} with a parameter of 6 (the Device Status Report returns the current active position.) rN)rqrVrrrWrr>rkrs rtest_reportCursorPositionz3ServerProtocolOutputTests.test_reportCursorPositionsK **,  NN "DHHtOkoo6K6K$K r!N)&rrrr4r2rrrrurxr{r}rrrrrrrrrrrrrrrrrrrrrrrrrrrr!rrnrnys #1b )C (B/ /C5       S  Q:   &  RR  RRYYRYY  YYIJJK  r!rn)3textwraptypingrrtwisted.conch.insults.insultsrrrrr r r r r rrrrtwisted.internet.protocolrtwisted.internet.testingrtwisted.python.compatrtwisted.python.constantsrr twisted.trialrr r#r'r+objectrr2r=dedentr>rnrrrrTestCaserrrrrrnrr!rrs !/4+:"4)%" (3( (* # &   -" J) u u   u         u  ! $   + DD  $22$--x/@/@-,@183D3D@6 -0(2C2C -F- 2H4E4E-:P ("3"3YP lE  1 1E r!