Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.12.152.183
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_bytes.cpython-310.pyc
o

`b�-�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlZddlZddlmZmZddlmZejjrYdd�Znd	d�ZGd
d�d�ZGdd
�d
�ZGdd�dee
j�ZGdd�dee
j�ZGdd�de
j�ZGdd�de
j�ZGdd�dejj �Z!Gdd�de!e
j�Z"Gdd�de!e
j�Z#Gdd�d�Z$Gdd�de%�Z&Gd d!�d!e'�Z(Gd"d#�d#e'�Z)Gd$d%�d%e$e
j�Z*Gd&d'�d'e$e
j�Z+e,d(kr�e
�-�dSdS))z�Unit tests for the bytes and bytearray types.

XXX This is a mess.  Common tests should be unified with string_tests.py (and
the latter should be modernized).
�N)�
import_helper)�warnings_helper)�bigaddrspacetest�MAX_Py_ssize_t)�assert_python_failurecst����fdd��}|S)Ncs@t�dtf���|i|��Wd�S1swYdS�N��rZcheck_warnings�BytesWarning)�args�kw��func��8/usr/local/python-3.10/lib/python3.10/test/test_bytes.py�wrappers$�z%check_bytes_warnings.<locals>.wrapper)�	functools�wraps)rrrr
r�check_bytes_warningssrcCs|S�Nrr
rrrr$�c@seZdZddd�Zdd�ZdS)�	IndexablercCs
||_dSr��value)�selfrrrr�__init__)�
zIndexable.__init__cCs|jSrr�rrrr�	__index__+szIndexable.__index__N)r)�__name__�
__module__�__qualname__rrrrrrr(s
rc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zedd��Zdd�Zdd�Zedd ��Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$dAdB�Z%dCdD�Z&dEdF�Z'dGdH�Z(dIdJ�Z)dKdL�Z*dMdN�Z+dOdP�Z,dQdR�Z-dSdT�Z.dUdV�Z/dWdX�Z0dYdZ�Z1d[d\�Z2d]d^�Z3d_d`�Z4dadb�Z5dcdd�Z6dedf�Z7dgdh�Z8didj�Z9dkdl�Z:dmdn�Z;dodp�Z<dqdr�Z=dsdt�Z>dudv�Z?dwdx�Z@dydz�ZAd{d|�ZBd}d~�ZCdd��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�S)��
BaseBytesTestcCs.|��}|�t|�|j�|�|j|j�dSr)�	type2test�assertEqual�type�	__class__�r�brrr�test_basics1szBaseBytesTest.test_basicscCsH|�d�}tjtjfD]}||�}|�||�|�t|�t|��qdS�N�abcd)r#�copy�deepcopyr$r%�r�aZcopy_methodr(rrr�	test_copy6s
�zBaseBytesTest.test_copycs�|���|�t��d�|�t�fdd��|�t�fdd��|�t�fdd��|�t�fdd��|�t�fdd��|�t�fdd��|�t�fd	d��|�t�fd
d��|�t�fdd��|�t�fdd��|�t�fd
d��dS)Nrc��dS)Nrrr�r(rr�<lambda>@�z3BaseBytesTest.test_empty_sequence.<locals>.<lambda>cr1�N�rrr2rrr3Ar4cs
�tjSr��sys�maxsizerr2rrr3B�
cs�tjdSr5r7rr2rrr3C�cs�ddS�N�
�drrr2rrr3D�cr1�N���rrr2rrr3Er4cr1)N���rrr2rrr3Fr4cs�tjSrr7rr2rrr3Gr?c��tjdSr5r7rr2rrr3H�crC)N�r7rr2rrr3IrDcs�ddSr<rrr2rrr3Jr;)r#r$�len�assertRaises�
IndexErrorrrr2r�test_empty_sequence=sz!BaseBytesTest.test_empty_sequencecCs|�td��}|�t|�d�|�t|�ttd���|�dh�}|�|d�|�ddh�}|�t|�ddh�|�ttd���}|�t|�d�|�t|�ttd���|�dd	�td�D��}|�t|�d
�|�t|�ttd��ddd��Gd
d�d�}|�|��}|�|d�dS)N��*�*�+�-)rMrN)rNrMcss�|]	}|dr|VqdS)rENr��.0�irrr�	<genexpr>]s�z3BaseBytesTest.test_from_iterable.<locals>.<genexpr>�r6rEc@�eZdZdd�ZdS)z+BaseBytesTest.test_from_iterable.<locals>.ScSsd|S)N�r6rE�r)rrQrrr�__getitem__c�z7BaseBytesTest.test_from_iterable.<locals>.S.__getitem__N)rr r!rWrrrr�Sb�rY�)r#�ranger$rF�list�assertIn�tuple�iter)rr(rYrrr�test_from_iterableLs "z BaseBytesTest.test_from_iterablecCsT|�ttd���}|�t|�d�|�t|�ttd���|�d�}|�|d�dS�NrJrUr[)r#r_r\r$rFr]r'rrr�test_from_tuplehs

zBaseBytesTest.test_from_tuplecCsX|�ttd���}|�t|�d�|�t|�ttd���|�gd��}|�|d�dSrb)r#r]r\r$rFr'rrr�test_from_listps
zBaseBytesTest.test_from_listcs\G�fdd�d�}|�|�g�|�t��d�G�fdd�d�}|�g�|�t��d�dS)Nc�eZdZ�fdd�ZdS)z0BaseBytesTest.test_from_mutating_list.<locals>.Xcs���dS�NrK)�clearr�r/rrr{sz:BaseBytesTest.test_from_mutating_list.<locals>.X.__index__N�rr r!rrrhrr�Xz�rjrLcre)z0BaseBytesTest.test_from_mutating_list.<locals>.Ycst��dkr��|�dS)N��rK)rF�appendrrhrrr�s
z:BaseBytesTest.test_from_mutating_list.<locals>.Y.__index__Nrirrhrr�Y�rkrns�****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************�r$�bytes)rrjrnrrhr�test_from_mutating_listxsz%BaseBytesTest.test_from_mutating_listcCsd|�t�td�td�td�g�}|�t|�gd��|�t|jtd�g�|�t|jtd�g�dS)Nr6���rr6rrrsrArJ)r#rr$r]rG�
ValueErrorr'rrr�test_from_index�s�zBaseBytesTest.test_from_indexcCsb|�t�dgd���}|�|d�|�d�}|�|d�Gdd�dt�}|�|�|d��d�dS)N�BrUr[c@rT)z)BaseBytesTest.test_from_buffer.<locals>.BcSst�r)�	TypeErrorrrrrr�rz3BaseBytesTest.test_from_buffer.<locals>.B.__index__Nrirrrrrw�rZsfoobar)r#�arrayr$rp)rr/rwrrr�test_from_buffer�s
zBaseBytesTest.test_from_buffercCs�|�|�d�d�|�|�d�d�|�|�d�d�|�t|jd�|�|�dd	�d
�|�|�d
�d
�|�t|jtjd�dS)Nr�r6��srA�0�ascii�0)r$r#rGru�
OverflowErrorr8r9rrrr�test_from_ssize�szBaseBytesTest.test_from_ssizecCs&|�t|jd�Gdd�d�}|�t|jdg�|�t|jdg�|�t|jdg�|�t|j|�g�|jt|jdd�|jt|jdd�|�t|jd	d�|�t|jd
d�|jt|jd	dd�|jt|jd
dd�|�t|jd�|jt|jddd�|�t|jdd�|�t|jddd
�dS)Ngc@�eZdZdS)z5BaseBytesTest.test_constructor_type_errors.<locals>.CN�rr r!rrrr�C��r�r~r)�encoding�ignore)�errorsrr{rsasciisignore)rGrxr#)rr�rrr�test_constructor_type_errors�s z*BaseBytesTest.test_constructor_type_errorscCs�|�t|jdg�|�t|jtjg�|�t|jtjdg�|�t|jtjdg�|�t|jddg�|�t|jdg�|�t|jdg�|�t|jtjg�|�t|jtjdg�|�t|jddg�dS)NrAr6rEr=r>rJi)rGrur#r8r9rrrr�test_constructor_value_errors�sz+BaseBytesTest.test_constructor_value_errorsc	CsDt}|�ttf|j|�z	t|d�WdSttfy!YdSw)N�)rrGr��MemoryErrorr#�	bytearray)r�sizerrr�test_constructor_overflow�s�z'BaseBytesTest.test_constructor_overflowcCsXGdd�d�}|�t|j|��|�t|j|�g�Gdd�d�}|�t|j|��dS)Nc@rT)z9BaseBytesTest.test_constructor_exceptions.<locals>.BadIntcS�dddS�Nr6rrrrrrr��zCBaseBytesTest.test_constructor_exceptions.<locals>.BadInt.__index__Nrirrrr�BadInt�rZr�c@rT)z>BaseBytesTest.test_constructor_exceptions.<locals>.BadIterablecSr�r�rrrrr�__iter__�r�zGBaseBytesTest.test_constructor_exceptions.<locals>.BadIterable.__iter__N)rr r!r�rrrr�BadIterable�rZr�)rG�ZeroDivisionErrorr#)rr�r�rrr�test_constructor_exceptions�s
z)BaseBytesTest.test_constructor_exceptionscCs|�gd��}|�gd��}|�ddg�}|�||�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�dS)NrUr6rV)r#r$�
assertTrue�assertFalse)r�b1�b2�b3rrr�test_compare�s&zBaseBytesTest.test_comparecCs�|�|�d�dkd�|�|�d�dkd�|�|�d�dkd�|�|�d�dkd�|�|��t�kd�|�|��t�kd�dS)Nsabc�abcFsabcsabcsabcT)r$r#�strrrrr�test_compare_to_str�s��z!BaseBytesTest.test_compare_to_strcCs<tttd��}|�|�}tt|��}|��|�||�dS)N�Hello)r]�map�ordr#�reversed�reverser$)r�inputr(�outputrrr�
test_reverseds

