HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_c_locale_coercion.cpython-37.opt-1.pyc
B

��g`I�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	Z
ddlmZm
Z
ddgZdZdZdZdd	d
gZej�d�r�e
jjr�dZdZq�e�d
�n4ej�d�r�dZdZnejdkr�dZnejdkr�dZdZeejdko�eed�o�eed��Zdd�ZdZede�ZGdd�de�ZdZ dZ!da"da#da$dd�Z%Gd d!�d!ej&�Z'Gd"d#�d#e'�Z(e
jj)e�*e�+d$�d%�Gd&d'�d'e'���Z,d(d)�Z-e.d*k�r�e-�dS)+�N)�
namedtuple)�run_python_until_end� interpreter_requires_environment�Cz
invalid.ascii�asciiTzC.UTF-8zC.utf8zUTF-8�linuxzutf-8ZPOSIXZaixz	iso8859-1�darwin�cygwinF)zC.UTF-8zC.utf8zUTF-8)rr�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))z-c�)�PYTHONCOERCECLOCALEr)�_check_nl_langinfo_CODESET�formatr�rc)Zlocale_nameZcmd_fmt�cmd�result�py_cmd�r�7/usr/local/lib/python3.7/test/test_c_locale_coercion.py�_set_locale_in_subprocessVs
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, os, codecsz6print(codecs.lookup(sys.getfilesystemencoding()).name)zFprint(codecs.lookup(sys.stdin.encoding).name + ':' + sys.stdin.errors)zHprint(codecs.lookup(sys.stdout.encoding).name + ':' + sys.stdout.errors)zHprint(codecs.lookup(sys.stderr.encoding).name + ':' + 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_detailsqs
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=0z-crr)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__�joinr+�classmethodr*r2rrrrrds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).cCsJtdk	rdSgaxtD]}t|�rt�|�qWtrFtdat�t�adS)Nr)�AVAILABLE_TARGETS�_C_UTF8_LOCALESrrr!�CLI_COERCION_WARNING_FMTr�CLI_COERCION_WARNING)Z
target_localerrr�setUpModule�s
r<c@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)rr2r*�assertEqual)
�selfr(�expected_fs_encoding�expected_stream_encoding�expected_warningsr%rZencoding_detailsr1Zexpected_detailsrrr�_check_child_encoding_details�s
z5_LocaleHandlingTestCase._check_child_encoding_detailsN)r3r4r5rCrrrrr=�sr=c@s eZdZedd��Zdd�ZdS)�LocaleConfigurationTestscCstst�d��dS)Nz No C-with-UTF-8 locale available)r8�unittestZSkipTest)r$rrr�
setUpClass�sz#LocaleConfigurationTests.setUpClasscCs�d|_d}d}ddddd�}xjdD]b}x\tD]T}|dkrB|dkrBq,|j||d��*|��}|||<|j|||ddd	�WdQRXq,Wq"WdS)
Nzutf-8r)rrrr
)rrrzUTF-8)�env_varZconfigured_localeF)rBr%)�maxDiffr8�subTest�copyrC)r?r@rA�
base_var_dictrG�
locale_to_set�var_dictrrr�)test_external_target_locale_configuration�s(


zBLocaleConfigurationTests.test_external_target_locale_configurationN)r3r4r5r7rFrNrrrrrD�srDZPY_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��Dtrf|}|}	nd}d}	tj	j
r�|tgkr�d}|�|||||	�WdQRXxXt
D]P}
xJdD]B}|j||
|d	��(|��}|
||<|�|||||�WdQRXq�Wq�WdS)
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
        NFr)rrrr
r
T)Zdefault_localer
)rr)rGZnominal_localer
)rHr8�EXPECTED_C_LOCALE_FS_ENCODING�!EXPECTED_C_LOCALE_STREAM_ENCODING�LEGACY_LOCALE_WARNING�updaterI�!EXPECT_COERCION_IN_DEFAULT_LOCALE�test�support�
is_androidr;rC�EXPECTED_C_LOCALE_EQUIVALENTSrJ)
r?r&r'�coerce_c_localerBr%Z
extra_varsrKZ_expected_warningsZ_coercion_expectedrLrGrMrrr�_check_c_locale_coercionsR





z,LocaleCoercionTests._check_c_locale_coercioncCs|jdddd�dS)Nzutf-8)rY)rZ)r?rrr� test_PYTHONCOERCECLOCALE_not_set_sz4LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_setcCs"xdD]}|jdd|d�qWdS)N)r�1�trueZfalsezutf-8)rY)rZ)r?Zsettingrrr�!test_PYTHONCOERCECLOCALE_not_zerocs
z5LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_zerocCs|jdddtgd�dS)Nzutf-8�warn)rYrB)rZr;)r?rrr�$test_PYTHONCOERCECLOCALE_set_to_warnisz8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_warncCs*|jttddd�|jttdddd�dS)N�0F)rYr%r)rYrr%)rZrPrQ)r?rrr�$test_PYTHONCOERCECLOCALE_set_to_zeropsz8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_zerocCs0|jttdddd�|jttddtgdd�dS)NrF)rYrr%r_)rYrrBr%)rZrPrQrR)r?rrr�test_LC_ALL_set_to_C}sz(LocaleCoercionTests.test_LC_ALL_set_to_CcCs�t�tjd�}|�tjtj|�t�tjd�}|dkr@|�d�|tkrV|�d|�d}ttjdd�}t	j
tjd|gt	j
|d	d
�}|�|j��|�dS)Nrrz.test requires LC_CTYPE locale different than Czcoerced LC_CTYPE locale: %sz=import locale; print(locale.setlocale(locale.LC_CTYPE, None))r\)r
z-cT)�stdout�env�text)�locale�	setlocalerZ
addCleanupZskipTest�TARGET_LOCALESr"�os�environ�
subprocess�run�sys�
executable�PIPEr>rdr0)r?Zold_loc�loc�codererrrr�#test_PYTHONCOERCECLOCALE_set_to_one�s
z7LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_one)NT)
r3r4r5rZr[r^r`rbrcrsrrrrrOs	
F
rOcCstj�tt�tj��dS)N)rUrVZrun_unittestrDrOZ
reap_childrenrrrr�	test_main�srt�__main__)/rgrjZshutilrlrnZ	sysconfigrE�collectionsrZtest.supportrUZtest.support.script_helperrrrXrQrPrTri�platform�
startswithrVrWrr9�bool�hasattrrr�_fieldsZ_EncodingDetailsrrRr:r8r!r;r<ZTestCaser=rDZcpython_onlyZ
skipUnlessZget_config_varrOrtr3rrrr�<module>sf





:-