Sindbad~EG File Manager

Current Path : /proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/
Upload File :
Current File : //proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/test_string_literals.cpython-312.pyc

�

'ΜgH4���dZddlZddlZddlZddlZddlZddlZdZd�ZGd�dej�Z
edk(rej�yy)a�Test correct treatment of various string literals by the parser.

There are four types of string literals:

    'abc'             -- normal str
    r'abc'            -- raw str
    b'xyz'            -- normal bytes
    br'xyz' | rb'xyz' -- raw bytes

The difference between normal and raw strings is of course that in a
raw string, \ escapes (while still used to determine the end of the
literal) are not interpreted, so that r'\x00' contains four
characters: a backslash, an x, and two zeros; while '\x00' contains a
single character (code point zero).

The tricky thing is what should happen when non-ASCII bytes are used
inside literals.  For bytes literals, this is considered illegal.  But
for str literals, those bytes are supposed to be decoded using the
encoding declared for the file (UTF-8 by default).

We have to test this with various file encodings.  We also test it with
exec()/eval(), which uses a different code path.

This file is really about correct treatment of encodings and
backslashes.  It doesn't concern itself with issues like single
vs. double quotes or singly- vs. triply-quoted strings: that's dealt
with elsewhere (I assume).
�Na�# coding: %s
a = 'x'
assert ord(a) == 120
b = '\x01'
assert ord(b) == 1
c = r'\x01'
assert list(map(ord, c)) == [92, 120, 48, 49]
d = '\x81'
assert ord(d) == 0x81
e = r'\x81'
assert list(map(ord, e)) == [92, 120, 56, 49]
f = '\u1881'
assert ord(f) == 0x1881
g = r'\u1881'
assert list(map(ord, g)) == [92, 117, 49, 56, 56, 49]
h = '\U0001d120'
assert ord(h) == 0x1d120
i = r'\U0001d120'
assert list(map(ord, i)) == [92, 85, 48, 48, 48, 49, 100, 49, 50, 48]
c��t|g�S)N)�bytes)�is �6/usr/local/lib/python3.12/test/test_string_literals.py�byter<s���!��:��c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�TestLiteralsc��tjdd|_tj�|_tjj
d|j
�y)Nr)�sys�path�	save_path�tempfile�mkdtemp�tmpdir�insert��selfs r�setUpzTestLiterals.setUpBs7�����!�����&�&�(���������4�;�;�'rc��|jtjddtj|j
d��y)NT)�
ignore_errors)rrr
�shutil�rmtreerrs r�tearDownzTestLiterals.tearDownGs%���n�n�������
�
�d�k�k��6rc�`�tD]%}|dk(r�	d|cxkrdkr�nJt|���y)N�
� �~)�TEMPLATE�repr)r�cs  r�
test_templatezTestLiterals.test_templateKs.���A���9��q��C��8��a��8�/�rc�z�|jtd�d�|jtd�td��|jtd�td��|jtd�td��|jtd�td��|jtd	�td
��|jtd�td
��|jtd�td
��|jtd�td
��y)Nz 'x' �xz '\x01' �z '' z '\x81' �u '' z
 '\u1881' �u 'ᢁ' z '\U0001d120' � �u '𝄠' ��assertEqual�eval�chrrs r�test_eval_str_normalz!TestLiterals.test_eval_str_normalQs�������k�*�C�0�����o�.��A��7�����n�-�s�1�v�6�����o�.��D�	�:�����n�-�s�4�y�9�����/�0�#�f�+�>�����.�/��V��=�����3�4�c�'�l�C�����2�3�S��\�Brc��|jttd�|jttd�|jttd�|jttd�|jttd�|jttd�|jttd�|jttd�|jttd	�|jttd
�|jttd�|jttd�|jttd
�|jttd�y)Nz '\x' z '\x0' z '\u' z '\u0' z '\u00' z	 '\u000' z '\U' z '\U0' z '\U00' z	 '\U000' z
 '\U0000' z '\U00000' z '\U000000' z
 '\U0000000' ��assertRaises�SyntaxErrorr+rs r�test_eval_str_incompletez%TestLiterals.test_eval_str_incomplete\s�����+�t�]�;����+�t�^�<����+�t�]�;����+�t�^�<����+�t�_�=����+�t�-=�>����+�t�]�;����+�t�^�<����+�t�_�=����+�t�-=�>����+�t�->�?����+�t�-?�@����+�t�-@�A����+�t�-A�Brc	��tdd�D]O}|dvr�|jt�5|jt	d|z�dt|�z�ddd��Qt
jd��5}t
jdt�	�t	d
�ddd�|jt�d�|jt|dj�d�|j|djd
�|j|djd�t
jd��5}t
jdt�	�|jt�5}t	d
�ddd�j }ddd�|j|g�|jj"d�|j|jd
�|j|jd�|j|j$d�t
jd��5}t
jdt�	�|jt�5}t	d�ddd�j }ddd�|jt|�d�|j|dj&t�|j)t|dj�d�|j|djd
�y#1swY��xYw#1swY��~xYw#1swY���xYw#1swY���xYw#1swY��xYw#1swY��xYw)Nr%�s

"'01234567NU\abfnrtuvxz'\%c'�\T��record�always��categoryz	'''
\z'''r�invalid escape sequence '\z'�<string>�errorz'\e' $zinvalid escape sequence)�range�assertWarns�
SyntaxWarningr*r+r,�warnings�catch_warnings�simplefilter�len�str�message�filename�linenor0r1�	exception�msg�offsetr:�assertRegex�r�b�w�cm�excs     r�test_eval_str_invalid_escapez)TestLiterals.test_eval_str_invalid_escapels}���q�#��A��6�6���!�!�-�0�� � ��h��l�!3�T�C��F�]�C�1�0���
$�
$�D�
1�Q��!�!�(�]�C����2�	
����Q���#�����Q�q�T�\�\�*�,K�L�����1����
�3�����1����a�(�
�
$�
$�D�
1�Q��!�!�'�M�B��"�"�;�/�2��]�#�0��,�,�C�	2�
	
����B��������"A�B�������z�2�������Q�'�������Q�'��
$�
$�D�
1�Q��!�!�(�]�C��"�"�;�/�2��Y��0��,�,�C�	2�
	
����Q���#�����1����
�6�����Q�q�T�\�\�*�,E�F�����1����
�3�A1�0��2�
1��0�/��2�
1��0�/��2�
1�s_�+L�5'L�;1L2�,L%�8L2�,1M�L?�)M�L	�L"�%L/	�*L2�2L<�?M	�M�Mc��tdd�D]G}|jt�5|jt	d|z�t|��ddd��It
jd��5}t
jdt��t	d�ddd�|jt�d	�|jt|d
j�d�|j|d
jd�|j|d
jd	�t
jd��5}t
jd
t��|jt�5}t	d�ddd�j }ddd�|j|g�|jj"d�|j|jd�|j|jd	�|j|j$d	�y#1swY��xYw#1swY���xYw#1swY��xYw#1swY��xYw)N��z'\%o'Tr6r8r9z'''
\407'''r%r�$invalid octal escape sequence '\407'r<r=)r>r?r@r*r+r,rArBrCrDrErFrGrHr0r1rIrJrK�rrrOrPrQs     r�"test_eval_str_invalid_octal_escapez/TestLiterals.test_eval_str_invalid_octal_escape�s����u�f�%�A��!�!�-�0�� � ��h��l�!3�S��V�<�1�0�&��
$�
$�D�
1�Q��!�!�(�]�C���!�2�	
����Q���#�����Q�q�T�\�\�*�@�	B�����1����
�3�����1����a�(�
�
$�
$�D�
1�Q��!�!�'�M�B��"�"�;�/�2��_�%�0��,�,�C�	2�
	
����B��������"I�J�������z�2�������Q�'�������Q�'�+1�0��2�
1��0�/��2�
1�s;�(H�-'H�31H5�$H)�0H5�H	�H&�)H2	�.H5�5H>c�2�|jtd�d�|jtd�d�|jtd�td��|jtd�d�|jtd	�td
��|jtd�d�|jtd
�td��|jtd�d�|jtd�td��y)Nz r'x' r$z	 r'\x01' �\x01z r'' r%z	 r'\x81' z\x81u r'' r&z r'\u1881' z\u1881u r'ᢁ' r'z r'\U0001d120' z
\U0001d120u	 r'𝄠' r(r)rs r�test_eval_str_rawzTestLiterals.test_eval_str_raw�s�������l�+�S�1�����.�/��>�����o�.��A��7�����.�/��>�����o�.��D�	�:�����0�1�>�B�����/�0�#�f�+�>�����4�5�7I�J�����3�4�c�'�l�Crc� �|jtd�d�|jtd�td��|jtd�td��|jtd�td��|jttd�|jtd	�d
�|jttd�|jtd�d
�|jttd�y)Nz b'x' �xz	 b'\x01' r%z b'' z	 b'\x81' r&u b'' � br'\u1881' �\u1881u b'ᢁ' � br'\U0001d120' �
\U0001d120u	 b'𝄠' �r*r+rr0r1rs r�test_eval_bytes_normalz#TestLiterals.test_eval_bytes_normal�s�������l�+�T�2�����.�/��a��9�����o�.��Q��8�����.�/��d��<����+�t�_�=�����1�2�4D�E����+�t�->�?�����5�6�8L�M����+�t�-B�Crc�p�|jttd�|jttd�y)Nz b'\x' z b'\x0' r/rs r�test_eval_bytes_incompletez'TestLiterals.test_eval_bytes_incomplete�s&�����+�t�^�<����+�t�_�=rc	�\�tdd�D]P}|dvr�|jt�5|jt	d|z�dt|g�z�ddd��Rt
jd��5}t
jdt�	�t	d
�ddd�|jt�d�|jt|dj�d�|j|djd
�|j|djd�t
jd��5}t
jdt�	�|jt�5}t	d
�ddd�j }ddd�|j|g�|jj"d�|j|jd
�|j|jd�y#1swY���xYw#1swY��nxYw#1swY��xYw#1swY��xYw)Nr%r4s

"'01234567\abfnrtvxzb'\%c'�\Tr6r8r9z
b'''
\z'''rr;r<r=�r>r?r@r*r+rrArBrCrDrErFrGrHr0r1rIrJrMs     r�test_eval_bytes_invalid_escapez+TestLiterals.test_eval_bytes_invalid_escape�s����q�#��A��3�3���!�!�-�0�� � ��i�!�m�!4�e�e�Q�C�j�6H�I�1�0���
$�
$�D�
1�Q��!�!�(�]�C��� �2�	
����Q���#�����Q�q�T�\�\�*�,K�L�����1����
�3�����1����a�(�
�
$�
$�D�
1�Q��!�!�'�M�B��"�"�;�/�2��^�$�0��,�,�C�	2�
	
����B��������"A�B�������z�2�������Q�'�'1�0��2�
1��0�/��2�
1�s;�,G<�6'H	�<1H"�-H�9H"�<H	�	H�H	�H"�"H+c	�R�tdd�D]K}|jt�5|jt	d|z�t|dzg��ddd��Mt
jd��5}t
jdt��t	d	�ddd�|jt�d
�|jt|dj�d�|j|djd
�|j|djd
�t
jd��5}t
jdt��|jt�5}t	d	�ddd�j }ddd�|j|g�|jj"d�|j|jd
�|j|jd
�y#1swY���xYw#1swY��nxYw#1swY��xYw#1swY��xYw)NrTrUzb'\%o'�Tr6r8r9zb'''
\407'''r%rrVr<r=rhrWs     r�$test_eval_bytes_invalid_octal_escapez1TestLiterals.test_eval_bytes_invalid_octal_escape�s����u�f�%�A��!�!�-�0�� � ��i�!�m�!4�e�Q��Y�K�6H�I�1�0�&��
$�
$�D�
1�Q��!�!�(�]�C��!�"�2�	
����Q���#�����Q�q�T�\�\�*�@�	B�����1����
�3�����1����a�(�
�
$�
$�D�
1�Q��!�!�'�M�B��"�"�;�/�2��%�&�0��,�,�C�	2�
	
����B��������"I�J�������z�2�������Q�'�)1�0��2�
1��0�/��2�
1�s;�,G7�1'H�71H�(H�4H�7H	�H�H	�H�H&c�8�|jtd�d�|jtd�d�|jtd�d�|jtd�d�|jtd�td��|jtd	�td��|jtd
�d�|jtd�d�|jttd
�|jttd�|jtd�d�|jtd�d�|jttd�|jttd�|jtd�d�|jtd�d�|jttd�|jttd�|jttd�|jttd�|jttd�|jttd�|jttd�|jttd�y)Nz br'x' r]z rb'x' z
 br'\x01' �\x01z
 rb'\x01' z br'' r%z rb'' z
 br'\x81' s\x81z
 rb'\x81' u br'' u rb'' r^r_z rb'\u1881' u	 br'ᢁ' u	 rb'ᢁ' r`raz rb'\U0001d120' u
 br'𝄠' u
 rb'𝄠' z bb'' z rr'' z brr'' z bbr'' z rrb'' z rbb'' rbrs r�test_eval_bytes_rawz TestLiterals.test_eval_bytes_raw�s�������m�,�d�3�����m�,�d�3�����/�0�.�A�����/�0�.�A�����.�/��a��9�����.�/��a��9�����/�0�.�A�����/�0�.�A����+�t�-=�>����+�t�-=�>�����1�2�4D�E�����1�2�4D�E����+�t�-?�@����+�t�-?�@�����5�6�8L�M�����5�6�8L�M����+�t�-C�D����+�t�-C�D����+�t�\�:����+�t�\�:����+�t�]�;����+�t�]�;����+�t�]�;����+�t�]�;rc�~�|jtd�d�|jtd�d�|jtd�d�|jttd�|jttd�|jttd�|jttd	�y)
