
    dafS                     6   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"                  j%                  d
      r#e	j&                  rdZdZniej)                  d       nWej"                  j%                  d      rdZdZn7e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xr  ee d      xr	  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jF                        Z$ G d d e$      Z%e	jL                   ejN                   ejP                  d!      d"       G d# d$e$                    Z)d% Z*e+d&k(  r ejX                          yy)'    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  }|j                  |       }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        6/root/Python-3.12.4/Lib/test/test_c_locale_coercion.py_set_locale_in_subprocessr    W   sC    MG!SS
..
%C)$LNFF99>    zBfsencoding stdin_info stdout_info stderr_info lang lc_ctype lc_allEncodingDetailsc                   R    e Zd Zdj                  g d      Zed        Zed        Zy)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                 J   |dz   }|d}|j                  |      gdz  }|j                  |j                  d             |j                  dd      }|rt        }	n|j                  dd      }	|j                  dd      }
||	|
f}t	         | |g|| j                               S )	z;Returns expected child process details for a given encodingz:{}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59 	7>>*<=> VY7 3 (Z C",,x; "3_DC=k=H=EEGHHr!   c                 z   t        ddd| j                  fi |\  }}|j                  dk(  s|j                  |       |j                  j                  d      j                         }t         | | j                               }|j                  j                  d      j                         j                         }||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#":":

 yyA~KKzz((1<<>!%c<&8&@&@&B!Czz((188:EEG%|33r!   N)__name__
__module____qualname__joinr?   classmethodr=   rI    r!   r   r"   r"   e   s@    88 	% 	 I I* 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                     t         y g a t        D ]#  } t        |       st         j                  |        % t         r"t         d   at
        j                  t              at        j                  rt        dt                t        dt               t        dt               t        dt               t        dt               t        dt               t        dt               y y )	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\      s    
 $ ) 4$]3$$]34 /27>>?RS$%6$9:;01N0QRS45V4YZ[01N0QRS45V4YZ["?"567-.H-KLM r!   c                       e Zd Zd Zy)_LocaleHandlingTestCasec                     t         j                  |      }|\  }}	t         j                  |||||      }
| j                  ||
       |g }| j                  |	|       y)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   sp     !228<)/&,*?? $"
 	)+;<$ "'89r!   N)rJ   rK   rL   rh   rO   r!   r   r^   r^      s    :r!   r^   c                   (    e Zd Zed        Zd Zd Zy)LocaleConfigurationTestsc                 :    t         st        j                  d      y )Nz No C-with-UTF-8 locale available)rQ   unittestSkipTest)r1   s    r   
setUpClassz#LocaleConfigurationTests.setUpClass   s     !##$FGG !r!   c                    d | _         d}d}dddddd}dD ]`  }t        D ]U  }|dk(  r|dk(  r| j                  ||      5  |j                         }|||<   | j	                  |||d d d	       d d d        W b y # 1 sw Y   dxY w)
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   s     &#*  #% "
 , 	PG!2 P f$')A\\'4A " C 	P,113H(5HW%66x7K7ONRIMIN 7 P		P 	PP	P	P 	P    -A::Bc                    d | _         d}d}dddddd}dD ]`  }t        D ]U  }|dk(  r|dk(  r| j                  ||      5  |j                         }|||<   | j	                  |||dd d	
       d d d        W b y # 1 sw Y   dxY w)Nr
   r   r   rp   rr   r)   rs   strictFrv   rw   r{   s          r   test_with_ioencodingz-LocaleConfigurationTests.test_with_ioencoding  s     &#*  #% '
 , 	PG!2 P f$')A\\'4A " C 	P,113H(5HW%66x7K7ONVIMIN 7 P		P 	PP	P	P 	Pr   N)rJ   rK   rL   rN   rn   r   r   rO   r!   r   rj   rj      s%     H H!PF 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	y)
LocaleCoercionTestsNc                 ,   d| _         t        st        }t        }d}|rt        g}dddddd}|j                  |       |||d<   | j                  d|      5  t        r|}|}	nd}d}	t        j                  r|t        gk(  rd}| j                  |||d||	       ddd       t        D ]R  }
dD ]K  }| j                  ||
|d	      5  |j                         }|
||<   | j                  |||d||       ddd       M T y# 1 sw Y   exY w# 1 sw Y   fxY w)
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  s   "  7K?O % %:$;! #% "
 	Z(&3BM/0 \\.=  ? 	C0%6"%6"%)"%*"
 ""&+?*@@%)"..}/:/>/3/A/AC	C. ; 	JM/ J\\'1>6E35 " 7 J  -113H(5HW%66x7B7F7;7H7HJJ JJ	J/	C 	C2J Js   AC>,D
>D
Dc                 ,    | j                  ddd        y )Nr
   r   r   ra   s    r    test_PYTHONCOERCECLOCALE_not_setz4LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_set  s    %%gw%Mr!   c                 :    dD ]  }| j                  dd|        y )N)r   1truefalser
   r   r   )ra   settings     r   !test_PYTHONCOERCECLOCALE_not_zeroz5LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_zero  s*     2 	UG))'7G)T	Ur!   c                 8    | j                  dddt        g       y )Nr
   warn)r   re   )r   rT   r   s    r   $test_PYTHONCOERCECLOCALE_set_to_warnz8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_warn  s#    %%gw6<9M8N 	& 	Pr!   c                 z    | j                  t        t        dd       | j                  t        t        ddd       y )N0F)r   r2   r   r   r+   r2   )r   rY   rX   r   s    r   $test_PYTHONCOERCECLOCALE_set_to_zeroz8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_zero  sE    %%&C&G698= 	& 	?
 	%%&C&G69-08=	 	& 	?r!   c                     | j                  t        t        d dd       | j                  t        t        ddt        gd       y )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  sN    %%&C&G6:-08=	 	& 	? 	%%&C&G6<-09N8O8= 	& 	?r!   c                    t        j                  t         j                  d       }| j                  t         j                  t         j                  |       	 t        j                  t         j                  d      }dk(  r| j                  d       |t        v r| j                  d|z         d}t        t        j                  d      }t        j                  t        j                  d|gt        j                  |d	
      }| j!                  |j"                  j%                         |       y # t         j                  $ r$}| j                  t        |             Y d }~d }~ww xY w)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  s   ""6??D9((&//7C	"""6??B7C #:MMJK. MM7#=> O2::37nncnndD9$.OO!$"&( 	**,c2 || 	"MM#a&!!	"s   $D+ +E">EE")NT)
rJ   rK   rL   r   r   r   r   r   r   r   rO   r!   r   r   r   A  s3     4837	LJ\NUP??3r!   r   c                  ,    t        j                          y )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      s    	  
   "  ; "%o 6  %, ! '  %) !/ <<7#,3)(/% 	&,,W5\\U#(3%$/!\\X$+!\\X ).%\\Y(/%$+! 1 "LL++ FM"FI  O/9 94& 94| J     N<:h// :@MP6 MP^ 	-Y--.BC?AS31 S3A S3l zHMMO r!   