
    daf                        d dl mZ  ej                  d      Zd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZ ej                  dej                        Z G d d      Z G d de      Z ej"                  ee	      \  ZZ G d
 de      Z ej"                  ee	      \  ZZ G d d      Z G d de      Z ej"                  ee	      \  ZZ G d de      Z ej"                  ee	      \  ZZedk(  r e
j>                          yy)    )utilzimportlib.machineryNz&^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)c                   v    e Zd ZdZdZdZdj                  ee      ZdZd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zy)EncodingTesta  PEP 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                 r   t        j                  | j                        5 }t        || j                     d      5 }|j	                  |       d d d        | j
                  j                  | j                  || j                           }| j                  |      cd d d        S # 1 sw Y   VxY w# 1 sw Y   y xY w)Nwb)r   create_modulesmodule_nameopenwrite	machinerySourceFileLoaderload)selfsourcemappingfileloaders        J/root/Python-3.12.4/Lib/test/test_importlib/source/test_source_encoding.pyrun_testzEncodingTest.run_test%   s      !1!12 	%ggd../6 #$

6"#^^44T5E5E29$:J:J2KMF99V$	% 	%# #	% 	%s#   B-B!AB-!B*	&B--B6c                     dj                  |      }t        j                  |      sJ |j                  d      g}|j	                  | j
                  j                  |             dj                  |      S )Nz# coding={0}utf-8   
)format	CODING_REmatchencodeappendsource_linejoin)r   encodingencoding_linesource_liness       r   create_sourcezEncodingTest.create_source-   se    &--h7}---%,,W56D,,33H=>zz,''    c                     d}t         j                  |      sJ dj                  |      j                  d      }| j	                  |       y )Nz# coding=koi8-rz	{0}
a=42
zkoi8-r)r   r   r   r   r   )r   r$   r   s      r   test_non_obvious_encodingz&EncodingTest.test_non_obvious_encoding4   sB     *}---%%m4;;HEfr'   c                 X    | j                  | j                  j                  d             y Nr   )r   r!   r   r   s    r   test_default_encodingz"EncodingTest.test_default_encoding=   s    d&&--g67r'   c                 L    d}| j                  |      }| j                  |       y )NLatin-1r&   r   )r   r#   r   s      r   test_encoding_on_first_linez(EncodingTest.test_encoding_on_first_lineA   s#    ##H-fr'   c                 N    d| j                  d      z   }| j                  |       y )Ns   #/usr/bin/python
r/   r0   r   r   s     r   test_encoding_on_second_linez)EncodingTest.test_encoding_on_second_lineG   s#    &););I)FFfr'   c                 z    | j                  t        j                  | j                  j	                  d      z          y r+   )r   codecsBOM_UTF8r!   r   r,   s    r   test_bomzEncodingTest.test_bomL   s(    foo(8(8(?(?(HHIr'   c                 j    t         j                  | j                  d      z   }| j                  |       y r+   )r6   r7   r&   r   r3   s     r   test_bom_and_utf_8zEncodingTest.test_bom_and_utf_8P   s'    4#5#5g#>>fr'   c                     t         j                  | j                  d      z   }| j                  t              5  | j                  |       d d d        y # 1 sw Y   y xY w)Nzlatin-1)r6   r7   r&   assertRaisesSyntaxErrorr   r3   s     r   test_bom_conflictzEncodingTest.test_bom_conflictU   sJ    4#5#5i#@@{+ 	"MM&!	" 	" 	"s   AAN)__name__
__module____qualname____doc__variable	characterr   r!   r   r   r&   r)   r-   r1   r4   r8   r:   r>    r'   r   r   r      sX    	 HI!((9=KK%(8
J
"r'   r   c                       e Zd Zd Zy)EncodingTestPEP451c                     t        j                  | j                        }t        j                  j                  | j                  |      |_        |j                  |       |S N)types
ModuleTyper   	importlibr   spec_from_loader__spec__exec_module)r   r   modules      r   r   zEncodingTestPEP451.load]   sI    !!$"2"23#..99$:J:JFS6"r'   Nr?   r@   rA   r   rE   r'   r   rG   rG   [       r'   rG   )r   c                       e Zd Zd Zy)EncodingTestPEP302c                     t        j                         5  t        j                  dt               |j	                  | j
                        cd d d        S # 1 sw Y   y xY wNignore)warningscatch_warningssimplefilterDeprecationWarningload_moduler   )r   r   s     r   r   zEncodingTestPEP302.loadk   sH    $$& 	8!!(,>?%%d&6&67	8 	8 	8s   5AANrQ   rE   r'   r   rT   rT   i   s    8r'   rT   c                   (    e Zd ZdZd Zd Zd Zd Zy)LineEndingTestzjSource written with the three types of line endings (\n, \r\n, \r)
    need to be readable [cr][crlf][lf].c                 R   d}g d}|j                  |      }t        j                  |      5 }t        ||   d      5 }|j	                  |       d d d        | j
                  j                  |||         }| j                  ||      cd d d        S # 1 sw Y   CxY w# 1 sw Y   y xY w)Nr   )s   a = 42s   b = -13r'   r
   )r"   r   r   r   r   r   r   r   )r   line_endingr   r%   r   r   r   r   s           r   r   zLineEndingTest.run_test{   s    3!!,/  - 	2gk*D1 #T

6"#^^44[5<[5IKF99V[1	2 	2# #	2 	2s"   BB8BB	BB&c                 &    | j                  d       y )N   r   r,   s    r   test_crzLineEndingTest.test_cr       er'   c                 &    | j                  d       y )Ns   
rc   r,   s    r   	test_crlfzLineEndingTest.test_crlf   s    gr'   c                 &    | j                  d       y )Nr   rc   r,   s    r   test_lfzLineEndingTest.test_lf   re   r'   N)r?   r@   rA   rB   r   rd   rg   ri   rE   r'   r   r^   r^   v   s    +	2r'   r^   c                       e Zd Zd Zy)LineEndingTestPEP451c                     t        j                  |      }t        j                  j	                  ||      |_        |j                  |       |S rI   )rJ   rK   rL   r   rM   rN   rO   )r   r   r   rP   s       r   r   zLineEndingTestPEP451.load   s=    !!+.#..99+vN6"r'   NrQ   rE   r'   r   rk   rk      rR   r'   rk   c                       e Zd Zd Zy)LineEndingTestPEP302c                     t        j                         5  t        j                  dt               |j	                  |      cd d d        S # 1 sw Y   y xY wrV   )rX   rY   rZ   r[   r\   )r   r   r   s      r   r   zLineEndingTestPEP302.load   sB    $$& 	3!!(,>?%%k2	3 	3 	3s   +A

ANrQ   rE   r'   r   rn   rn      s    3r'   rn   __main__) test.test_importlibr   import_importlibr   r6   importlib.utilrL   rerJ   unicodedataunittestrX   compileASCIIr   r   rG   	test_bothFrozen_EncodingTestPEP451Source_EncodingTestPEP451rT   Frozen_EncodingTestPEP302Source_EncodingTestPEP302r^   rk   Frozen_LineEndingTestPEP451Source_LineEndingTestPEP451rn   Frozen_LineEndingTestPEP302Source_LineEndingTestPEP302r?   mainrE   r'   r   <module>r      s$   $!D!!"78	   	     BJJ@"((K	E" E"P  T^^&)<8 8 T^^&)< :>  T^^(I>3> 3 T^^(I> zHMMO r'   