Nz u'x' r$u U'ä' �äu u'ä' z ur'' z ru'' z bu'' z ub'' )r*r+r0r1rs r�test_eval_str_uzTestLiterals.test_eval_str_us�������l�+�S�1�����/�0�$�7�����P�Q�SW�X����+�t�\�:����+�t�\�:����+�t�\�:����+�t�\�:rc��|jtd�d�|jtd�d�|jtd�d�|jtd�d��|jtd	�d
�y)Nz B'x' r]z	 R'\x01' rZz
 BR'\x01' rnz
 F'{1+1}' �z U'\U0001d120' u𝄠)r*r+rs r�test_uppercase_prefixesz$TestLiterals.test_uppercase_prefixessq������l�+�T�2�����.�/��9�����/�0�(�;�����.�/�C�5�:�����4�5�}�Erc�z�d|jdd�z}tjj|j|dz�}t|d|��}	|j
t|z�|j
|�|j�t|�tj|=y#|j�wxYw)N�xx_�-�_z.pyrO)�encoding)�replace�osr
�joinr�open�writer�close�
__import__r�modules)rrz�extra�modname�fn�fs      r�check_encodingzTestLiterals.check_encoding s����(�*�*�3��4�4��
�W�W�\�\�$�+�+�w���
7����S�8�,��	�
�G�G�H�x�'�(�
�G�G�E�N�
�G�G�I��7���K�K�� ��
�G�G�I�s�)B(�(B:c�,�d}|jd|�y)Nu#z = 'ሴ'; assert ord(z) == 0x1234
�utf-8�r��rr�s  r�test_file_utf_8zTestLiterals.test_file_utf_8,s��9�����G�U�+rc�L�d}|jt|jd|�y)Nub'€'
r�)r0r1r�r�s  r�test_file_utf_8_errorz"TestLiterals.test_file_utf_8_error0s!�������+�t�':�':�G�U�Krc�&�|jd�y)Nr�r�rs r�test_file_utf8zTestLiterals.test_file_utf84s�����G�$rc�&�|jd�y)Nz
iso-8859-1r�rs r�test_file_iso_8859_1z!TestLiterals.test_file_iso_8859_17s�����L�)rc�&�|jd�y)Nzlatin-1r�rs r�test_file_latin_1zTestLiterals.test_file_latin_1:s�����I�&rc�&�|jd�y)N�latin9r�rs r�test_file_latin9zTestLiterals.test_file_latin9=s�����H�%rN)�)�__name__�
__module__�__qualname__rrr"r-r2rRrXr[rcrerirlrorrrur�r�r�r�r�r�r��rrr
r
@sw��(�
7�9�	C�C� $4�L(�2	D�	D�>�(�2(�0<�4;�F�
!�,�L�%�*�'�&rr
�__main__)
�__doc__r|rrr�unittestrArr�TestCaser
r��mainr�rr�<module>r�sY���:
�
�
������,�~&�8�$�$�~&�B�z���H�M�M�O�r

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists