Your IP : 216.73.216.85


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_c_locale_coercion.cpython-39.pyc

a

XC?h�K�@s�ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddgZdZ
dZdZgd	�Zej�d
�r�e	jr�dZ
dZq�e�d�nHej�d
�r�dZ
dZn2ejdkr�dZn"ejdkr�dZnejdkr�dZ
dZd	Zeejdv�oeed��oeed��Zdd�ZdZede�ZGdd�de�ZdZdZdada da!dd�Z"Gdd �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)zC.UTF-8zC.utf8�UTF-8�linux�utf-8ZPOSIXZaixz	iso8859-1�darwin�cygwinFZvxworks)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/alt/python39/lib64/python3.9/test/test_c_locale_coercion.py�_set_locale_in_subprocessWs
rzBfsencoding stdin_info stdout_info stderr_info lang lc_ctype lc_all�EncodingDetailsc@s2eZdZd�gd��Zedd��Zedd��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'))cCs||d}d|�d�g}|�|�d��|�dd�}|r>t}n|�dd�}|�dd�}	|||	f}
t||g|�|
�R����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_detailsrs
z$EncodingDetails.get_expected_detailscCsltddd|jfi|��\}}|jdks0|�|�|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__�joinr/�classmethodr.r6rrrrres

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�tdur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"
rFc@seZdZdd�ZdS)�_LocaleHandlingTestCasec
CsJt�|�}|\}}t�||||�}	|�||	�|dur: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)rr6r.�assertEqual)
�selfr,�expected_fs_encoding�expected_stream_encoding�expected_warningsr)rZencoding_detailsr5Zexpected_detailsrrr�_check_child_encoding_details�s
�z5_LocaleHandlingTestCase._check_child_encoding_detailsN)r7r8r9rMrrrrrG�srGc@s eZdZedd��Zdd�ZdS)�LocaleConfigurationTestscCstst�d��dS)Nz No C-with-UTF-8 locale available)r<�unittestZSkipTest)r(rrr�
setUpClass�sz#LocaleConfigurationTests.setUpClassc
Cs�d|_d}d}ddddd�}dD]r}tD]h}|dkr>|dkr>q(|j||d��4|��}|||<|j|||ddd	�Wd�q(1s�0Yq(q dS)
Nr	r�r r!r"r�r r!r r)�env_varZconfigured_localeF)rLr))�maxDiffr<�subTest�copyrM)rIrJrK�
base_var_dictrS�
locale_to_set�var_dictrrr�)test_external_target_locale_configuration�s.���zBLocaleConfigurationTests.test_external_target_locale_configurationN)r7r8r9r;rPrZrrrrrN�s
rNZPY_COERCE_C_LOCALEz(C locale coercion disabled at build timec@sFeZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)�LocaleCoercionTestsNTc

Ksd|_ts t}t}d}|r tg}ddddd�}|�|�|durH||d<|jd|d��Ltrf|}|}	nd}d}	tj	r�|t
gkr�d}|�|||||	�Wd�n1s�0YtD]b}
dD]X}|j||
|d	��2|�
�}|
||<|�|||||�Wd�q�1�s0Yq�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
        NFrrQrT)Zdefault_localerrR)rSZnominal_localer)rTr<rDrC�LEGACY_LOCALE_WARNING�updaterUrEr�
is_androidr?rMrBrV)
rIr*r+�coerce_c_localerLr)Z
extra_varsrWZ_expected_warningsZ_coercion_expectedrXrSrYrrr�_check_c_locale_coercions^�
���"��z,LocaleCoercionTests._check_c_locale_coercioncCs|jdddd�dS)Nr	�r_�r`�rIrrr� test_PYTHONCOERCECLOCALE_not_setisz4LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_setcCsdD]}|jdd|d�qdS)N)r�1�trueZfalser	rarb)rIZsettingrrr�!test_PYTHONCOERCECLOCALE_not_zeromsz5LocaleCoercionTests.test_PYTHONCOERCECLOCALE_not_zerocCs|jdddtgd�dS)Nr	�warn)r_rL)r`r?rcrrr�$test_PYTHONCOERCECLOCALE_set_to_warnss�z8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_warncCs*|jttddd�|jttdddd�dS)N�0F)r_r)r�r_r"r))r`rDrCrcrrr�$test_PYTHONCOERCECLOCALE_set_to_zerozs��z8LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_zerocCs0|jttdddd�|jttddtgdd�dS)NrFrkrh)r_r"rLr))r`rDrCr\rcrrr�test_LC_ALL_set_to_C�s��z(LocaleCoercionTests.test_LC_ALL_set_to_Cc
Cs�t�tjd�}|�tjtj|�zt�tjd�}Wn4tjyf}z|�t|��WYd}~n
d}~00|dkrz|�d�|tvr�|�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))rerrT)�stdout�env�text)�locale�	setlocaler!Z
addCleanup�ErrorZskipTest�str�TARGET_LOCALESr&�os�environ�
subprocess�run�sys�
executable�PIPErHrnr4)rIZold_locZloc�e�coderorrrr�#test_PYTHONCOERCECLOCALE_set_to_one�s$$
�z7LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_one)NT)
r7r8r9r`rdrgrirlrmrrrrrr[s	�
J
r[cCst��dS)N)rZ
reap_childrenrrrr�tearDownModule�sr��__main__)-rqrvrxrzZ	sysconfigrO�collectionsr�testrZtest.support.script_helperrrBrCrDrEru�platform�
startswithr^r#r=�bool�hasattrrr�_fieldsZ_EncodingDetailsrr\r>r<r%r?rFZTestCaserGrNZcpython_onlyZ
skipUnlessZget_config_varr[r�r7�mainrrrr�<module>st


��
:�	�-