B €/g^N:ã@sxddlZddlZddlZddlZddlZddlmZddlmZddl m Z Gdd„dƒZ Gdd„dej ƒZ d d „ZdS) éN)Ú HTTPException)Úsupport)ÚBytesIOc@sÄeZdZdZdZdZdZdZdZdZ dZ dd„Z dd „Z d d „Z d d „Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„ZdS),ÚTestBaseÚNéruí»®cCsX|jdkrt |j¡|_|jj|_|jj|_|jj|_|jj|_ |jj |_ |jj |_ dS)N) ÚcodecÚcodecsÚlookupÚencodingÚencodeÚdecodeÚ streamreaderÚreaderÚ streamwriterÚwriterÚincrementalencoderÚincrementaldecoder)Úself©rú3/usr/lib64/python3.7/test/multibytecodec_support.pyÚsetUps      zTestBase.setUpcCs”g}x8|jD].}| d¡}| ¡}dd„|Dƒ}| |¡q WxPt|ŽD]D\}}| |¡d}| || d¡¡|jrH| || |¡d¡qHWdS)Nó cSsg|] }|d‘qS)rr)Ú.0Úlinerrrú *sz-TestBase.test_chunkcoding..rzutf-8) ÚtstringÚsplitÚpopÚappendÚzipr Ú assertEqualÚ roundtriptestr )rZ tstring_linesÚbÚlinesZlastZnativeÚutf8ÚurrrÚtest_chunkcoding$s  zTestBase.test_chunkcodingc CsÎxÈ|jD]¾\}}}t|tƒr$|j}n|j}|r¶|||ƒd}||jkr~| t|ƒtkt|ƒ¡| ||d||j |||f¡qÆ| t|ƒtkt|ƒ¡| ||d||j |||f¡q|  t |||¡qWdS)Nrz%a.decode(%r, %r)=%a != %az%a.encode(%r, %r)=%a != %a) Ú codectestsÚ isinstanceÚbytesr r Ú assertTrueÚtypeÚstrr!r Ú assertRaisesÚ UnicodeError)rÚsourceÚschemeÚexpectedÚfuncÚresultrrrÚtest_errorhandle2s$      zTestBase.test_errorhandlecCs0|jr| d¡d}| | |d¡dd¡dS)Nz$encoding contains full ISO 10646 mapuଓଣୠ nd eggsÚxmlcharrefreplacersଓଣୠ nd eggs)Ú has_iso10646ÚskipTestr!r )rÚsrrrÚtest_xmlcharrefreplaceIs  zTestBase.test_xmlcharrefreplacecsj|jr| d¡ddlm‰‡fdd„}t d|¡|jrF|j\}}nd}d}| | |d¡d|¡dS) Nz$encoding contains full ISO 10646 mapr)Úcodepoint2namecs|t|tƒstd|ƒ‚g}xP|j|j|j…D]:}t|ƒˆkrV| dˆt|ƒ¡q.| dt|ƒ¡q.Wd |¡|jfS)Nzdon't know how to handle %rz&%s;z&#%d;r) r)ÚUnicodeEncodeErrorÚ TypeErrorÚobjectÚstartÚendÚordrÚjoin)ÚexcÚlÚc)r;rrÚxmlcharnamereplaceYs   z>TestBase.test_customreplace_encode..xmlcharnamereplaceztest.xmlcharnamereplaceu«ℜ» = 〈ሴ〉s*«ℜ» = ⟨ሴ⟩) r7r8Z html.entitiesr;r Úregister_errorÚxmlcharnametestr!r )rrFZsinZsoutr)r;rÚtest_customreplace_encodeSs     z"TestBase.test_customreplace_encodecCs>dd„}t d|¡| d|jdd¡d}| |d¡dS)NcSs d|jfS)Ns1234)r@)rCrrrÚ myreplaceosz7TestBase.test_callback_returns_bytes..myreplacez test.cjktestÚabcÚdefrs abc1234def)r rGr Úunmappedunicoder!)rrJÚencrrrÚtest_callback_returns_bytesns z$TestBase.test_callback_returns_bytescsN‡fdd„}t d|¡x0dddggdtƒfD]‰| t|j|jd¡q.WdS)Ncs ˆ|jfS)N)r@)rC)ÚretrrrJvsz7TestBase.test_callback_wrong_objects..myreplacez test.cjktestréé)r rGr>r.r=r rM)rrJr)rPrÚtest_callback_wrong_objectsus   z$TestBase.test_callback_wrong_objectscCs^dd„}t d|¡| | d|jdd¡d¡dd„}t d|¡| t|j|jd¡dS)NcSsdt|jƒfS)NÚx)Úintr@)rCrrrrJsz4TestBase.test_callback_long_index..myreplacez test.cjktestÚabcdÚefgh)s abcdxefghé cSsdtjdfS)NrTr)ÚsysÚmaxsize)rCrrrrJ…s)r rGr!r rMr.Ú IndexError)rrJrrrÚtest_callback_long_index~s   z!TestBase.test_callback_long_indexcCs,dd„}t d|¡| t|j|jd¡dS)NcSsdS)N)rTNr)rCrrrrJŒsz4TestBase.test_callback_None_index..myreplacez test.cjktest)r rGr.r=r rM)rrJrrrÚtest_callback_None_index‹s z!TestBase.test_callback_None_indexcs@‡fdd„‰dˆ_t dˆ¡| | d|jdd¡d¡dS)Ncs*ˆjdkrˆjd8_dSd|jfSdS)Nrr)ÚREPLACEDrZTERMINAL)Úlimitr@)rC)rJrrrJ“s z8TestBase.test_callback_backward_index..myreplacerRz test.cjktestrVrW)s4abcdREPLACEDabcdREPLACEDabcdREPLACEDabcdTERMINALefghrX)r_r rGr!r rM)rr)rJrÚtest_callback_backward_index’s   z%TestBase.test_callback_backward_indexcCs6dd„}t d|¡| | d|jdd¡d¡dS)NcSsd|jdfS)Nr^rQ)r@)rCrrrrJ sz7TestBase.test_callback_forward_index..myreplacez test.cjktestrVrW)sabcdREPLACEDghrX)r rGr!r rM)rrJrrrÚtest_callback_forward_indexŸs z$TestBase.test_callback_forward_indexcCs,dd„}t d|¡| t|j|jd¡dS)NcSsdS)N)ZTERMédr)rCrrrrJ§sz:TestBase.test_callback_index_outofbound..myreplacez test.cjktest)r rGr.r[r rM)rrJrrrÚtest_callback_index_outofbound¦s z'TestBase.test_callback_index_outofboundcCs¬t d¡}xœdgttddƒƒdddddgD]v}|t|jdƒƒ}tƒ}| ¡}x:|dk rh| |¡}n| ¡}|svP| |¡}|  |¡qTW|  |  ¡|jd ¡q.WdS) Nzutf-8ré!é@é€éiir) r Ú getreaderÚlistÚrangerrrÚreadr Úwriter!Úgetvalue)rÚ UTF8ReaderÚsizehintÚistreamÚostreamÚencoderÚdataÚerrrÚtest_incrementalencoder­s   z TestBase.test_incrementalencodercCsžt d¡}xŽddgttddƒƒddddd gD]f}t|jd ƒ}|tƒƒ}| ¡}x*| |¡}|shPqV| |¡}|  |¡qVW|  |  ¡|jd¡q0WdS) Nzutf-8éÿÿÿÿrrdrerfrgiir) r Ú getwriterrirjrrrrkr rlr!rm)rÚ UTF8WriterrorprqÚdecoderrsr&rrrÚtest_incrementaldecoderÁs    z TestBase.test_incrementaldecodercCsŽ|j}| ¡}| t|j|d¡d|_| | |d¡d¡| ¡dd„}t  d|¡d|_| | |d¡d¡d|_| | |d¡d¡dS)NTÚignoreócSs d|jfS)NZcalled)r@)rCrrrÚ tempreplaceÜszDTestBase.test_incrementalencoder_error_callback..tempreplaceztest.incremental_error_callbackscalled) rMrr.r<r Úerrorsr!Úresetr rG)rÚinvrtr}rrrÚ&test_incrementalencoder_error_callbackÒs z/TestBase.test_incrementalencoder_error_callbackcCsºt d¡}xªdD]¢}xœddgttddƒƒdddd d gD]t}| t|jd ƒ¡}|tƒƒ}t||ƒ}x0||ƒ}|svP|d krŠ| |¡qh|  |¡qhW|  |  ¡|jd¡q:WqWdS) Nzutf-8)rkÚreadlineÚ readlinesrvrrdrerfrgiirrƒ) r rwrirjrrrÚgetattrÚ writelinesrlr!rm)rrxÚnamerorprqr3rsrrrÚtest_streamreaderæs     zTestBase.test_streamreaderc CsÌd}t d¡}x¸|D]°}xªdgttddƒƒddddd gD]„}|t|jdƒƒ}| tƒ¡}t||ƒ}x@|dk r|||ƒ}n|ƒ}|sˆP|d krœ| |¡qj|  |¡qjW|  |  ¡|jd ¡qy| ¡ ¡Wn(ttfk r8| d|j¡YnXdS)NzCould not retrieve )Úopen_mapping_fileÚcloseÚOSErrorrr8Ú mapfileurl)rrrrr$szTestBase_Mapping.setUpcCs t |j¡S)N)rZopen_urlresourcer”)rrrrr‘*sz"TestBase_Mapping.open_mapping_filecCs"|j d¡r| ¡n| ¡dS)Nz.xml)r”ÚendswithÚ_test_mapping_file_ucmÚ_test_mapping_file_plain)rrrrÚtest_mapping_file-s  z"TestBase_Mapping.test_mapping_filec Cs8dd„}i}| ¡}x|D]}|s,P| d¡d ¡ ¡}t|ƒdkrPq t|dƒ}|dkrtt|d@gƒ}nz|dkr¦t|d ?|d ?d@|d ?d@|d@gƒ}nH|d krÎt|d ?|d ?d@|d@gƒ}n |d kr t|d ?|d@gƒ}nq ||dƒ}t|ƒdks ||krq |||<| ||¡q WWdQRXdS)Nc Ssd tttt| d¡ƒƒ¡S)Nrú+)rBÚmapÚchrÚevalr)r9rrrÚ4r|z;TestBase_Mapping._test_mapping_file_plain..ú#rrQééÿiéééirgriýÿ)r‘rÚstripÚlenrœr*rAÚ _testpoint) rZunichrsZurt_waÚfrrsZcsetvalÚcsetchÚunichrrrr—3s4    z)TestBase_Mapping._test_mapping_file_plainc Csb| ¡}| ¡}WdQRXt d|¡}x4|D],\}}tt|dƒƒ}t |¡}| ||¡q.WdS)Nz'r¢) r‘rkÚreÚfindallr›rUr*Úfromhexr¦)rr§ZucmdataZucZuniZcodedr©Zcodechrrrr–Ts   z'TestBase_Mapping._test_mapping_file_ucmcCsx|jD]}|j|ŽqWdS)N)Úsupmapsr¦)rÚmappingrrrÚtest_mapping_supplemental]s z*TestBase_Mapping.test_mapping_supplementalcCsH||f|jkr"| | |j¡|¡||f|jkrD| t||jƒ|¡dS)N)Ú pass_enctestr!r r Ú pass_dectestr-)rr¨r©rrrr¦aszTestBase_Mapping._testpointc CsÚxÔ|jD]Ê\}}}t|tƒr$|j}n|j}|rÀt|tƒr|||j|ƒ}| t|ƒtkt|ƒ¡|  ||d||j|||f¡qÒ||j|ƒ}| t|ƒtkt|ƒ¡|  ||d||j|||f¡q|  t ||j|¡qWdS)Nz%a.decode(%r, %r)=%a != %az%a.encode(%r, %r)=%a != %a) r(r)r*r r r r+r,r-r!r.r/)rr0r1r2r3r4rrrr5gs&        z!TestBase_Mapping.test_errorhandleN)rrŽrr°r±r­r(rr‘r˜r—r–r¯r¦r5rrrrrs! rc Csvtj tj t¡d¡}ttj ||d¡dƒ}| ¡}WdQRXttj ||d¡dƒ}| ¡}WdQRX||fS)NZ cjkencodingsz.txtÚrbz -utf8.txt)ÚosÚpathrBÚdirnameÚ__file__Úopenrk)r†Údirr§Zencodedr%rrrÚload_teststrings r¹)r r³rªrYZunittestZ http.clientrZtestrÚiorrZTestCaserr¹rrrrÚs   a