HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/test/__pycache__/test_c_locale_coercion.cpython-38.opt-1.pyc
U

.D�gHK�@s�ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddgZdZ
dZdZd	d
dgZej�d�r�e	jr�d
Z
d
Zq�e�d�n4ej�d�r�dZ
dZnejdkr�d
Znejdkr�dZdZeejdko�eed�o�eed��Zdd�ZdZede�ZGdd�de�ZdZdZdada da!dd �Z"Gd!d"�d"ej#�Z$Gd#d$�d$e$�Z%e	j&e�'e�(d%�d&�Gd'd(�d(e$���Z)d)d*�Z*e+d+k�r�e*�dS),�N)�
namedtuple)�support)�run_python_until_end�Cz
invalid.ascii�asciiT�C.UTF-8�C.utf8�UTF-8�linux�utf-8ZPOSIXZaixz	iso8859-1�darwin�cygwinF)rrr	)rr
�nl_langinfo�CODESETcCs6d}tr|d7}|�|�}td|dd�\}}|jdkS)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)Zlocale_nameZcmd_fmt�cmd�result�py_cmd�r�:/opt/cppython/lib/python3.8/test/test_c_locale_coercion.py�_set_locale_in_subprocessSs
rzBfsencoding stdin_info stdout_info stderr_info lang lc_ctype lc_all�EncodingDetailsc
@s>eZdZd�dddddddd	g�Zed
d��Zedd
��ZdS)r�;zimport 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'))cCsx|d}d|�d�g}|�|�d��|�dd�}|r>t}n|�dd�}|�dd�}	|||	f}
t||f||
�����S)	z;Returns expected child process details for a given encodingz:{}��surrogateescape�backslashreplace�LANGznot set�LC_CTYPE�LC_ALL)r�append�get�CLI_COERCION_TARGET�dict�_asdict)�cls�coercion_expected�fs_encoding�stream_encoding�env_vars�_streamZstream_infoZ
expected_langZexpected_lc_ctypeZexpected_lc_allZenv_inforrr�get_expected_detailsns
z$EncodingDetails.get_expected_detailscCshtddd|jf|�\}}|jdks,|�|�|j�d���}t||����}|j	�d��
���}||fS)ajRetrieves 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-Xzutf8=0rrr)r�CHILD_PROCESS_SCRIPTrZfail�out�decode�
splitlinesr(r)�err�rstrip)r*r.rrZstdout_linesZchild_encoding_details�stderr_linesrrr�get_child_details�s��

z!EncodingDetails.get_child_detailsN)�__name__�
__module__�__qualname__�joinr1�classmethodr0r8rrrrras�
z�Python 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.z�Python detected LC_CTYPE=C: LC_CTYPE coerced to {} (set another locale or PYTHONCOERCECLOCALE=0 to disable this locale coercion behavior).cCs�tdk	rdSgatD]}t|�rt�|�qtrBtdat�t�atj	r�t
dt���t
dt���t
dt���t
dt
���t
dt���t
dt���t
dt���dS)	NrzAVAILABLE_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_LOCALESrr%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)Z
target_localerrr�setUpModule�s"
rHc@seZdZdd�ZdS)�_LocaleHandlingTestCasec
CsJt�|�}|\}}t�||||�}	|�||	�|dkr:g}|�||�dS)a5Check 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)rr8r0�assertEqual)
�selfr.�expected_fs_encoding�expected_stream_encoding�expected_warningsr+rZencoding_detailsr7Zexpected_detailsrrr�_check_child_encoding_details�s
�z5_LocaleHandlingTestCase._check_child_encoding_detailsN)r9r:r;rOrrrrrI�srIc@s eZdZedd��Zdd�ZdS)�LocaleConfigurationTestscCstst�d��dS)Nz No C-with-UTF-8 locale available)r>�unittestZSkipTest)r*rrr�
setUpClass�sz#LocaleConfigurationTests.setUpClasscCs�d|_d}d}ddddd�}dD]^}tD]T}|dkr>|dkr>q(|j||d��*|��}|||<|j|||ddd	�W5QRXq(q dS)
Nrr�r"r#r$r�r"r#r"r	)�env_varZconfigured_localeF)rNr+)�maxDiffr>�subTest�copyrO)rKrLrM�
base_var_dictrU�
locale_to_set�var_dictrrr�)test_external_target_locale_configuration�s.���zBLocaleConfigurationTests.test_external_target_locale_configurationN)r9r:r;r=rRr\rrrrrP�s
rPZPY_COERCE_C_LOCALEz(C locale coercion disabled at build timec@sFeZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)�LocaleCoercionTestsNTc
Ks�d|_ts t}t}d}|r tg}ddddd�}|�|�|dk	rH||d<|jd|d��Btrf|}|}	nd}d}	tj	r�|t
gkr�d}|�|||||	�W5QRXtD]L}
dD]B}|j||
|d	��(|�
�}|
||<|�|||||�W5QRXq�q�dS)
aCheck 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
        NFrrSrT)Zdefault_localerrT)rUZnominal_localer)rVr>rFrE�LEGACY_LOCALE_WARNING�updaterWrGr�
