
    5\hS                     (   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mZ d dlm	Z	 d dl
mZ ddgZdZdZdZg d	Zej                            d
          r"e	j        rdZdZn`e                    d           nJej                            d          rdZdZn+ej        dk    rdZnej        dk    rdZnej        dk    rdZdZd	Z eej        dvo ee d          o ee d                    Zd ZdZ ede          Z G d de          ZdZdZdada da!d Z" G d dej#                  Z$ G d d e$          Z%e	j&         ej'         ej(        d!          d"           G d# d$e$                                  Z)d% Z*e+d&k    r ej,                     dS dS )'    N)
namedtuple)support)run_python_until_endCzinvalid.asciiasciiT)zC.UTF-8zC.utf8UTF-8linuxutf-8POSIXaixz	iso8859-1darwincygwinFvxworks)r   r	   nl_langinfoCODESETc                     d}t           r|dz  }|                    |           }t          d|d          \  }}|j        dk    S )Nz=import locale; print(locale.setlocale(locale.LC_CTYPE, '{}'))z>; import sys; sys.exit(not locale.nl_langinfo(locale.CODESET))-c PYTHONCOERCECLOCALEr   )_check_nl_langinfo_CODESETformatr   rc)locale_namecmd_fmtcmdresultpy_cmds        E/opt/python-3.11.14/usr/lib/python3.11/test/test_c_locale_coercion.py_set_locale_in_subprocessr    W   sP    MG! TSS
..
%
%C)$LLLNFF9>    zBfsencoding stdin_info stdout_info stderr_info lang lc_ctype lc_allEncodingDetailsc                   h    e Zd Zd                    g d          Zed             Zed             ZdS )r"   ;)zimport sys, osz"print(sys.getfilesystemencoding())z2print(sys.stdin.encoding + ':' + sys.stdin.errors)z4print(sys.stdout.encoding + ':' + sys.stdout.errors)z4print(sys.stderr.encoding + ':' + sys.stderr.errors)z(print(os.environ.get('LANG', 'not set'))z,print(os.environ.get('LC_CTYPE', 'not set'))z*print(os.environ.get('LC_ALL', 'not set'))c                    |dz   }|d}|                     |          gdz  }|                    |                     d                     |                    dd          }|rt          }	n|                    dd          }	|                    d	d          }
||	|
f}t	           | |g||R                                            S )
z;Returns expected child process details for a given encodingz:{}Nsurrogateescape   backslashreplaceLANGznot setLC_CTYPELC_ALL)r   appendgetCLI_COERCION_TARGETdict_asdict)clscoercion_expectedfs_encodingstream_encodingstream_errorsenv_vars_streamstream_infoexpected_langexpected_lc_ctypeexpected_lc_allenv_infos               r   get_expected_detailsz$EncodingDetails.get_expected_detailsr   s     "E)  .M~~m4459 	7>>*<==>>> VY77 	D 3 (Z C C",,x;; "3_DCC=k=H===EEGGHHHr!   c                    t          ddd| j        fi |\  }}|j        dk    s|                    |           |j                            d                                          }t           | |                                           }|j	                            d          
                                                                }||fS )aj  Retrieves fsencoding and standard stream details from a child process

        Returns (encoding_details, stderr_lines):

        - encoding_details: EncodingDetails for eager decoding
        - stderr_lines: result of calling splitlines() on the stderr output

        The child is run in isolated mode if the current interpreter supports
        that.
        z-Xzutf8=0r   r   r   )r   CHILD_PROCESS_SCRIPTr   failoutdecode