zBaseBytesTest.test_reversedcsP�fdd�}|d�}��|dd�|d����|dd�|d����|dd�|d	����|dd�|d
����|dd�|d
����|dd�|d
����|dd
�|d����|dd
�|d����|d
d�|d	����|dd�|d
����|dd�|d
����|dd�|d
����|dd�|d��dS)Ncs��tt|��Sr)r#r�r���srrr�by
sz'BaseBytesTest.test_getslice.<locals>.by�Hello, worldr}r�r6Zello�z, �world�r>���i����������)r$�rr�r(rrr�
test_getsliceszBaseBytesTest.test_getslicecCs�ttd��}|�|�}ddddddtjddd	d
f}|D]#}|D]}|dd�D]}|�||||�|�||||���q'qqdS)Nrsrr6rV�r>rArB���r�)r]r\r#r8r9r$)r�Lr(�indices�start�stop�steprrr�test_extended_getslice s
(���z$BaseBytesTest.test_extended_getslicec	Csrd}dD]}|�||�}|�||�|�|���q|�t|j|d�|�|dd�}|�||�|dd�d��dS)N�Hello world
ሴ噸骼��utf-8zutf-16�latin-1r����r�)r#r$�encoderG�UnicodeEncodeError�r�sample�encr(rrr�
test_encoding+s zBaseBytesTest.test_encodingcCs�d}dD]}|�||�}|�|�|�|�qd}|�|d�}|�t|jd�|�|�dd�d�|�|jddd�d�|�|�d	���d
�dS)Nr�r�uHello world
€þÿr�r�r�zHello world
)r�r�s☃u☃)r#r$�decoderG�UnicodeDecodeErrorr�rrr�test_decode4s�zBaseBytesTest.test_decodecCsdd}d}t�d|jj�d|�d|�d|�d|�d|�d	|�d
��}tddd
|�}|�|jd|�dS)NzBoom, Shaka Laka, Boom!)r�utf8�latin1z0
            import sys
            type2test = z
            encodings = zr

            for data in ('', 'short string'):
                try:
                    type2test(data, encoding=z�)
                except LookupError:
                    pass
                else:
                    sys.exit(21)

                for encoding in encodings:
                    try:
                        type2test(data, encoding=encoding, errors=a>)
                    except LookupError:
                        pass
                    else:
                        sys.exit(22)

            for data in (b'', b'short string'):
                data = type2test(data)
                print(repr(data))
                try:
                    data.decode(encoding=z�)
                except LookupError:
                    sys.exit(10)
                else:
                    sys.exit(23)

                try:
                    data.decode(errors=z�)
                except LookupError:
                    pass
                else:
                    sys.exit(24)

                for encoding in encodings:
                    try:
                        data.decode(encoding=encoding, errors=z�)
                    except LookupError:
                        pass
                    else:
                        sys.exit(25)

            sys.exit(10)
        z-X�devz-cr=)�textwrap�dedentr#rrr$�rc)r�invalid�	encodings�code�procrrr�test_check_encoding_errorsBs&����� �(
�0z(BaseBytesTest.test_check_encoding_errorscCsb|�d�}|�||���|�d�}|�||�dgd��|�d�}|�||�dgd��dS)Nrr=i')r#r$r'rrr�
test_from_intzs


zBaseBytesTest.test_from_intcsx|�d��|�d��|���d�|��td�d�|�td��d�|�t�fdd��|�t�fdd��dS)N�abc�def�abcdefsdefabccs�dS)N�defrr)r�rrr3�r4z+BaseBytesTest.test_concat.<locals>.<lambda>csd�S)Nr�rr)r�rrr3�r4)r#r$rprGrxrr)r�r�r�test_concat�s

zBaseBytesTest.test_concatc	s�d|�d�fD]f�|��dd�|��dd�|��dd�|�t�fdd��|�t�fd	d��|�ttf��
�tj}Wd�n1sLwY|�ttf��
�tj9�Wd�n1shwYqdS)
Nr�rV�	abcabcabcrr{rAcs�dS�Ng��Q�	@rrr2rrr3�r4z+BaseBytesTest.test_repeat.<locals>.<lambda>csd�Sr�rrr2rrr3�r4)r#r$rGrxr�r�r8r9�r�crr2r�test_repeat�s����zBaseBytesTest.test_repeatcCs*|�|�d�d|�td�gd��dS)N�xr>�x)r$r#r�rrrr�test_repeat_1char�s*zBaseBytesTest.test_repeat_1charcst|�d��|�td���|�ttd����|�d��|�t�fdd��|�t�fdd��|�t�fdd��|�t�fdd��|�t�fd	d��|�t�fd
d��tt	fD]Z}|�|d���|�|d���|�|d
���|�|d���|�|d���|�|d���|�|d���|�|d���|�|d���|�|d���|�|d���q]dS)Nr�r/��c�d�vS)N�,rrr2rrr3�r4z-BaseBytesTest.test_contains.<locals>.<lambda>cr�r@rrr2rrr3�r4cstjd�vSr5r7rr2rrr3�r;csd�vSrrrr2rrr3�r4csttd���vS�Nr/)�floatr�rr2rrr3�rDcr�r�rrr2rrr3�r4r{�a�b�c�ab�bc�ac�dsdabsabd)
r#r^r��intZassertNotInrGrurxrpr��r�frr2r�
test_contains�s.
�zBaseBytesTest.test_containsc	Cs�|�t|jj�|�t|jjd�|�|j�d�|���tgd��}|�|j�d�|�|�|j�d�|�|�|j�d�|�dD]}|�|j�|�|���qCdD]}|�t|jj|�qT|�|j�d	�d
�|�t|jjd�|�t|jjd�|�t|jjd
�|�t|jjd�|�t|jjd�|�t|jjd�dD]*\}}|�t��}|j�|�Wd�n1s�wY|�d|t|j	��q�dS)Nr6r��rM�0�1a2B30z  1A 2B  30   z
 1A
