Your IP : 216.73.216.213


Current Path : /opt/alt/python312/lib64/python3.12/test/test_tools/__pycache__/
Upload File :
Current File : //opt/alt/python312/lib64/python3.12/test/test_tools/__pycache__/test_i18n.cpython-312.opt-1.pyc

�

�#�j[>���dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZm
Z
ddlmZmZe�ee�j%�j&dzZd	�ZGd
�dej,�Zd�Zd
�Zedk(rReej8�dkDr+ej8ddk(re�ej:d�ej<�yy)z%Tests to cover the Tools/i18n package�N)�dedent)�Path)�assert_python_ok)�skip_if_missing�toolsdir)�temp_cwd�temp_dir�	i18n_datac��tjd�}d}tj|||�}tjd�}d}tj|||�}tjd�}d�}tj|||�}|S)zrNormalize the POT creation timestamp, charset and
    file locations to make the POT file easier to compare.

    z"POT-Creation-Date: .+?\\n"z-"POT-Creation-Date: 2000-01-01 00:00+0000\\n"z*"Content-Type: text/plain; charset=.+?\\n"z,"Content-Type: text/plain; charset=UTF-8\\n"z#:.+c�H�|djtjd�S)Nr�/)�replace�os�sep)�matchs �@/opt/alt/python312/lib64/python3.12/test/test_tools/test_i18n.pyrz#normalize_POT_file.<locals>.replace's���Q�x�������,�,�)�re�compile�sub)�pot�date_pattern�header�charset_pattern�charset�fileloc_patternrs       r�normalize_POT_filers~���:�:�<�=�L�
=�F�
�&�&��v�s�
+�C��j�j�!N�O�O�=�G�
�&�&��'�3�
/�C��j�j��)�O�-�
�&�&��'�3�
/�C��Jrc�n�eZdZdZeedd�Zd�Zd�Zd�Z	ddd	�d
�Z
d�Zd�Ze
jej j#d
�d�d��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d �Z#d!�Z$d"�Z%d#�Z&d$�Z'd%�Z(d&�Z)d'�Z*d(�Z+d)�Z,d*�Z-d+�Z.d,�Z/d-�Z0d.�Z1y/)0�Test_pygettextzTests for the pygettext.py tool�i18nzpygettext.pyc���i}|jd�D]O}|r|jd�r�|jd�}|jdd�\}}|j�||<�Q|S)z: utility: return the header of a .po file as a dictionary �
)�#�msgid�msgstr�"�:�)�split�
startswith�strip)�self�data�headers�line�key�vals      r�
get_headerzTest_pygettext.get_header2sc�����J�J�t�$�D��4�?�?�+C�D���:�:�c�?�D��z�z�#�q�)�H�C���9�9�;�G�C�L�%��rc��g}d}g}|jd�D]�}|rW|jd�r!|j|jd��n%|jdj	|��g}d}�\|jd�s�n|td�d}|j|jd��d}��|r |jdj	|��|S)z= utility: return all msgids in .po file as a list of strings Fr"r&zmsgid NT)r)r*�appendr+�join�len)r,r-�msgids�
reading_msgid�	cur_msgidr/s      r�
get_msgidszTest_pygettext.get_msgids=s������
��	��J�J�t�$�D���?�?�3�'��$�$�T�Z�Z��_�5��M�M�$�)�)�I�"6�7� "�I�$)�M�����x�(��C��M�N�+��� � ����C��1� $�
�%���
�
�d�i�i�	�2�3��
rc�Z�d|_|jt|�t|��y)z Check if two POT files are equalN)�maxDiff�assertEqualr)r,�expected�actuals   r�assert_POT_equalzTest_pygettext.assert_POT_equalUs%��������+�H�5�7I�&�7Q�Rr�T��args�strictc��d}td�5t|dd��5}|j|�ddd�td|jg|�|���}|r|j|jd�tdd��5}|j�}ddd�ddd�|j�S#1swY�xYw#1swY�.xYw#1swY�2xYw)	z0Return all msgids extracted from module_content.ztest.pyN�w�utf-8��encoding�-Xutf8r�messages.pot)	r�open�writer�scriptr=�err�readr:)r,�module_contentrCrD�filename�fp�resr-s        r�extract_from_strzTest_pygettext.extract_from_strZs�����
�d�^��h��g�6�"�����(�7�"�8�T�[�[�J�4�J��J�C��� � ����#�.��n�w�7�2��w�w�y��8�
����t�$�$�7�6��
8�7��
�^�s:�C�B-�AC�;B9�C�-B6	�2C�9C	�>C�Cc�*�|j|dd��S)z4Return all docstrings extracted from module_content.�z--docstringsFrB)rU)r,rQs  r�extract_docstrings_from_strz*Test_pygettext.extract_docstrings_from_strgs���$�$�^�:K�TY�$�Z�Zrc�:�td�5}td|j�tdd��5}|j	�}ddd�|j�}|j
d|�|j
d|�|j
d|�|j
d	|�|j
d
|�|j
d|�|j
d|�|j
d
|�|j
d|�ddd�y#1swY��xYw#1swYyxYw)z�Make sure the required fields are in the header, according to:
           http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry
        NrJrKrGrHzProject-Id-Version�POT-Creation-DatezPO-Revision-DatezLast-Translatorz
Language-TeamzMIME-VersionzContent-TypezContent-Transfer-EncodingzGenerated-By)rrrNrLrPr2�assertIn)r,�cwdrSr-rs     r�test_headerzTest_pygettext.test_headerks����d�^�s��X�t�{�{�3��n�w�7�2��w�w�y��8��_�_�T�*�F��M�M�.��7��M�M�-�v�6��M�M�,�f�5��M�M�+�V�4��M�M�/�6�2��M�M�.�&�1��M�M�.�&�1��M�M�5�v�>��M�M�.�&�1��^�7�7���^�s#�$D�D�B;D�D	�
D�D�aixzbpo-29972: broken test on AIXc�p�ddlm}td�5}td|j�t	dd��5}|j�}ddd�|j
�}|d}|jd	�r|dtd	�}|j|d
�ddd�y#1swY�ZxYw#1swYyxYw)z; Match the date format from xgettext for POT-Creation-Date r)�datetimeNrJrKrGrHrZz\nz%Y-%m-%d %H:%M%z)
r`rrrNrLrPr2�endswithr6�strptime)r,r`r\rSr-r�creationDates       r�test_POT_Creation_Datez%Test_pygettext.test_POT_Creation_Date�s���	&�
�d�^�s��X�t�{�{�3��n�w�7�2��w�w�y��8��_�_�T�*�F�!�"5�6�L��$�$�U�+�+�L�c�%�j�[�9��
���l�,>�?��^�7�7���^�s#�$B,�B �AB,� B)	�%B,�,B5c��dD]K}|j|�5|jtd|z��}|jd|�ddd��My#1swY�XxYw)N�z	"""doc"""z
r'''doc'''zR'doc'zu"doc"zE                def foo(bar):
                    %s
                �doc��subTestrXrr[�r,rgr7s   r�test_funcdocstringz!Test_pygettext.test_funcdocstring��`��B�C����c�"��9�9�&�B��B�;����
�
�e�V�,�#�"�C�"�"���0A�A	c��|jtd��}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz5        def foo(bar):
            b"""doc"""
        rg�rXr�assertFalse�r,r7r$s   r�test_funcdocstring_bytesz'Test_pygettext.test_funcdocstring_bytes��F���1�1�&�:�3
���	
���V�F�V�E�u��~�%�V�F�G��F�
�	A�Ac��|jtd��}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz5        def foo(bar):
            f"""doc"""
        rgrorqs   r�test_funcdocstring_fstringz)Test_pygettext.test_funcdocstring_fstring�rsrtc��dD]K}|j|�5|jtd|z��}|jd|�ddd��My#1swY�XxYw)Nrfz@                class C:
                    %s
                rgrhrjs   r�test_classdocstringz"Test_pygettext.test_classdocstring�rlrmc��|jtd��}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz0        class C:
            b"""doc"""
        rgrorqs   r�test_classdocstring_bytesz(Test_pygettext.test_classdocstring_bytes�rsrtc��|jtd��}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz0        class C:
            f"""doc"""
        rgrorqs   r�test_classdocstring_fstringz*Test_pygettext.test_classdocstring_fstring�rsrtc��dD]K}|j|�5|jtd|z��}|jd|�ddd��My#1swY�XxYw)Nrfz#                %s
                rgrhrjs   r�test_moduledocstringz#Test_pygettext.test_moduledocstring�s^��B�C����c�"��9�9�&�B��B�;����
�
�e�V�,�	#�"�C�"�"�rmc��|jtd��}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz        b"""doc"""
        rgrorqs   r�test_moduledocstring_bytesz)Test_pygettext.test_moduledocstring_bytes��F���1�1�&�:�3
���	
���V�F�V�E�u��~�%�V�F�G��Frtc��|jtd��}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz        f"""doc"""
        rgrorqs   r�test_moduledocstring_fstringz+Test_pygettext.test_moduledocstring_fstring�r�rtc�J�|jd�}|jd|�y)Nz_("""doc""" r'str' u"ing")�	docstring)rXr[�r,r7s  r�
test_msgidzTest_pygettext.test_msgid�s#���1�1�0�2���
�
�k�6�*rc�x�|jd�}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz
_(b"""doc""")rg�rXrprqs   r�test_msgid_byteszTest_pygettext.test_msgid_bytes��8���1�1�/�B�����V�F�V�E�u��~�%�V�F�G��F��	7�7c�x�|jd�}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz
_(f"""doc""")rgr�rqs   r�test_msgid_fstringz!Test_pygettext.test_msgid_fstring�r�r�c�\�|jtd��}|jd|�y)z3 Test docstrings for functions with annotated args z9        def foo(bar: str):
            """doc"""
        rgN�rXrr[r�s  r�!test_funcdocstring_annotated_argsz0Test_pygettext.test_funcdocstring_annotated_args��.���1�1�&�:�3
���	
�
�
�e�V�$rc�\�|jtd��}|jd|�y)z: Test docstrings for functions with annotated return type z;        def foo(bar) -> str:
            """doc"""
        rgNr�r�s  r�#test_funcdocstring_annotated_returnz2Test_pygettext.test_funcdocstring_annotated_return�r�rc�\�|jtd��}|jd|�y)z6 Test docstring for functions with default arg values z7        def foo(bar=()):
            """doc"""
        rgNr�r�s  r� test_funcdocstring_defvalue_argsz/Test_pygettext.test_funcdocstring_defvalue_args�r�rc��|jtd��}|jd|�|jd|�|jd|�y)z� Test docstring extraction for multiple functions combining
        annotated args, annotated return types and default arg values
        z�        def foo1(bar: tuple=()) -> str:
            """doc1"""

        def foo2(bar: List[1:2]) -> (lambda x: x):
            """doc2"""

        def foo3(bar: 'func'=lambda x: x) -> {1: 2}:
            """doc3"""
        �doc1�doc2�doc3Nr�r�s  r�!test_funcdocstring_multiple_funcsz0Test_pygettext.test_funcdocstring_multiple_funcs�sL���1�1�&�	:�	3
�	��	
�
�
�f�f�%��
�
�f�f�%��
�
�f�f�%rc�\�|jtd��}|jd|�y)ze Test docstring extraction for a class with colons occurring within
        the parentheses.
        z\        class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)):
            """doc"""
        rgNr�r�s  r�test_classdocstring_early_colonz.Test_pygettext.test_classdocstring_early_colons0���1�1�&�:�3
���	
�
�
�e�V�$rc�\�|jtd��}|jd|�y)Nz"        f"{_('foo bar')}"
        �foo barr�r�s  r�test_calls_in_fstringsz%Test_pygettext.test_calls_in_fstrings�.���1�1�&�:�3
���	
�
�
�i��(rc�\�|jtd��}|jd|�y)Nz#        rf"{_('foo bar')}"
        r�r�r�s  r�test_calls_in_fstrings_rawz)Test_pygettext.test_calls_in_fstrings_raw!r�rc�\�|jtd��}|jd|�y)Nz+        f"""{f'{_("foo bar")}'}"""
        r�r�r�s  r�test_calls_in_fstrings_nestedz,Test_pygettext.test_calls_in_fstrings_nested'r�rc�\�|jtd��}|jd|�y)Nz&        f"{obj._('foo bar')}"
        r�r�r�s  r� test_calls_in_fstrings_attributez/Test_pygettext.test_calls_in_fstrings_attribute-r�rc�\�|jtd��}|jd|�y)Nz*        f"{type(str)('foo bar')}"
        r��rXr�assertNotInr�s  r�(test_calls_in_fstrings_with_call_on_callz7Test_pygettext.test_calls_in_fstrings_with_call_on_call3s0���1�1�&�:�3
���	
����F�+rc�\�|jtd��}|jd|�y)Nz6        f"{_('foo {bar}').format(bar='baz')}"
        �	foo {bar}r�r�s  r�"test_calls_in_fstrings_with_formatz1Test_pygettext.test_calls_in_fstrings_with_format9s.���1�1�&�:�3
���	
�
�
�k�6�*rc��|jtd��}|j|D�cgc]	}d|vs�|��c}�ycc}w)Nz%        f"{_(f'foo {bar}')}"
        r�rorqs   r�)test_calls_in_fstrings_with_wrong_input_1z8Test_pygettext.test_calls_in_fstrings_with_wrong_input_1?sG���1�1�&�:�3
���	
���V�L�V�E�{�e�7K�%�V�L�M��Lrtc�\�|jtd��}|jd|�y)Nz        f"{_(1)}"
        r(r�r�s  r�)test_calls_in_fstrings_with_wrong_input_2z8Test_pygettext.test_calls_in_fstrings_with_wrong_input_2Es0���1�1�&�:�3
���	
����F�#rc��|jtd��}|jd|�|jd|�y)Nz%        f"{_('foo', 'bar')}"
        �foo�barr�r�s  r�(test_calls_in_fstring_with_multiple_argsz7Test_pygettext.test_calls_in_fstring_with_multiple_argsKs@���1�1�&�:�3
���	
�����'������'rc��|jtd��}|jd|�|jd|�|jd|�y)Nz)        f"{_('foo', bar='baz')}"
        r�r��bazr�r�s  r�'test_calls_in_fstring_with_keyword_argsz6Test_pygettext.test_calls_in_fstring_with_keyword_argsRsP���1�1�&�:�3
���	
�����'������'������'rc��|jtd��}|jd|�|jd|�y)Nz*        f"{_(f'foo') + _('bar')}"
        r�r�)rXrr�r[r�s  r�5test_calls_in_fstring_with_partially_wrong_expressionzDTest_pygettext.test_calls_in_fstring_with_partially_wrong_expressionZs>���1�1�&�:�3
���	
�����'��
�
�e�V�$rc�^�|jtd��}|j|dg�y)z@Test that function and class names are not mistakenly extracted.z�        def _(x):
            pass

        def _(x="foo"):
            pass

        async def _(x):
            pass

        class _(object):
            pass
        �N)rUrr=r�s  r�test_function_and_class_namesz,Test_pygettext.test_function_and_class_namesas2���&�&�v�/�(
���	
����"��&rc��t�D]E\}}}|j|��5|jd��}|j||�ddd��Gy#1swY�RxYw)z9Test that the pygettext output exactly matches snapshots.)�
input_filerGrHN)�extract_from_snapshotsri�	read_textr@)r,r��output_file�outputr>s     r�test_pygettext_outputz$Test_pygettext.test_pygettext_outputrsW��/E�/G�+�J��V������4�&�0�0�'�0�B���%�%�h��7�5�4�0H�4�4�s�%A�A	c���d}d}d}td�5td�5}t|dd�}|jj	�|jd|�d�d	�
�t|dd�}|jj	�|jd|�d�d	�
�t|d
d�}|jj	�|jd|�d�d	�
�t
d|j|�td�jd	�
�}|jd|�d�|�|jd|�d�|�|j||�ddd�ddd�y#1swY�xYw#1swYyxYw)zVMake sure the directories are inspected for source files
           bpo-31920
        zText to translate1zText to translate2zText to ignoreN�pypkgzpymod.pyz_(�)rGrHzpkg.pyz	pymod2.py�CVSz	pymod3.pyrJrKzmsgid "r&)rr	r�parent�mkdir�
write_textrrNr�r[r�)	r,�text1�text2�text3�sdir�pymod�pymod2�pymod3r-s	         r�test_files_listzTest_pygettext.test_files_listysF��%��$�� ��
�d�^�X�d�^�t���w�
�3�E��L�L��� ����r�%��!�_�w��?��$��+�6�F��M�M���!�����5�)�1�o���@��$��{�3�F��M�M���!�����5�)�1�o���@��X�t�{�{�D�9���'�1�1�7�1�C�D��M�M�G�E�7�!�,�d�3��M�M�G�E�7�!�,�d�3����U�D�)�#,�^�^�^�^��^�^�s#�E&�D+E�	E&�E#	�E&�&E/N)2�__name__�
__module__�__qualname__�__doc__rrrNr2r:r@rUrXr]�unittest�skipIf�sys�platformr*rdrkrrrvrxrzr|r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rArrrr-s��)�
�(�F�N�
3�F�	��0S�
8:�$�%�[�2�4�X�_�_�S�\�\�,�,�U�3�4�6�@�6�@�"-�H�H�-�H�H�-�H�H�+�
H�H�%�%�%�&�$%�)�)�)�)�,�+�N�$�(�(�%�'�"8�*rrc#�K�dddddd�}|j�D]�\}}t|t�r|\}}t|z}t|z}nt|z}|j	d�}|j�}t
d�5t|j�j|�tdtjg|�|j���||td�jd�	�f��ddd���y#1swY��xYw�w)
NrW)z--escaperA)zmessages.pyz
fileloc.pyz
docstrings.py�
escapes.py)r�zascii-escapes.potz.potrJrKrGrH)�items�
isinstance�tuple�DATA_DIR�with_suffix�
read_bytesrr�name�write_bytesrrrNr�)�	snapshotsrRrCr�r��contentss      rr�r��s�����(�'�*�$�-/�	�I�$�/�/�+���$��h��&�$,�!�H�k�"�[�0�K�!�H�,�J�!�H�,�J�$�0�0��8�K��(�(�*��
�d�^�����!�-�-�h�7��X�~�'<�'<�
.�t�
.�'�_�_�
.��{���'�1�1�7�1�C�E�
E�	�^�,��^�s�A<D�>A,C5�*D�5C>	�:Dc�f�t�D]$\}}}t|�}|j|d���&y)NrGrH)r�rr�)�_r�r�s   r�update_POT_snapshotsr��s3��"8�":���;��#�F�+�����v���8�#;r�__main__r(z--snapshot-update)r�rrr�r��textwrapr�pathlibr�test.support.script_helperr�test.test_toolsrr�test.support.os_helperrr	�__file__�resolver�r�r�TestCaserr�r�r�r6�argv�exit�mainrArr�<module>r�s���+�	�	�
����7�5�5�����>�!�!�#�*�*�[�8���2d*�X�&�&�d*�NE�:9��z��
�3�8�8�}�q��S�X�X�a�[�,?�?����������H�M�M�O�r