is_androidrArOrDrX)
rKr,r-�coerce_c_localerNr+Z
extra_varsrYZ_expected_warningsZ_coercion_expectedrZrUr[rrr�_check_c_locale_coercions^�
�����z,LocaleCoercionTests._check_c_locale_coercioncCs|jdddd�dS)Nr�ra�rb�rKrrr� test_PYTHONCOERCECLOCALE_not_setesz4LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_setcCsdD]}|jdd|d�qdS)N)r�1�trueZfalserrcrd)rKZsettingrrr�!test_PYTHONCOERCECLOCALE_not_zeroisz5LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_zerocCs|jdddtgd�dS)Nr�warn)rarN)rbrArerrr�$test_PYTHONCOERCECLOCALE_set_to_warnos�z8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_warncCs*|jttddd�|jttdddd�dS)N�0F)rar+r�rar$r+)rbrFrErerrr�$test_PYTHONCOERCECLOCALE_set_to_zerovs��z8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_zerocCs0|jttdddd�|jttddtgdd�dS)NrFrmrj)rar$rNr+)rbrFrEr^rerrr�test_LC_ALL_set_to_C�s��z(LocaleCoercionTests.test_LC_ALL_set_to_Cc
Cs�t�tjd�}|�tjtj|�zt�tjd�}Wn2tjk
rd}z|�t|��W5d}~XYnX|dkrx|�d�|tkr�|�d|�d}tt	j
dd�}tjt
jd|gtj|d	d
�}|�|j��|�dS)Nrrz.test requires LC_CTYPE locale different than Czcoerced LC_CTYPE locale: %sz=import locale; print(locale.setlocale(locale.LC_CTYPE, None))rgrrT)�stdout�env�text)�locale�	setlocaler#Z
addCleanup�ErrorZskipTest�str�TARGET_LOCALESr(�os�environ�
subprocess�run�sys�
executable�PIPErJrpr6)rKZold_loc�loc�e�coderqrrrr�#test_PYTHONCOERCECLOCALE_set_to_one�s$ 
�z7LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_one)NT)
r9r:r;rbrfrirkrnror�rrrrr]s	�
J
r]cCst�tt�t��dS)N)rZrun_unittestrPr]�
reap_childrenrrrr�	test_main�s
�r��__main__),rsrxrzr|Z	sysconfigrQ�collectionsr�testrZtest.support.script_helperrrDrErFrGrw�platform�
startswithr`r%r?�bool�hasattrrr�_fieldsZ_EncodingDetailsrr^r@r>r'rArHZTestCaserIrPZcpython_onlyZ
skipUnlessZget_config_varr]r�r9rrrr�<module>sn



��
:�	�-