B €/g^N:c@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ÚcodecsZlookupÚencodingÚencodeÚdecodeZ streamreaderÚreaderZ 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)Z.0Úlinerrrz *sz-TestBase.test_chunkcoding..rúutf-8) ÚtstringÚsplitZpopÚappendZzipr Ú assertEqualÚ roundtriptestr )rZ tstring_linesZbZlinesZlastZnativeÚ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)Nrú%a.decode(%r, %r)=%a != %aú%a.encode(%r, %r)=%a != %a) Ú codectestsÚ isinstanceÚbytesr r Ú assertTrueÚtypeÚstrrr Ú assertRaisesÚ UnicodeError©rZsourceZschemeZexpectedÚfuncZresultrrrÚtest_errorhandle2s$      zTestBase.test_errorhandlecCs0|jr| d¡d}| | |d¡dd¡dS)Nú$encoding contains full ISO 10646 mapuଓଣୠ nd eggsZxmlcharrefreplacersଓଣୠ nd eggs)Ú has_iso10646ÚskipTestrr )rÚsrrrÚtest_xmlcharrefreplaceIs  zTestBase.test_xmlcharrefreplacecsj|jr| d¡ddlm‰‡fdd„}t d|¡|jrF|j\}}nd}d}| | |d¡d|¡dS) Nr.r©Ú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ÚobjectZstartÚendÚordrÚjoin)ÚexcZlZcr3rrÚxmlcharnamereplaceYs   z>TestBase.test_customreplace_encode..xmlcharnamereplaceztest.xmlcharnamereplaceu«ℜ» = 〈ሴ〉s*«ℜ» = ⟨ሴ⟩) r/r0Z html.entitiesr4r Úregister_errorÚxmlcharnametestrr )rr<ZsinZsoutrr3rÚtest_customreplace_encodeSs     z"TestBase.test_customreplace_encodecCs>dd„}t d|¡| d|jdd¡d}| |d¡dS)NcSó d|jfS)Ns1234©r8©r;rrrÚ myreplaceoóz7TestBase.test_callback_returns_bytes..myreplaceú test.cjktestZabcZdefrs abc1234def)r r=r Úunmappedunicoder)rrCZencrrrÚtest_callback_returns_bytesns z$TestBase.test_callback_returns_bytescsN‡fdd„}t d|¡x0dddggdtƒfD]‰| t|j|jd¡q.WdS)Ncs ˆ|jfSrrArB©ZretrrrCvrDz7TestBase.test_callback_wrong_objects..myreplacerEréé)r r=r7r)r6r rF©rrCrrHrÚ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)Úintr8rBrrrrCrDz4TestBase.test_callback_long_index..myreplacerEÚabcdÚefgh)s abcdxefghé cSsdtjdfS)NrMr)ÚsysZmaxsizerBrrrrC…rD)r r=rr rFr)Ú IndexErrorrKrrrÚtest_callback_long_index~s   z!TestBase.test_callback_long_indexcCó,dd„}t d|¡| t|j|jd¡dS)NcSódS)N)rMNrrBrrrrCŒrDz4TestBase.test_callback_None_index..myreplacerE)r r=r)r6r rFrKrrrÚtest_callback_None_index‹ó z!TestBase.test_callback_None_indexcs@‡fdd„‰dˆ_t dˆ¡| | d|jdd¡d¡dS)Ncs*ˆjdkrˆjd8_dSd|jfSdS)Nrr)ÚREPLACEDrZTERMINAL)Úlimitr8rB©rCrrrC“s z8TestBase.test_callback_backward_index..myreplacerJrErOrP)s4abcdREPLACEDabcdREPLACEDabcdREPLACEDabcdTERMINALefghrQ)rZr r=rr rFrrr[rÚtest_callback_backward_index’s   z%TestBase.test_callback_backward_indexcCs6dd„}t d|¡| | d|jdd¡d¡dS)NcSsd|jdfS)NrYrIrArBrrrrC rDz7TestBase.test_callback_forward_index..myreplacerErOrP)sabcdREPLACEDghrQ)r r=rr rFrKrrrÚtest_callback_forward_indexŸs z$TestBase.test_callback_forward_indexcCrU)NcSrV)N)ZTERMidrrBrrrrC§rDz:TestBase.test_callback_index_outofbound..myreplacerE)r r=r)rSr rFrKrrrÚtest_callback_index_outofbound¦rXz'TestBase.test_callback_index_outofboundcCs¬t d¡}xœdgttddƒƒdddddgD]v}|t|jdƒƒ}tƒ}| ¡}x:|dk rh| |¡}n| ¡}|svP| |¡}|  |¡qTW|  |  ¡|jd ¡q.WdS) Nrré!é@é€ééér) r Ú getreaderÚlistÚrangerrrÚreadr ÚwriterÚgetvalue)rÚ UTF8ReaderÚsizehintÚistreamÚostreamZencoderÚdataÚerrrÚtest_incrementalencoder­s   z TestBase.test_incrementalencodercCsžt d¡}xŽddgttddƒƒddddd gD]f}t|jd ƒ}|tƒƒ}| ¡}x*| |¡}|shPqV| |¡}|  |¡qVW|  |  ¡|jd¡q0WdS) Nréÿÿÿÿrr_r`rarbrcrdr) r Ú getwriterrfrgrrrrhr rirrj)rÚ UTF8WriterrlrmrnZdecoderrorrrrÚtest_incrementaldecoderÁs    z TestBase.test_incrementaldecodercCsŽ|j}| ¡}| t|j|d¡d|_| | |d¡d¡| ¡dd„}t  d|¡d|_| | |d¡d¡d|_| | |d¡d¡dS)NTZignoreócSr@)NZcalledrArBrrrÚ tempreplaceÜrDzDTestBase.test_incrementalencoder_error_callback..tempreplaceztest.incremental_error_callbackscalled) rFrr)r5r ÚerrorsrÚresetr r=)rZinvrprwrrrÚ&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) Nr©rhZreadlineÚ readlinesrrrr_r`rarbrcrdrr|) r rsrfrgr rrÚgetattrÚ writelinesrirrj)rrtÚnamerlrmrnr,rorrrÚ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 ¡qrFrr r-r2r?rGrLrTrWr\r]r^rqrurzr€rr‚rƒrrrrrs6     rc@s\eZdZgZgZgZgZdd„Zdd„Zdd„Z dd„Z d d „Z d d „Z d d„Z dd„ZdS)ÚTestBase_Mappingc Cs>y| ¡ ¡Wn(ttfk r8| d|j¡YnXdS)NzCould not retrieve )Úopen_mapping_fileZcloseZOSErrorrr0Ú mapfileurlrrrrr$szTestBase_Mapping.setUpcCs t |j¡Sr)rZopen_urlresourcer‰rrrrrˆ*rDz"TestBase_Mapping.open_mapping_filecCs"|j d¡r| ¡n| ¡dS)Nz.xml)r‰ZendswithÚ_test_mapping_file_ucmÚ_test_mapping_file_plainrrrrÚ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)Nrz+)r:ZmapÚchrÚevalr)r1rrrZ4rvz;TestBase_Mapping._test_mapping_file_plain..z#rrIiiÿiiéiirbriýÿ)rˆrZstripZlenrŽr%r9Ú _testpoint) rZunichrsZurt_waÚfrroZcsetvalÚcsetchÚunichrrrr‹3s4    z)TestBase_Mapping._test_mapping_file_plainc Csb| ¡}| ¡}WdQRXt d|¡}x4|D],\}}tt|dƒƒ}t |¡}| ||¡q.WdS)Nz'r) rˆrhÚreZfindallrrNr%Zfromhexr)rr‘ZucmdataZucZuniZcodedr“ZcodechrrrrŠTs   z'TestBase_Mapping._test_mapping_file_ucmcCsx|jD]}|j|ŽqWdSr)Úsupmapsr)rZmappingrrrÚtest_mapping_supplemental]s z*TestBase_Mapping.test_mapping_supplementalcCsH||f|jkr"| | |j¡|¡||f|jkrD| t||jƒ|¡dSr)Ú pass_enctestrr r Ú pass_dectestr()rr’r“rrrraszTestBase_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)Nr!r") r#r$r%r r r r&r'r(rr)r*r+rrrr-gs&        z!TestBase_Mapping.test_errorhandleN)r„r…r†r—r˜r•r#rrˆrŒr‹rŠr–rr-rrrrr‡s! r‡c Csvtj tj t¡d¡}ttj ||d¡dƒ}| ¡}WdQRXttj ||d¡dƒ}| ¡}WdQRX||fS)NZ cjkencodingsz.txtZrbz -utf8.txt)ÚosZpathr:ZdirnameZ__file__Zopenrh)rZdirr‘ZencodedrrrrÚload_teststrings rš)r r™r”rRZunittestZ http.clientrZtestrZiorrZTestCaser‡ršrrrrZs   a