2B	30z	

 u…   
Z0000ss1Br/Zrtz1a b cd�z12      34))z12 x4 56rV)z12 3x 56r�)z12 xy 56rV)u	12 3ÿ 56r�zat position %s)
rGrxr#�fromhexr$r�rur^r��	exception)rr(r��data�pos�cmrrr�test_fromhex�s0
��zBaseBytesTest.test_fromhexcCs~|�t|jj�|�t|jjd�|�|�d���d�|�tgd����d�|�|�d���d�|�td���d�dS)Nr6r{rr�Z1a2b30�+0)rGrxr#�hexr$r��
memoryviewrrrr�test_hex�szBaseBytesTest.test_hexcCs�|�d�}|�|��d�|�t��
|�d�Wd�n1s"wY|�t��
|�d�Wd�n1s<wY|�|�dd�d�|�t��|�dd�Wd�n1sawY|�t��
|�d�Wd�n1s{wY|�t��
|�d�Wd�n1s�wY|�t��
|�d	�Wd�n1s�wY|�t��|�td
��Wd�n1s�wY|�|�dd�d�|�|�d�d�|�|�d
�d�|�|�d�d�|�|�d�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�d�d�|�|�d�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�d}|�|�dd �d!�dS)"Ns��Zb901efr�xx�:r�ÿ����rJr|zb901efr��zb901ef�rVr����zb9:01:ef�$zb9$01$efr6rArEzb9:01ef�*rBzb901*efs {sworldishelloi0�.�zC7b7305000000776f.726c646902000000.730500000068656c.6c6f690100000030)r#r$rrGrurx�chr)rZthree_bytesrrrr�test_hex_separator_basics�sR
�������z'BaseBytesTest.test_hex_separator_basicscCs$|�tdd��}|�|��d�dS)N�Z�_Z
5a5b5c5d5e�r#r\r$r)rZ
five_bytesrrr�test_hex_separator_five_bytessz+BaseBytesTest.test_hex_separator_five_bytescCs|�dd�tdd�D��}|�|��d�|�|�dd�d�|�|�dd	�d
�|�|�dd�d
�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�dS)Ncss�|]}|dVqdS)rVNr�rPr�rrrrR
��z=BaseBytesTest.test_hex_separator_six_bytes.<locals>.<genexpr>r6r�Z0306090c0f12rz03.06.09.0c.0f.12� rEz0306 090c 0f12�-rVz
030609-0c0f12rr�z
0306:090c0f12r}z
03:06090c0f12�r�_r�Z
030609_0c0f12rz
0306090c:0f12�@r�z
0306090c0f@12i����i����r)rZ	six_bytesrrr�test_hex_separator_six_bytes	sz*BaseBytesTest.test_hex_separator_six_bytescCs|�|�d��g�d�|�|�d��dg�d�dgddgddggd�fD]2}tt|j|��}|�|�d��|�d�|�|�d��t|��d�|�|�d��t|��d�q&|�d�j}|�|dd	g�d
�|�|td�d	g�d
�|�|dtd	�g�d
�|�|td�d	g�d
�|�|dtd	�g�d
�dgd}ddd
}|�||�|�dgd}dd}|�|�d��|�|�|�	t
|�d�jd�|�	t
��|td�ddg�Wd�n1s�wY|�	t
��|td�ddg�Wd�dS1�swYdS)Nr{r�r�r�r�r�)r�r�r�s.:scdsab.:cdi��s.:abci��� Zcdsef)r$r#�joinr]r�r_r`rr�rGrx)rZlstZdot_join�seqZexpectedrrr�	test_joins4

�$�zBaseBytesTest.test_joincCs|�d�}d}d}d}|�|�d�d�|�|�d�d�|�|�d	�d
�|�|�|�d�|�|�|�d
�|�|�dd�d�|�|�dd�d�|�|�dd
d�d
�|�|�ddd�d
�|�|�|d�d�|�|�|d�d�|�|�|d
d�d
�|�|�|dd�d
�dS)N�mississippi�i�p�w�ir��ssrE�wrr�pr6rVr��	)r#r$�count)rr(rQ�p�wrrr�
test_count7s"
zBaseBytesTest.test_countcCs�|�d�}|�|���d��|�|�d��|�|�d��|�|�d��|�|�d��|�|�d��|�t��}|�dg�Wd�n1sMwYt|j�}|�d|�|�d|�dS)	N�hello�anythingshel�hshellowsharpr_)	r#r��
startswithr�rGrxr�r�r^�rr(r��excrrr�test_startswithNs
�
zBaseBytesTest.test_startswithcCs�|�d�}|�t��d��|�|�d��|�|�d��|�|�d��|�|�d��|�|�d��|�t��}|�dg�Wd�n1sLwYt|j�}|�	d|�|�	d|�dS)	Nr/r0sllo�oswhellosnorpr_)
r#r�r��endswithr�rGrxr�r�r^r3rrr�
test_endswith\s
�
zBaseBytesTest.test_endswithcCs|�d�}d}d}|�|�d�d�|�|�d�d�|�|�d�d�|�|�|�d	�|�|�|�d�|�|�dd
�d�|�|�dd	d�d�|�|�dd	d
�d�|�|�|d
�d�|�|�|d	d
�d	�|�|�|d	d
�d�ddtjd	fD]}|�td|j|�q~dS)Nr"r#r%r'rEr(rA�
mississippianr6rVr}r�rrJzbyte must be in range\(0, 256\))r#r$�findr8r9�assertRaisesRegexru)rr(rQr-�indexrrr�	test_findjs(
��zBaseBytesTest.test_findcCs�|�d�}d}d}|�|�d�d�|�|�d�d�|�|�d�d�|�|�|�d	�|�|�|�d�|�|�dd
�d�|�|�ddd�d
�|�|�|dd
�d�|�|�|d
d�d�|�|�|dd
�d�dS)Nr"r#r%r'r}r(rAr9r=rVrrrEr6r*r�)r#r$�rfind�rr(rQr-rrr�
test_rfind�s
zBaseBytesTest.test_rfindcCs�|�d�}d}d}|�|�d�d�|�t|jd�|�t|jd�|�|�|�d�|�t|j|�|�|�dd	�d
�|�|�ddd�d�|�t|jddd	�|�|�|d�d�|�|�|dd	�d�|�t|j|dd	�dS)
Nr"r#r%r'rEr(r9r6rVr}r�r)r#r$r<rGrur?rrr�
test_index�s
zBaseBytesTest.test_indexcCs�|�d�}d}d}|�|�d�d�|�t|jd�|�t|jd�|�|�|�d�|�t|j|�|�|�dd	�d�|�|�dd
d�d�|�|�|d
d	�d
�|�|�|d	d�d�|�t|j|d
d	�dS)Nr"r#r%r'r}r(r9r=rVrrrEr6r*r�)r#r$�rindexrGrur?rrr�test_rindex�s
zBaseBytesTest.test_rindexcCs�|�d�}|}|d}|�|d�|�|d�|�||u�|�d�}|d}|�|d�|�t|�|j�|�d�}|d}|�|d�|�t|�|j�dS�	Ns
hello, %b!�worlds
hello, world!s%s / 100 = %d%%)sseventy-nine�Osseventy-nine / 100 = 79%s
hello,%b!s
hello,world!�r#r$r��assertIsr%)rr(�origr/rrr�test_mod��


zBaseBytesTest.test_modcCs�|�d�}|}|d;}|�|d�|�|d�|�||u�|�d�}|d;}|�|d�|�t|�|j�|�d�}|d;}|�|d�|�t|�|j�dSrDrG)rr(rIrrr�	test_imod�rKzBaseBytesTest.test_imodcCsV|�t��t�|�d�Wd�n1swY|�|�d��d�t�dS)Nr�z%r)rGrx�objectr#rH�__rmod__�NotImplementedrrrr�	test_rmod�s�zBaseBytesTest.test_rmodcCs6|�d�}|�|�dd�d�|�|�dd�d�dS)Nr"r&r�smassassappar'r�s	mixixippi)r#r$�replacer'rrr�test_replace�s
zBaseBytesTest.test_replacecCs|�t|�d�jdd�dS)N�a b� r{)rGrxr#rQrrrr�test_replace_int_error��z$BaseBytesTest.test_replace_int_errorcC�0|�t|�d�jd�|�t|�d�jd�dS�NrSr�rGrxr#�split�rsplitrrrr�test_split_string_error��z%BaseBytesTest.test_split_string_errorcCrW�NrSrTrYrrrr�test_split_int_error�r]z"BaseBytesTest.test_split_int_errorcCsFdD]}|�|�}|�|��|g�q|�d�}|�|��dg�dS)N)sabsabsabsab�		

�)r#r$rZr'rrr�test_split_unicodewhitespace�s


z*BaseBytesTest.test_split_unicodewhitespacecCs |�d�}|�|��dg�dS)Nr`ra)r#r$r[r'rrr�test_rsplit_unicodewhitespace�s
z+BaseBytesTest.test_rsplit_unicodewhitespacecCs2|�d�}|�|�d�d�|�|�d�d�dS)Nr"r')smir'sissippir()r"r{r{)r#r$�	partitionr'rrr�test_partition�s
zBaseBytesTest.test_partitioncCsD|�d�}|�|�d�d�|�|�d�d�|�|�d�d�dS)Nr"r')smissir'sippir&)s
mississippr&r{r()r{r{r")r#r$�
rpartitionr'rrr�test_rpartitions
zBaseBytesTest.test_rpartitioncCrWrX�rGrxr#rdrfrrrr�test_partition_string_error
r]z)BaseBytesTest.test_partition_string_errorcCrWr^rhrrrr�test_partition_int_errorr]z&BaseBytesTest.test_partition_int_errorcCsNttjd�D]}dD]}|�|�}t�||�}t�|�}|�||�qqdS�Nr6)r{r�r�s�ab�s�)r\�pickle�HIGHEST_PROTOCOLr#�dumps�loadsr$)r�protor(Zps�qrrr�
test_picklings

��zBaseBytesTest.test_picklingcCs�ttjd�D]W}dD]R}t|�|��}}t|�|��}t�||�}t�|�}|�t	|�t	|��|�t|�|�t�|�}|sBqt
|�t�||�}t�|�}|�t|�|dd��qqdSrk)r\rlrmr`r#r]rnror$r%�next)rrpr(�itZitorgr��drrr�test_iterator_picklings"


��z$BaseBytesTest.test_iterator_picklingcCsX|�|�d��td��d�|�|�d��td��d�|�|�d��td��d�dS)Nr�r�r�r�r�)r$r#�stripr�lstrip�rstriprrrr�test_strip_bytearray,s z"BaseBytesTest.test_strip_bytearraycC�F|�t|�d�jd�|�t|�d�jd�|�t|�d�jd�dS)Nr�Zac�rGrxr#rwrxryrrrr�test_strip_string_error1�z%BaseBytesTest.test_strip_string_errorcCr{)Ns abc rTr|rrrr�test_strip_int_error6r~z"BaseBytesTest.test_strip_int_errorcC�:|�d�}ttfD]}|�|�d|d��|�d��q	dS)Nr�r��-s--abc--)r#rpr�r$�center�rr(Z	fill_typerrr�test_center;�
��zBaseBytesTest.test_centercCr�)Nr�r�r�sabc----)r#rpr�r$�ljustr�rrr�
test_ljustBr�zBaseBytesTest.test_ljustcCr�)Nr�r�r�s----abc)r#rpr�r$�rjustr�rrr�
test_rjustIr�zBaseBytesTest.test_rjustcCsL|�t|�d�jdd�|�t|�d�jdd�|�t|�d�jdd�dS)Nr�r�rT)rGrxr#r�r�r�rrrr�test_xjust_int_errorPsz"BaseBytesTest.test_xjust_int_errorcs4|�d��|��fdd�tt���D�gd��dS)NsA��cs g|]}t�||d���qS�r6)r�rOr2rr�
<listcomp>Ws z*BaseBytesTest.test_ord.<locals>.<listcomp>)r�A�rSrs)r#r$r\rFrrr2r�test_ordUs
�zBaseBytesTest.test_ordcCs`d}|�|j�dd�|�d}|�|j�dd�|�|�t|jjdd�|�t|jjdd�dS)	Ns	

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`xyzdefghijklmnopqrstuvwxyz{|}~�����������������������������������������������������������������������������������������������������������������������������r��xyzs	

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������xyzs���sxyzqr�r�)r$r#�	maketransrGrurx)rZ
transtablerrr�test_maketransZszBaseBytesTest.test_maketranscCs�|�d�}|�d�}|�d�}|�d�}|�d�}|�d|�|d��|�d|�|dd��|�d|�|dd��|�d	|�|dd��|�d|�|d��|�d|�|dd��|�d|�|dd��|�d	|�|dd��|�d|�|d��|�d|�|dd��|�d|�|dd��|�d	|�|dd��|�d|�|d��|�d|�|dd��|�d|�|dd��|�d	|�|dd��|�d|�|d��|�d
|�|dd��|�d
|�|dd��|�d	|�|dd��|�d|�|d��|�d|�|dd��|�d|�|dd��|�d|�|dd��|�d|�|d��|�d|�|dd��|�d|�|dd��|�d|�|dd��dS)
Nr/�lr1r�r6rErVrBrr6TF)	r#r$r:r>r<rBr+r7r2)rr(�l�hr��orrr�test_none_argumentsbsB




z!BaseBytesTest.test_none_argumentscCsV|�d�}|j|j|j|j|jfD]}|�t|d�|�t|d�|�t|d�qdS)Nr/rArJi')r#r+r:r<r>rBrGru)rr(�methodrrr�(test_integer_arguments_out_of_byte_range�s
�z6BaseBytesTest.test_integer_arguments_out_of_byte_rangec	Cs�|�d�}|�d�}|�td|j|ddd�|�td|j|ddd�|�td|j|ddd�|�td|j|ddd�|�td|j|ddd�|�td|j|ddd�|�td	|j	|ddd�dS)
Nr/r�z\bfind\bz	\brfind\bz	\bindex\bz
\brindex\bz	\bcount\bz\bstartswith\bz\bendswith\b)
r#r;rxr:r>r<rBr+r2r7)rr(r�rrr�*test_find_etc_raise_correct_error_messages�s.

�������z8BaseBytesTest.test_find_etc_raise_correct_error_messagescCs(tj�|t|j�tj�|t|j�dSr)�test�supportZcheck_free_after_iteratingr`r#r�rrrr�test_free_after_iterating�sz'BaseBytesTest.test_free_after_iteratingcCs4|�d�}ttd��}td�|td�<|�t|j�|�t|jdd�|�t|jttd���|�|d�}|�	|d�|�
||j�|�|�}|�|d�}|�	||�|�	|d�|�|d�}|�	|d	�|�dd
�}|�	|d�|j|dd�}|�	|d�|j|dd�}|�	|d	�|jdd
d�}|�	|d�dS)
Nr/rJ�er�rsr{sheller�shee�eshllo)�delete)r#r�r\r�rGrx�	translaterurpr$�assertIsInstance)rr(Zrosettar�rurrr�test_translate�s.

zBaseBytesTest.test_translatecCs�t�d�}|�d�}|�t��|�|d�Wd�n1s wY|�t��|�|d�Wd�n1s;wY|�|�|d�d�dS)N�	_testcapi)rKrBr6rrK)r�
import_moduler#rGrHZsequence_getitemr$)rr��objrrr�test_sq_item�s

��zBaseBytesTest.test_sq_itemN)Krr r!r)r0rIrarcrdrqrvrzr�r�r�rr�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr!r.r5r8r=r@rArCrJrLrPrRrUr\r_rbrcrergrirjrrrvrzr}rr�r�r�r�r�r�r�r�r�r�r�r�rrrrr"/s�




	8	
%%+r"c@s@eZdZeZdd�Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
S)�	BytesTestcCsBd}d}|�t|��
|dWd�dS1swYdS)N�pythonz'byte indices must be integers or slicesr/)r;rx�rr(�msgrrr�test_getitem_error�s

"�zBytesTest.test_getitem_errorcCsRt�ttj�}t|ddd��}|�t|jd�Wd�dS1s"wYdS)N�rbr)�	bufferingr{)�os�open�__file__�O_RDONLYrGrx�readinto)r�fdr�rrr�test_buffer_is_readonly�s"�z!BytesTest.test_buffer_is_readonlycCsGdd�d�}|�t|��d�Gdd�d�}|�tt|��Gdd�d�}|�tt|��Gdd�d�}|�t|��d�Gdd�dt�}|�t|d	��d�|�t|d	�d
�d�Gdd�d�}|�t|��d�|�tt|���t�|�t|��d�|�tt|���t�dS)
Nc@rT)� BytesTest.test_custom.<locals>.AcS�dS�Nr�rrrrr�	__bytes__�r�*BytesTest.test_custom.<locals>.A.__bytes__N�rr r!r�rrrr�A�rZr�r�c@r�)r�Nr�rrrrr��r?c@rT)r�cSsdSrrrrrrr��rr�Nr�rrrrr��rZc@�eZdZdd�Zdd�ZdS)r�cSr�)Nr�rrrrrr��rr�cSr�rfrrrrrr�rz*BytesTest.test_custom.<locals>.A.__index__N)rr r!r�rrrrrr��sr�c@rT)r�cSr�r�rrrrrr��rr�Nr�rrrrr��rZu€z
iso8859-15��c@rT)r�cSstd�Sr�)�OtherBytesSubclassrrrrr��rXr�Nr�rrrrr��rZ)	r$rprGrxr�rHr%r��
BytesSubclass)rr�rrr�test_custom�s zBytesTest.test_customcsrt�d�}t�d�}ddlm}m}ddlm}m}m}m}m	}	m
}
m}|j}|f|_
||_|�|d�d�|�|dd�d	�|�|d
|d��d�|�|d
|td���d
�|�|d
|d��d�|�|d|d�|d�|	d��d�|�|d|d�|d�|	d��d�|�|d|d�|d�|	d��d�|�|d|d��d�|�|d|d ��d!�|�|d"|d#��d$�|�|�}
tjd%kr�d&�d|
���fd'd(�}nd)d(�}d*}|�|d+||��d,||��d-��|�|d.|d/��d0�|	d�j}d1||jtfd1||jtfd2||jtfd2||jtfd3||jtfd4|
|jtfd4|
|jtfd5|	|tfd6|||ff	D]\}}}}|�||||��||��d-��f�q,|�|d7d8�d8�|�|d9d:�d;�|�|d<�d=�|�|d>�d?�|�|d@|tdA���dB�|�|dC�dD�|�|d=�d=�|�|dE|d�|d��dF�|�t |dG|d��|�t |dG|dH��|�|dI�dI�|�|dDdI�dI�dS)JN�ctypesr�r)�	pythonapi�	py_object)�c_int�c_uint�c_long�c_ulong�c_size_t�	c_ssize_t�c_char_psformats
Hello %s !rEs
Hello world !sc=%csc=�@sc=@rssc=�sd=%d ld=%ld zd=%zdr6rErVs
d=1 ld=2 zd=3rArBr�sd=-1 ld=-2 zd=-3su=%u lu=%lu zu=%zu�{i�isu=123 lu=456 zu=789si=%isi=123i����si=-123sx=%xi�
sx=abc�ntz0x%0{}Xcs�|Srr��ptr�Z
ptr_formatrr�
ptr_formatter7rXz1BytesTest.test_from_format.<locals>.ptr_formattercSsd|S)Nz%#xrr�rrrr�;rXi�ͫsptr=%pzptr=rss=%sscstrss=cstrs%ds%lds%lus%zds%zus%ps%5sr�s%.3sr�r�s%%�%s[%%]s[%]s%%%crs%_s%%ss%ssx=%i y=%sx=2 y=%s%crJr{)!rr�r�r�r�r�r�r�r�r�r�r��PyBytes_FromFormat�argtypesZrestyper$r�Zsizeofr��name�formatr�rZINT_MINr�ZINT_MAXZLONG_MINZLONG_MAXZ	ULONG_MAXZPY_SSIZE_T_MINZPY_SSIZE_T_MAXrGr�)rr�r�r�r�r�r�r�r�r�r�r�r�Z
sizeof_ptrr�r�Zsize_maxZ	formatstrZctypes_typerZpy_formatterrr�r�test_from_formats�

$
��������������

��


�
���
�
��
��
�
�
��zBytesTest.test_from_formatcCs�Gdd�dt�}gd�}|�t|�d�|�tt||��Gdd�dt�}|�td�d�|�tt|d��Gd	d
�d
t�}|�td�d�|�tt|d��Gdd
�d
t�}td�|d�}}|�t|�d�|�tt|�dS)Nc@�eZdZdZdS)z7BytesTest.test_bytes_blocking.<locals>.IterationBlockedNr�rrrr�IterationBlockedw�r�)rr6rErVsc@r�)z1BytesTest.test_bytes_blocking.<locals>.IntBlockedNr�rrrr�
IntBlocked�r�r�rVsc@r�)z;BytesTest.test_bytes_blocking.<locals>.BytesSubclassBlockedNr�rrrr�BytesSubclassBlocked�r�r�r�c@r�)z4BytesTest.test_bytes_blocking.<locals>.BufferBlockedNr�rrrr�
BufferBlocked�r�r�)r]r$rprGrxr�r�)rr�rQr�r�r��ba�bbrrr�test_bytes_blockingvszBytesTest.test_bytes_blockingcCsPd}d}|�t|�t|��|�t|�t|��|�t|�t|d��|�t|�t|d��|�t|�t|d��|�t|�td|��|�t|�t|d��Gdd�dt�}|d	�}|�t|�t|��|�t|�t|d��|�t|�t|d��|�t|�t|d��|�t|�td|��|�t|�t|d��dS)
Ns123abc1@s456zyx-+rrr6rEc@r�)z5BytesTest.test_repeat_id_preserving.<locals>.SubBytesNr�rrrr�SubBytes�r�r�sqwerty())r$�id�assertNotEqualrp)rr/r(r�r�rrr�test_repeat_id_preserving�s"z#BytesTest.test_repeat_id_preservingN)rr r!rpr#r�r�r�r�r�r�rrrrr��s!rr�c@s2eZdZeZdd�Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"e#j$j%d=d>��Z&d?d@�Z'e#j(j)j*Z*dAdB�Z+dCdD�Z,dES)F�
ByteArrayTestcCsFtd�}d}|�t|��
|dWd�dS1swYdS)Nr��,bytearray indices must be integers or slicesr/�r�r;rxr�rrrr���

"�z ByteArrayTest.test_getitem_errorcCsFtd�}d}|�t|��
d|d<Wd�dS1swYdS)Nr�r�Zpythonr/r�r�rrr�test_setitem_error�r�z ByteArrayTest.test_setitem_errorcCs|�ttt��dSr)rGrx�hashr�rrrr�test_nohash��zByteArrayTest.test_nohashcCsnd}|ddt|�}t��}z�t|d��
}|�|�Wd�n1s&wYt|d��}td�}|�|�}Wd�n1sDwY|�|t|��|�t|�t|��t|d��
}|�|�Wd�n1spwYt|d��}|�|�	�|�Wd�n1s�wYWzt
�|�WdSty�YdSwzt
�|�Wwty�Yww)NsHello world
r|��wbr�)
rF�tempfile�mktempr��writer�r�r$r]�readr��remove�OSError)rZshort_sampler�Ztfnr�r(�nrrr�test_bytearray_api�s<��������z ByteArrayTest.test_bytearray_apicCs\td�}|�|��d�|�|d�td�}|��|�|d�t�}|��|�|�dS)Nr/sollehshello1s1olleh)r�r$r�r�r'rrr�test_reverse�szByteArrayTest.test_reversecCsttd�}|��|�|d�td�}|��|�|d�td�}|�td��|��|�td��|�|d�dS)Nr�r{�rr,r))r�rgr$rmr�r'rrr�
test_clear�szByteArrayTest.test_clearcCs�td�}|��}|�|d�td�}|��}|�|d�td�}|��}|�||�|�||�|�td��|�|d�|�|d�dS)Nr�r{rur+)r�r,r$�assertIsNotrmr�)rr(r�rrrr0�szByteArrayTest.test_copycCs4dd�}|d�}|�t�d|�|d�|d�g�dS)NcSsttt|��Sr)r�r�r�r�rrrr��z&ByteArrayTest.test_regexps.<locals>.byr�s\w+r�r�)r$�re�findallr�rrr�test_regexpss$zByteArrayTest.test_regexpscCs>tgd��}d|d<|�|tgd���d|d<|�|tgd���td�|d	<|�|tgd
���zd	|d<|�d�Wn	tyFYnwzd	|d
<|�d�Wn	ty[Ynwzd|d	<|�d�Wn	typYnwz
td�|d	<|�d�Wn	ty�Ynwzd|d	<|�d�WdSty�YdSw)NrUr>r6)r6r>rVr�rA)r6r>r�r=r)r=r>r�rVzDidn't raise IndexErrori����rJzDidn't raise ValueErrorzDidn't raise TypeError)r�r$r�failrHrurxr'rrr�test_setitem	sJ�����zByteArrayTest.test_setitemcCsbttd��}|d=|�|ttdd���|d=|�|ttdd���|d=|�|tgd���dS)Nr=rr6rAr*r�)r6rErVr�rr�r)r�r\r$r'rrr�test_delitem+szByteArrayTest.test_delitemc	Csttd��}|�t|�ttd���tgd��|dd�<|�|tgd���|dd�=|�|tgd���tgd��|dd�<|�|ttd���td	d
g�|dd�<|�|tgd
���gd�|dd�<|�|ttd���gd�|dd�<|�|tgd���d|dd�<|�|tgd���td�|dd�<|�|tgd���g|dd�<|�|tgd���dddtd�ddddgddgggf	D]}|�t��||dd�<Wd�n1s�wYq�gd�dd gfD]}|�t��||dd�<Wd�n	1�swYq�dS)!Nr=)r6r6r6r6r6rr})
r6r6r6r6r6r}rr�rr*r�)r}rr�rr*)rr6rErVr�r>�er�r�)rr6rEr>rr�rr*)rVr�r}rrV)rKrKrK)
rr6rErKrKrKrVr�r}rr�rr*sfoo)rr6rE�f�or)rrrrrrr�)rrrrrgP����KDr�gffffff@r/r(r�r�)rrrsrJi���i(#)	r�r\r$r]rr�rGrxru)rr(�elemrrr�
test_setslice4sB
������zByteArrayTest.test_setslicecCsvttd��}|�t|�ttd���|dd�=|�t|�ttdd���|�tdd��|�t|�ttdd���dS)Nr>r=�n)r�r\r$r]�extendr'rrr�test_setslice_extend\s
z"ByteArrayTest.test_setslice_extendcCs,td�}|��|dd�=|td�7}~dS)Nr=r6rE)r��poprpr'rrr�test_fifo_overrunes

zByteArrayTest.test_fifo_overruncCs2td�}t�|�}|dd�=|�t�|�|�dS)Nr=r6)r�r8�	getsizeof�assertLessEqual)rr(r�rrr�test_del_expandns

zByteArrayTest.test_del_expandcCs�dddddddd>tjddd	d
f}|D]O}|D]J}|dd�D]A}ttd��}t|�}||||�}|��|||||�<|||||�<|�|t|��||||�=||||�=|�|t|��qqqdS)Nrr6rVr�r�iMrArBr�i���rs)r8r9r]r\r�r�r$)rr�r�r�r�r�r(r�rrr�test_extended_set_del_sliceus&����z)ByteArrayTest.test_extended_set_del_slicecCs@ttd��}||dd�<|�|tttd��ttd����dS)NrJr)r�r\r$r]r'rrr�test_setslice_trap�s(z ByteArrayTest.test_setslice_trapcCs|td�}|}|d7}|�|d�|�||�|�||�|d7}|�|d�z|d7}Wn
ty6YdSw|�d�dS)Nr�r�r�r�s	abcdefxyzrz'bytes += unicode didn't raise TypeError)r�r$rHrxr�rr(r�rrr�test_iconcat�s�zByteArrayTest.test_iconcatcC�<td�}|}|d9}|�|d�|�||�|�||�dS)Nr�rVr��r�r$rHrrrr�test_irepeat��zByteArrayTest.test_irepeatcCr)Nr�r>sdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrrrrr�test_irepeat_1char�rz ByteArrayTest.test_irepeat_1charcCsdt�}|��}|�|d�|g}td�D]}|d7}|��}|�|t|��||vr/|�|�qdS)Nrr>r�)r��	__alloc__ZassertGreaterEqualr\�
assertGreaterrFrm)rr(�allocr rQrrr�
test_alloc�s
��zByteArrayTest.test_alloccsft����fdd�}��|����t��ttdd�����t��d����}��|t���dS)Nc	3s~�tdd�D]6}|Vt��}��|ttdt|�d�����t��t|����t��|����}��|t���qdS)Nr6r>)r\r]r$rFrrr)rQr/r�r(rrr�g�s��z(ByteArrayTest.test_init_alloc.<locals>.gr6r>�c)r�rr$r]r\rFrr)rrrrrr�test_init_alloc�s	zByteArrayTest.test_init_alloccCs�d}t|�}|�|�|�|||�|�|dd�|�td�}|�tt|d��|�dd�|dD��|�||d�|�|dd�|�td�}|�ttt|d���|�||d�|�|dd�|�td�}|�ttt|d���|�||d�|�|dd�|�td�}|�t|jgd	��|�t|jgd
��|�t	|�d�td�}|�t
td��g�|�|d
�dS)Nr/r}r{�css�|]}t|�VqdSr)r�rrrrrR�rz,ByteArrayTest.test_extend.<locals>.<genexpr>�2r�)rr6rErJ)rr6rErArr/r�)r�r	r$r�r�r`r]rGrurFrr�)rrIr/rrr�test_extend�s2
zByteArrayTest.test_extendcstd����td��|��d���td��|��d�|�t�fdd��|�t�fdd��|�t�fdd����td	����td
��|��d�|�t�fdd����ttd
���|��d�tgd��}|�d�|�|tgd���|�d�|�|tddg��dS)Nr/r�shelosheocs��td��S)Nr�)r�r�rr2rrr3�r;z+ByteArrayTest.test_remove.<locals>.<lambda>c�
��d�S)Ni��r�rr2rrr3�r:cr$)Nr�r%rr2rrr3�r:r�r�r�cr$)Nr�r%rr2rrr3�r:r�r{)�~r�rS�r�)r&rSr'r'r&rS)	r�r�r�r$rGrurxrrpr�rr2r�test_remove�s&

