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_testcCs2d|}|dg}||j|d|S)Nz # coding={0}utf-8 )formatencodeappend source_linejoin)rencoding encoding_line source_linesrrr create_source-s  zEncodingTest.create_sourcecCs"d}d|d}||dS)Nz# coding=koi8-rz {0} a=42 zkoi8-r)rrr)rr rrrrtest_non_obvious_encoding4sz&EncodingTest.test_non_obvious_encodingcCs||jddSNr)rrrrrrrtest_default_encoding=sz"EncodingTest.test_default_encodingcCsd}||}||dS)NLatin-1r"r)rrrrrrtest_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+r.r/r1rrrrrs   rc@seZdZddZdS)EncodingTestPEP451cCs,t|j}tj|j||_|||SN)types ModuleTyper importlibrspec_from_loader__spec__ exec_module)rrmodulerrrr]s  zEncodingTestPEP451.loadNr2r3r4rrrrrr8[sr8)r c@seZdZddZdS)EncodingTestPEP302cCsDt(tdt||jWdS1s60YdSNignore)warningscatch_warnings simplefilterDeprecationWarning load_moduler )rrrrrrks  zEncodingTestPEP302.loadNrArrrrrBisrBc@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)rrr r r r rr)rZ line_endingr r!rrrrrrrr{s  (zLineEndingTest.run_testcCs|ddS)N rr%rrrtest_crszLineEndingTest.test_crcCs|ddS)Ns rMr%rrr test_crlfszLineEndingTest.test_crlfcCs|ddS)NrrMr%rrrtest_lfszLineEndingTest.test_lfN)r2r3r4r5rrNrOrPrrrrrJvs  rJc@seZdZddZdS)LineEndingTestPEP451cCs(t|}tj|||_|||Sr9)r:r;r<rr=r>r?)rrr r@rrrrs  zLineEndingTestPEP451.loadNrArrrrrQsrQc@seZdZddZdS)LineEndingTestPEP302cCsBt&tdt||WdS1s40YdSrC)rErFrGrHrI)rrr rrrrs  zLineEndingTestPEP302.loadNrArrrrrRsrR__main__) rZimport_importlibr r,importlib.utilr<rer: unicodedataZunittestrEcompileASCIIZ CODING_RErr8Z test_bothZFrozen_EncodingTestPEP451ZSource_EncodingTestPEP451rBZFrozen_EncodingTestPEP302ZSource_EncodingTestPEP302rJrQZFrozen_LineEndingTestPEP451ZSource_LineEndingTestPEP451rRZFrozen_LineEndingTestPEP302ZSource_LineEndingTestPEP302r2mainrrrrs:  H