a  ze@sddlmZedZddlZddlZddlZddlZddl Z ddl Z ddl Z e dej ZGdddZGdd d eZejeed \ZZGd d d eZejeed \ZZGd ddZGdddeZejeed \ZZGdddeZejeed \ZZedkre dS))utilzimportlib.machineryNz&^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)c@speZdZdZdZdZdeeZdZddZ dd Z d d Z d d Z ddZ ddZddZddZddZdS) EncodingTestaPEP 3120 makes UTF-8 the default encoding for source code [default encoding]. PEP 263 specifies how that can change on a per-file basis. Either the first or second line can contain the encoding line [encoding first line] [encoding second line]. If the file has the BOM marker it is considered UTF-8 implicitly [BOM]. If any encoding is specified it must be UTF-8, else it is an error [BOM and utf-8][BOM conflict]. üÉz {0} = '{1}' _tempc Cst|jj}t||jd}||Wdn1s>0Y|j|j||j}||WdS1s|0YdS)Nwb)rcreate_modules module_nameopenwrite machinerySourceFileLoaderload)selfsourcemappingfileloaderrc/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_importlib/source/test_source_encoding.pyrun_test%s( zEncodingTest.run_testcCs@d|}t|sJ|dg}||j|d|S)Nz # coding={0}utf-8 )format CODING_REmatchencodeappend source_linejoin)rencoding encoding_line source_linesrrr create_source-s   zEncodingTest.create_sourcecCs0d}t|sJd|d}||dS)Nz# coding=koi8-rz {0} a=42 zkoi8-r)rrrrr)rr"rrrrtest_non_obvious_encoding4sz&EncodingTest.test_non_obvious_encodingcCs||jddSNr)rrrrrrrtest_default_encoding=sz"EncodingTest.test_default_encodingcCsd}||}||dS)NLatin-1r$r)rr!rrrrtest_encoding_on_first_lineAs z(EncodingTest.test_encoding_on_first_linecCsd|d}||dS)Ns#/usr/bin/python r)r*rrrrrtest_encoding_on_second_lineGsz)EncodingTest.test_encoding_on_second_linecCs|tj|jddSr&)rcodecsBOM_UTF8rrr'rrrtest_bomLszEncodingTest.test_bomcCstj|d}||dSr&)r.r/r$rr,rrrtest_bom_and_utf_8PszEncodingTest.test_bom_and_utf_8cCsHtj|d}|t||Wdn1s:0YdS)Nzlatin-1)r.r/r$Z assertRaises SyntaxErrorrr,rrrtest_bom_conflictUs zEncodingTest.test_bom_conflictN)__name__ __module__ __qualname____doc__variable characterrrr rr$r%r(r+r-r0r1r3rrrrrs   rc@seZdZddZdS)EncodingTestPEP451cCs,t|j}tj|j||_|||SN)types ModuleTyper importlibrspec_from_loader__spec__ exec_module)rrmodulerrrr]s  zEncodingTestPEP451.loadNr4r5r6rrrrrr:[sr:)r c@seZdZddZdS)EncodingTestPEP302cCsDt(tdt||jWdS1s60YdSNignore)warningscatch_warnings simplefilterDeprecationWarning load_moduler )rrrrrrks  zEncodingTestPEP302.loadNrCrrrrrDisrDc@s0eZdZdZddZddZddZdd Zd S) LineEndingTestzjSource written with the three types of line endings (\n, \r\n, \r) need to be readable [cr][crlf][lf].c Csd}gd}||}t|f}t||d}||Wdn1sP0Y|j|||}|||WdS1s0YdS)Nr)sa = 42sb = -13r)r rr r r r rr)rZ line_endingr r#rrrrrrrr{s  (zLineEndingTest.run_testcCs|ddS)N rr'rrrtest_crszLineEndingTest.test_crcCs|ddS)Ns rOr'rrr test_crlfszLineEndingTest.test_crlfcCs|ddS)NrrOr'rrrtest_lfszLineEndingTest.test_lfN)r4r5r6r7rrPrQrRrrrrrLvs  rLc@seZdZddZdS)LineEndingTestPEP451cCs(t|}tj|||_|||Sr;)r<r=r>rr?r@rA)rrr rBrrrrs  zLineEndingTestPEP451.loadNrCrrrrrSsrSc@seZdZddZdS)LineEndingTestPEP302cCsBt&tdt||WdS1s40YdSrE)rGrHrIrJrK)rrr rrrrs  zLineEndingTestPEP302.loadNrCrrrrrTsrT__main__) rZimport_importlibr r.importlib.utilr>rer< unicodedataZunittestrGcompileASCIIrrr:Z test_bothZFrozen_EncodingTestPEP451ZSource_EncodingTestPEP451rDZFrozen_EncodingTestPEP302ZSource_EncodingTestPEP302rLrSZFrozen_LineEndingTestPEP451ZSource_LineEndingTestPEP451rTZFrozen_LineEndingTestPEP302ZSource_LineEndingTestPEP302r4mainrrrrs:  H