zByteArrayTest.test_removecs�td��|����td��|���d�td��|���d�td��|�t�fdd��|�td	d��|�td
���d�dS)NrErurr-rBr�cr$)Nr=)rrr2rrr3r:z(ByteArrayTest.test_pop.<locals>.<lambda>cS�
t���Sr)r�rrrrrr3r:rrs)r�r$rr�rGrHrrr2r�test_popszByteArrayTest.test_popcCs|�tdd��dS)NcSr)r)r��sortrrrrr3
r:z+ByteArrayTest.test_nosort.<locals>.<lambda>)rG�AttributeErrorrrrr�test_nosortr�zByteArrayTest.test_nosortcs�td����td��|��d�|���d�d�t����td��|�t��d�|�t�fdd��t����ttd���|��d	�dS)
Nshellr�r/r>r�r6cr$)Nr6)rmrr2rrr3r:z+ByteArrayTest.test_append.<locals>.<lambda>�A)r�rmr�r$rFrGrxrrrr2r�test_appendszByteArrayTest.test_appendcs�td����dtd����dtd����dtd����dtd��|��d�|�t�fdd	��t����d
ttd���|��d�dS)
Nsmssssppr6rQr�rBrlr"cs��dd�S)Nr�1)�insertrr2rrr3#r?z+ByteArrayTest.test_insert.<locals>.<lambda>rr�r.)r�r1r�r$rGrxrrrr2r�test_insertszByteArrayTest.test_insertcCsRtd�}|�||�ddd��tdd�td�D��}td�}|�||�|��dS)Nr�scdercSsg|]}|�qSrrrOrrrr�.rDz-ByteArrayTest.test_copied.<locals>.<listcomp>rJr{)r�r�rQr\r�)rr(�tr�rrr�test_copied(s
zByteArrayTest.test_copiedcCs�td��d�\}}}|�|d�|�|d�|�||�|d7}|�|d�td��d�\}}}|�|d�|�|d�td��d�\}}}|�|d�|�|d�|�||�|d7}|�|d�td��d�\}}}|�|d�|�|d�dS)Nr��yr{�!)r�rdr$r�rf)rr/r(r�rrr�0test_partition_bytearray_doesnt_share_nullstring2s$z>ByteArrayTest.test_partition_bytearray_doesnt_share_nullstringcs
ttd���t��}�fdd�}|d��dd�}|�t|d�|��|�|�t|d�|��|�|�t|d�|��|�|�t�jd�|��|�|�t�j�d�|��|��fdd	�}|�t|�|��|��fd
d�}|�t|�|��|�dS)Nr=cs"t|dd|d��dd�<dS)Nr6rErA)r\)r�r2rr�resizeNs"z3ByteArrayTest.test_resize_forbidden.<locals>.resize�r*rr6cs
�d=dSr5rrr2rr�delitem]rz4ByteArrayTest.test_resize_forbidden.<locals>.delitemcsd�ddd�<dS)Nr{r6rArErrr2rr�delslicebsz5ByteArrayTest.test_resize_forbidden.<locals>.delslice)r�r\rrG�BufferErrorr$rr�)r�vr8rIr:r;rr2r�test_resize_forbiddenGs*z#ByteArrayTest.test_resize_forbiddencCs ddlm}|�t|t��dS)Nr)�getbuffer_with_null_view)r�r?rGr<r�)rr?rrr�test_obsolete_write_lockgsz&ByteArrayTest.test_obsolete_write_lockc	Cs�td�}td�}ttjd�D]�}t|�}t�||f|�}t�|�\}}||dd�<|�t	|�t	|��|�t|�|�t
|�t�||f|�}t�|�\}}||dd�<|�t	|�t	|��|�t|�|dd��tdt|��D]}t
|�qrt�||f|�}t�|�\}}||dd�<|�t	|�t	|��|�t|�|t|�d��|�t
t
|�t�||f|�}t�|�\}}||dd�<|�t|�g�qdS)Nr�sqwertyr6)r�r]r\rlrmr`rnror$r%rsrFrG�
StopIteration)	rrIr�rpZitorigrurtr(rQrrr�test_iterator_pickling2ls8
�z%ByteArrayTest.test_iterator_pickling2cCs4td�}t|�}t|�|��|�t|�g�dS)Nr�)r�r`rsrgr$r])rr�rtrrr�test_iterator_length_hint�s
z'ByteArrayTest.test_iterator_length_hintcCsLtd�}d|dd�<|d}|d}|�|d�|�||�|�|d�dS)Nr�r�rEr6rVsxcsxcxcxc�r�r$)rr(r�r�rrr�test_repeat_after_setslice�sz(ByteArrayTest.test_repeat_after_setsliceN)-rr r!r�r#r�r�r�r�r�r�r0r�rrrr
rrrrrrrrr r#r(r*r-r/r2r4r7r>r�r�Zcpython_onlyr@rBZ
list_testsZ
CommonTestZtest_exhausted_iteratorrCrErrrrr��sL"	(		


 

$	r�c@s�eZdZedd��Zedd��Zdd�Zejj	dd��Z
d	d
�Zedd��Zd
d�Z
dd�Zdd�Zdd�Ze�ejjd�dd��ZdS)�AssortedBytesTestcCs�ttfD]:}|�|t��d�|�|tdg��d�|�|tgd���d�|�|d�d�|�|d�d	�|�|d
�d�qdS)N�bytearray(b'')rzbytearray(b'\x00')rtzbytearray(b'\x00\x01\xfe\xff')r�zb'abc'�'zb"'"s'"zb'\'"')r��reprr$r�r�rrr�
test_repr_str�s��zAssortedBytesTest.test_repr_strc	Cs�dtd�fD]:}|�t|�t|��|�t|d�t|��|�tdt�t|�j	���
t|d�Wd�n1s;wYqdS)Nr�rz\b%s\br�)
r�r$r�r�r;rxr��escaper%rr'rrr�test_format�s����zAssortedBytesTest.test_formatcCs�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�dtd�kd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�|�td�dkd�dS)Nr�Tr�Frorrrr�test_compare_bytes_to_bytearray�s0z1AssortedBytesTest.test_compare_bytes_to_bytearraycCsH|�tj�|�tj�d�tj�|�tj�|�tj�d�tj�dS)Nz
bytearray(zbytes()ZassertIsNotNoner��__doc__r�r2rprrrr�test_doc�szAssortedBytesTest.test_doccCs,td�}t|�}t|�}|�|t|��dS)NsHello world
����)rprr�r$)rr��bufr(rrr�test_from_bytearray�sz%AssortedBytesTest.test_from_bytearraycCsp|�td�d�|�td�d�|�td�d�|�ttd��d�|�ttd��d�|�ttd��d	�dS)
Nr{zb''r�zb'x'rzb'\x80'rGzbytearray(b'x')zbytearray(b'\x80'))r$r�r�rrrr�test_to_str�szAssortedBytesTest.test_to_strcCsRgd�}|D]
\}}|�|t|d��qtdd�D]
}|�ttdt|��qdS)N))sWonderful spamzWonderful spam)sWonderful spam toozWonderful spam too)s��uª€)s\xaa\x00\000\200z\xaa\x00\000\200r�rSrJzb"%s")r$r�r\rG�SyntaxError�evalr)rZtestsr(r�r�rrr�test_literal�s
��zAssortedBytesTest.test_literalcC�|�d�td��ddg�dS�NrSrr�r�)r$rZrrrrr�test_split_bytearray��z&AssortedBytesTest.test_split_bytearraycCrVrW)r$r[rrrrr�test_rsplit_bytearrayrYz'AssortedBytesTest.test_rsplit_bytearraycCst�}|�|�dd�|�dS)Nr{)r�r�rQr'rrr�test_return_selfsz"AssortedBytesTest.test_return_selfz4BytesWarning is needed for this test: use -bb optioncCsJdd�}|��ddkWd�n1swY|��ddkWd�n1s-wY|��ddkWd�n1sDwY|��ddkWd�n1s[wY|��td�dkWd�n1stwY|��dtd�kWd�n1s�wY|��td�dkWd�n1s�wY|��dtd�kWd�n1s�wY|��ddkWd�n1s�wY|��ddkWd�n1s�wY|��ddkWd�n	1�swY|��
ddkWd�dS1�swYdS)NcSst�dtf�Srr	rrrr�
bytes_warning
r�z5AssortedBytesTest.test_compare.<locals>.bytes_warningr{rr|r�r�)rr\rrrr�
sJ
�
�
�
�����
�
�
�
$�zAssortedBytesTest.test_compareN)rr r!rrJrLrMr�r�Zrequires_docstringsrOrQrRrUrXrZr[�unittestZ
skipUnlessr8�flagsr\r�rrrrrF�s&






�rFc@r�)�BytearrayPEP3137TestcCst|�Srr])rr�rrr�marshal8rXzBytearrayPEP3137Test.marshalcCs�|�d�}dD]}t||�}|d�}|�||�|�|||d�qdD]}t|�}|�||�|�|||d�q$|�d�}|�|g�}|�||�|�||�dS)Ns1234)�zfillr�r�r�rVz" returned self on a mutable object)zval.split()[0]zval.rsplit()[0]zval.partition(b".")[0]zval.rpartition(b".")[2]zval.splitlines()[0]zval.replace(b"", b"")z! returned val on a mutable objectr{)ra�getattrr$r�rTr)r�valZmethnamer�Znewval�expr�seprrr�test_returns_new_copy;s$

��
z*BytearrayPEP3137Test.test_returns_new_copyN)rr r!rargrrrrr`7sr`cs eZdZ�fdd�ZdZ�ZS)�FixedStringTestcs&t|t�r
|�|�d��St��|�S)Nr�)�
isinstancer�r#r��super�fixtype)rr��r&rrrkSs
zFixedStringTest.fixtypeT)rr r!rkZcontains_bytes�
__classcell__rrrlrrhRsrhc@�eZdZeZdS)�ByteArrayAsStringTestN)rr r!r�r#rrrrroZr�roc@rn)�BytesAsStringTestN)rr r!rpr#rrrrrp]r�rpc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SubclassTestcCs�|�t|j|j��|�|��|j�d\}}|�|�|�|�}}|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||�|�||||�|�||||�|�||||�|�|d|dk�dS)N)r+�efghr})r��
issubclassr#�basetyper�r�r$)rr/r(Z_aZ_brrr�
test_basiccszSubclassTest.test_basiccCs`|�d�}|���|g�}|�||�|�t|�|jt|��|�dg�}|�t|�|j�dSr*)r#rtrr�rHr%)r�s1�s2Zs3rrrr!{s
zSubclassTest.test_joincCs�|�d�}d|_|�d�|_ttjd�D]A}t�t�||��}|�t	|�t	|��|�
||�|�
|j|j�|�
|j|j�|�
t|�t|��|�
t|j�t|j��qdS)Nr+r=rrr6)r#r��yr\rlrmrornr�r�r$r%)rr/rpr(rrr�test_pickle�s
�zSubclassTest.test_picklecCs�|�d�}d|_|�d�|_tjtjfD]<}||�}|�t|�t|��|�||�|�|j|j�|�|j|j�|�t|�t|��|�t|j�t|j��qdS)Nr+r=rr)	r#r�rxr,r-r�r�r$r%r.rrrr0�s
�zSubclassTest.test_copycs��j�d�}��|d���t|��j�G�fdd�d�j�}|�d�}��|d���t|�|���|jd�G�fdd�d�j�}|�d�}��|d���t|�|���|jd�dS)Nr�rcre)z%SubclassTest.test_fromhex.<locals>.B1cs�j�||�}d|_|S�N�bar)rt�__new__�foo)�clsr�merrrr|�sz-SubclassTest.test_fromhex.<locals>.B1.__new__N)rr r!r|rrrr�B1�rkr�r{cre)z%SubclassTest.test_fromhex.<locals>.B2cs.�jtur�jj|g|�Ri|��d|_dSrz)rtrprr})rr�kwargsrrrr�s

z.SubclassTest.test_fromhex.<locals>.B2.__init__N�rr r!rrrrr�B2�rkr�)r#r�r$rHr%rtr})rr(r�r�rrrr��s

zSubclassTest.test_fromhexN)rr r!rur!ryr0r�rrrrrqas


rqc@r�)�ByteArraySubclassNr�rrrrr��r�r�c@r�)r�Nr�rrrrr��r�r�c@r�)r�Nr�rrrrr��r�r�c@seZdZeZeZdd�ZdS)�ByteArraySubclassTestcCsNGdd�dt�}|dd�}|ddd�}|�|d�|ddd�}|�|d�dS)Nc@seZdZddd�ZdS)z:ByteArraySubclassTest.test_init_override.<locals>.subclassr6c_stj|g|�Ri|��dSr)r�r)r�newargrr�rrrr�rVzCByteArraySubclassTest.test_init_override.<locals>.subclass.__init__Nr�r�rrrr�subclass�sr�r�r+)�source)r�r�rD)rr�r�rrr�test_init_override�s
z(ByteArraySubclassTest.test_init_overrideN)rr r!r�rtr�r#r�rrrrr��sr�c@seZdZeZeZdS)�BytesSubclassTestN)rr r!rprtr�r#rrrrr��sr��__main__).rNryr�r�r8r,rrlr�r�r^Ztest.supportr�rrZtest.string_testsZtest.list_testsrrZtest.support.script_helperrr_r\rrr"ZTestCaser�r�rFr`Zstring_testsZBaseTestrhrorprqr�r�rpr�r�r�r�r�mainrrrr�<module>sf
-W~]�
© 2025 GrazzMean