splitlinesr/   r0   errrstrip)r1   r6   r   r   stdout_lineschild_encoding_detailsstderr_liness          r   get_child_detailsz!EncodingDetails.get_child_details   s     .(D#":
 

 
 yA~~KKz((11<<>>!%cc<&8&@&@&B&B!C!Cz((1188::EEGG%|33r!   N)__name__
__module____qualname__joinr?   classmethodr=   rI    r!   r   r"   r"   e   sp        88 	% 	% 	% 	 	 I I [I* 4 4 [4 4 4r!   zPython runtime initialized with LC_CTYPE=C (a locale with default ASCII encoding), which may cause Unicode compatibility problems. Using C.UTF-8, C.utf8, or UTF-8 (if available) as alternative Unicode-compatible locales is recommended.zPython detected LC_CTYPE=C: LC_CTYPE coerced to {} (set another locale or PYTHONCOERCECLOCALE=0 to disable this locale coercion behavior).c                  F   t           d S g a t          D ]+} t          |           rt                               |            ,t           r,t           d         at
                              t                    at          j	        rt          dt                      t          dt                     t          dt                     t          dt                     t          dt                     t          dt                     t          dt                     d S d S )	Nr   zAVAILABLE_TARGETS = z EXPECTED_C_LOCALE_EQUIVALENTS = z$EXPECTED_C_LOCALE_STREAM_ENCODING = z EXPECTED_C_LOCALE_FS_ENCODING = z$EXPECT_COERCION_IN_DEFAULT_LOCALE = z_C_UTF8_LOCALES = z_check_nl_langinfo_CODESET = )AVAILABLE_TARGETS_C_UTF8_LOCALESr    r,   r.   CLI_COERCION_WARNING_FMTr   CLI_COERCION_WARNINGr   verboseprintEXPECTED_C_LOCALE_EQUIVALENTS!EXPECTED_C_LOCALE_STREAM_ENCODINGEXPECTED_C_LOCALE_FS_ENCODING!EXPECT_COERCION_IN_DEFAULT_LOCALEr   )target_locales    r   setUpModuler\      s8   
 $ ) 4 4$]33 	4$$]333 T/27>>?RSS N:%6::;;;R1NRRSSSZ5VZZ[[[R1NRRSSSZ5VZZ[[[6?66777L.HLLMMMMMN Nr!   c                       e Zd Zd ZdS )_LocaleHandlingTestCasec                     t                               |          }|\  }}	t                               |||||          }
|                     ||
           |g }|                     |	|           dS )a5  Check the C locale handling for the given process environment

        Parameters:
            expected_fs_encoding: expected sys.getfilesystemencoding() result
            expected_stream_encoding: expected encoding for standard streams
            expected_warning: stderr output to expect (if any)
        N)r"   rI   r=   assertEqual)selfr6   expected_fs_encodingexpected_stream_encodingexpected_stream_errorsexpected_warningsr2   r   encoding_detailsrH   expected_detailss              r   _check_child_encoding_detailsz5_LocaleHandlingTestCase._check_child_encoding_details   s     !228<<)/&,*?? $"
 
 	)+;<<<$ "'899999r!   N)rJ   rK   rL   rh   rO   r!   r   r^   r^      s#        : : : : :r!   r^   c                   0    e Zd Zed             Zd Zd ZdS )LocaleConfigurationTestsc                 <    t           st          j        d          d S )Nz No C-with-UTF-8 locale available)rQ   unittestSkipTest)r1   s    r   
setUpClassz#LocaleConfigurationTests.setUpClass   s+     ! 	H#$FGGG	H 	Hr!   c                 *   d | _         d}d}dddddd}dD ]|}t          D ]r}|dk    r|dk    r|                     ||          5  |                                }|||<   |                     |||d d d	           d d d            n# 1 swxY w Y   s}d S )
Nr
   r   r)   r*   r+   r   PYTHONIOENCODINGr)   r*   r)   r   env_varconfigured_localeFrd   re   r2   maxDiffrQ   subTestcopyrh   ra   rb   rc   base_var_dictrt   locale_to_setvar_dicts          r   )test_external_target_locale_configurationzBLocaleConfigurationTests.test_external_target_locale_configuration   sW    &#*  #% "
 
 , 	P 	PG!2 P P f$$')A)A\\'4A " C C 	P 	P,1133H(5HW%66x7K7ONRIMIN 7 P P P		P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	PP	P 	P   5BB
B
c                 *   d | _         d}d}dddddd}dD ]|}t          D ]r}|dk    r|dk    r|                     ||          5  |                                }|||<   |                     |||dd d	
           d d d            n# 1 swxY w Y   s}d S )Nr
   r   r   rp   rr   r)   rs   strictFrv   rw   r{   s          r   test_with_ioencodingz-LocaleConfigurationTests.test_with_ioencoding  sW    &#*  #% '
 
 , 	P 	PG!2 P P f$$')A)A\\'4A " C C 	P 	P,1133H(5HW%66x7K7ONVIMIN 7 P P P		P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	PP	P 	Pr   N)rJ   rK   rL   rN   rn   r   r   rO   r!   r   rj   rj      sY         H H [H!P !P !PF P  P  P  P  Pr!   rj   PY_COERCE_C_LOCALEz(C locale coercion disabled at build timec                   >    e Zd Z	 	 d
dZd Zd Zd Zd Zd Zd	 Z	dS )LocaleCoercionTestsNTc                 j   d| _         t          st          }t          }d}|rt          g}dddddd}|                    |           |||d<   |                     d|          5  t          r|}|}	nd}d}	t          j	        r|t          gk    rd}|                     |||d||	           ddd           n# 1 swxY w Y   t          D ]k}
dD ]f}|                     ||
|d	          5  |                                }|
||<   |                     |||d||           ddd           n# 1 swxY w Y   gldS )
a  Check the C locale handling for various configurations

        Parameters:
            fs_encoding: expected sys.getfilesystemencoding() result
            stream_encoding: expected encoding for standard streams
            coerce_c_locale: setting to use for PYTHONCOERCECLOCALE
              None: don't set the variable at all
              str: the value set in the child's environment
            expected_warnings: expected warning lines on stderr
            extra_vars: additional environment variables to set in subprocess
        NFr   rp   r   T)default_localer   rr   )rt   nominal_localer   rq   )rx   rQ   rY   rX   LEGACY_LOCALE_WARNINGupdatery   rZ   r   
is_androidrT   rh   rW   rz   )ra   r3   r4   coerce_c_localere   r2   
extra_varsr|   _expected_warnings_coercion_expectedr}   rt   r~   s                r   _check_c_locale_coercionz,LocaleCoercionTests._check_c_locale_coercionG  sy   "   	<7K?O %  <%:$;! #% "
 
 	Z(((&3BM/0 \\.=  ? ? 	C 	C0 +%6"%6""%)"%*"
 " *&+?*@@@%)"..}/:/>/3/A/AC C C	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C. ; 	J 	JM/ J J\\'1>6E35 " 7 7 J J  -1133H(5HW%66x7B7F7;7H7HJ J JJ J J J J J J J J J J J J J JJ	J 	Js%   $AB55B9<B9&4D&&D*-D*c                 6    |                      ddd            d S )Nr
   r   r   ra   s    r    test_PYTHONCOERCECLOCALE_not_setz4LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_set  s#    %%gw%MMMMMr!   c                 @    dD ]}|                      dd|           d S )N)r   1truefalser
   r   r   )ra   settings     r   !test_PYTHONCOERCECLOCALE_not_zeroz5LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_zero  s?     2 	U 	UG))'7G)TTTT	U 	Ur!   c                 D    |                      dddt          g           d S )Nr
   warn)r   re   )r   rT   r   s    r   $test_PYTHONCOERCECLOCALE_set_to_warnz8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_warn  s;    %%gw6<9M8N 	& 	P 	P 	P 	P 	Pr!   c                     |                      t          t          dd           |                      t          t          ddd           d S )N0F)r   r2   r   r   r+   r2   )r   rY   rX   r   s    r   $test_PYTHONCOERCECLOCALE_set_to_zeroz8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_zero  sc    %%&C&G698= 	& 	? 	? 	?
 	%%&C&G69-08=	 	& 	? 	? 	? 	? 	?r!   c                     |                      t          t          d dd           |                      t          t          ddt          gd           d S )Nr   Fr   r   )r   r+   re   r2   )r   rY   rX   r   r   s    r   test_LC_ALL_set_to_Cz(LocaleCoercionTests.test_LC_ALL_set_to_C  sl    %%&C&G6:-08=	 	& 	? 	? 	? 	%%&C&G6<-09N8O8= 	& 	? 	? 	? 	? 	?r!   c                    t          j        t           j        d           }|                     t           j        t           j        |           	 t          j        t           j        d          }n># t           j        $ r,}|                     t          |                     Y d }~nd }~ww xY w|dk    r|                     d           |t          v r|                     d|z             d}t          t          j
        d          }t          j        t          j        d|gt          j        |d	
          }|                     |j                                        |           d S )Nr   r   z.test requires LC_CTYPE locale different than Czcoerced LC_CTYPE locale: %sz=import locale; print(locale.setlocale(locale.LC_CTYPE, None))r   r   r   T)stdoutenvtext)locale	setlocaler*   
addCleanupErrorskipTeststrTARGET_LOCALESr/   osenviron
subprocessrunsys
executablePIPEr`   r   rE   )ra   old_loclocecoder   r   s          r   #test_PYTHONCOERCECLOCALE_set_to_onez7LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_one  sG   "6?D99(&/7CCC	""6?B77CC| 	" 	" 	"MM#a&&!!!!!!!!	"#::MMJKKK.  MM7#=>>> O2:3777ncndD9$.O!$"&( ( ( 	**,,c22222s   A, ,B';"B""B')NT)
rJ   rK   rL   r   r   r   r   r   r   r   rO   r!   r   r   r   A  s         4837	LJ LJ LJ LJ\N N NU U UP P P? ? ?? ? ?3 3 3 3 3r!   r   c                  ,    t          j                     d S )N)r   reap_childrenrO   r!   r   tearDownModuler     s    r!   __main__)-r   r   r   r   	sysconfigrl   collectionsr   testr   test.support.script_helperr   rW   rX   rY   rZ   r   platform
startswithr   r,   rR   boolhasattrr   r    _fields_EncodingDetailsr"   r   rS   rQ   r.   rT   r\   TestCaser^   rj   cpython_only
skipUnlessget_config_varr   r   rJ   mainrO   r!   r   <module>r      sX    				     



      " " " " " "       ; ; ; ; ; ; "%o 6  %, ! '  %) !/// <7## , 	6,3)(/%% 	&,,W5555\U## ,(3%$/!!\X$+!!\X ).%%\Y(/%$+! 1 "TL++ GFM""GFI     O:/99 94 94 94 94 94& 94 94 94| J     N N N<: : : : :h/ : : :@MP MP MP MP MP6 MP MP MP^ 	-Y-.BCC?A AS3 S3 S3 S3 S31 S3 S3A A S3l   zHMOOOOO r!   