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_bytes.cpython-37.pyc
B

��g�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
Zddl
mZmZejjr�dd�Zndd�ZGdd�d�ZGd	d
�d
�ZGdd�dee	j�ZGd
d�dee	j�ZGdd�de	j�ZGdd�de	j�ZGdd�dejj�ZGdd�dee	j�ZGdd�dee	j�ZGdd�d�ZGdd�de �Z!Gdd�de"�Z#Gdd �d e"�Z$Gd!d"�d"ee	j�Z%Gd#d$�d$ee	j�Z&e'd%k�r�e	�(�dS)&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)�bigaddrspacetest�MAX_Py_ssize_tcst����fdd��}|S)Nc	s&tj�dtf���||�SQRXdS)N�)�test�support�check_warnings�BytesWarning)�args�kw)�func��+/usr/local/lib/python3.7/test/test_bytes.py�wrappersz%check_bytes_warnings.<locals>.wrapper)�	functools�wraps)rrr)rr
�check_bytes_warningssrcCs|S)Nr)rrrr
r sc@seZdZddd�Zdd�ZdS)�	IndexablercCs
||_dS)N)�value)�selfrrrr
�__init__%szIndexable.__init__cCs|jS)N)r)rrrr
�	__index__'szIndexable.__index__N)r)�__name__�
__module__�__qualname__rrrrrr
r$s
rc@seZdZdd�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�S)��
BaseBytesTestcCs.|��}|�t|�|j�|�|j|j�dS)N)�	type2test�assertEqual�type�	__class__)r�brrr
�test_basics-szBaseBytesTest.test_basicscCsL|�d�}x<tjtjfD],}||�}|�||�|�t|�t|��qWdS)Nsabcd)r�copy�deepcopyrr)r�a�copy_methodrrrr
�	test_copy2s

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)Nrcs�dS)Nrrr)rrr
�<lambda><�z3BaseBytesTest.test_empty_sequence.<locals>.<lambda>cs�dS)N�rr)rrr
r&=r'cs
�tjS)N)�sys�maxsizer)rrr
r&>r'cs�tjdS)Nr()r)r*r)rrr
r&?r'cs�ddS)N�
�drr)rrr
r&@r'cs�dS)N���rr)rrr
r&Ar'cs�dS)N���rr)rrr
r&Br'cs�tjS)N)r)r*r)rrr
r&Cr'cs�tjdS)Nr()r)r*r)rrr
r&Dr'cs�tjdS)N�)r)r*r)rrr
r&Er'cs�ddS)Nr+r,rr)rrr
r&Fr')rr�len�assertRaises�
IndexError)rr)rr
�test_empty_sequence9sz!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��*�*�+�-)r7r8)r8r7css|]}|dr|VqdS)r/Nr)�.0�irrr
�	<genexpr>Ysz3BaseBytesTest.test_from_iterable.<locals>.<genexpr>�r(r/c@seZdZdd�ZdS)z+BaseBytesTest.test_from_iterable.<locals>.ScSsd|S)N)r(r/�r)rr:rrr
�__getitem___sz7BaseBytesTest.test_from_iterable.<locals>.S.__getitem__N)rrrr>rrrr
�S^sr?s)r�rangerr0�list�assertIn�tuple�iter)rrr?rrr
�test_from_iterableHs "z BaseBytesTest.test_from_iterablecCsT|�ttd���}|�t|�d�|�t|�ttd���|�d�}|�|d�dS)Nr4)r(r/r=s)rrCr@rr0rA)rrrrr
�test_from_tupleds

zBaseBytesTest.test_from_tuplecCsZ|�ttd���}|�t|�d�|�t|�ttd���|�dddg�}|�|d�dS)Nr4r(r/r=s)rrAr@rr0)rrrrr
�test_from_listls
zBaseBytesTest.test_from_listcs\G�fdd�d�}|�|�g�|�t��d�G�fdd�d�}|�g�|�t��d�dS)NcseZdZ�fdd�ZdS)z0BaseBytesTest.test_from_mutating_list.<locals>.Xcs���dS)Nr5)�clear)r)r#rr
rwsz:BaseBytesTest.test_from_mutating_list.<locals>.X.__index__N)rrrrr)r#rr
�XvsrIr6cseZdZ�fdd�ZdS)z0BaseBytesTest.test_from_mutating_list.<locals>.Ycst��dkr��|�dS)Ni�r5)r0�append)r)r#rr
r~s
z:BaseBytesTest.test_from_mutating_list.<locals>.Y.__index__N)rrrrr)r#rr
�Y}srKs�****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************)r�bytes)rrIrKr)r#r
�test_from_mutating_listtsz%BaseBytesTest.test_from_mutating_listcCsh|�t�td�td�td�g�}|�t|�ddddg�|�t|jtd�g�|�t|jtd�g�dS)Nr(��rr-r4)rrrrAr1�
ValueError)rrrrr
�test_from_index�s
zBaseBytesTest.test_from_indexcCsd|�t�ddddg��}|�|d�|�d�}|�|d�Gdd�dt�}|�|�|d��d�dS)N�Br(r/r=sc@seZdZdd�ZdS)z)BaseBytesTest.test_from_buffer.<locals>.BcSst�dS)N)�	TypeError)rrrr
r�sz3BaseBytesTest.test_from_buffer.<locals>.B.__index__N)rrrrrrrr
rR�ssfoobar)r�arrayrrL)rr#rRrrr
�test_from_buffer�s
zBaseBytesTest.test_from_buffercCs�|�|�d�d�|�|�d�d�|�|�d�d�|�t|jd�|�|�dd	�d
�|�|�d
�d
�|�t|jtjd�dS)Nrr'r(��sr-�0�ascii�0)rrr1rP�
OverflowErrorr)r*)rrrr
�test_from_ssize�szBaseBytesTest.test_from_ssizecCs|�t|jd�Gdd�d�}|�t|jdg�|�t|jdg�|�t|jdg�|�t|j|�g�|�t|jdd�|�t|jdd�|jt|jddd	�|jt|jddd	�|�t|jd
�|jt|jd
dd	�|�t|jd
d�|�t|jd
dd�dS)
Ngc@seZdZdS)z5BaseBytesTest.test_constructor_type_errors.<locals>.CN)rrrrrrr
�C�sr]rXrrYr'�ignore)�errorsrsasciisignore)r1rSr)rr]rrr
�test_constructor_type_errors�sz*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)Nr-r(r/r+r,r4i)r1rPrr)r*)rrrr
�test_constructor_value_errors�sz+BaseBytesTest.test_constructor_value_errorsc	CsFt}|�ttf|j|�yt|d�Wnttfk
r@YnXdS)N�)rr1r[�MemoryErrorr�	bytearray)r�sizerrr
�test_constructor_overflow�sz'BaseBytesTest.test_constructor_overflowcCsXGdd�d�}|�t|j|��|�t|j|�g�Gdd�d�}|�t|j|��dS)Nc@seZdZdd�ZdS)z9BaseBytesTest.test_constructor_exceptions.<locals>.BadIntcSsdddS)Nr(rr)rrrr
r�szCBaseBytesTest.test_constructor_exceptions.<locals>.BadInt.__index__N)rrrrrrrr
�BadInt�srgc@seZdZdd�ZdS)z>BaseBytesTest.test_constructor_exceptions.<locals>.BadIterablecSsdddS)Nr(rr)rrrr
�__iter__�szGBaseBytesTest.test_constructor_exceptions.<locals>.BadIterable.__iter__N)rrrrhrrrr
�BadIterable�sri)r1�ZeroDivisionErrorr)rrgrirrr
�test_constructor_exceptions�s
z)BaseBytesTest.test_constructor_exceptionscCs|�dddg�}|�dddg�}|�ddg�}|�||�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�dS)Nr(r/r=)rr�
assertTrue�assertFalse)r�b1�b2Zb3rrr
�test_compare�s&zBaseBytesTest.test_comparecCs�|�|�d�dkd�|�|�d�dkd�|�|�d�dkd�|�|�d�dkd�|�|��t�kd�|�|��t�kd�dS)Nsabc�abcFsabcsabcsabcT)rr�str)rrrr
�test_compare_to_str�sz!BaseBytesTest.test_compare_to_strcCs<tttd��}|�|�}tt|��}|��|�||�dS)N�Hello)rA�map�ordr�reversed�reverser)r�inputr�outputrrr
�
test_reversed�s

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|��S)N)rrurv)�s)rrr
�bysz'BaseBytesTest.test_getslice.<locals>.byzHello, worldrWrtr(Zello�z, �world�r,i����i�������i����)r)rr}rr)rr
�
test_getsliceszBaseBytesTest.test_getslicecCs�ttd��}|�|�}ddddddtjddd	d
f}xV|D]N}xH|D]@}x:|dd�D]*}|�||||�|�||||���qTWqBWq8WdS)NrOrr(r=�r,r-r.i��i����)rAr@rr)r*r)r�Lr�indices�start�stop�steprrr
�test_extended_getslices


z$BaseBytesTest.test_extended_getslicec	Csvd}x0dD](}|�||�}|�||�|�|���q
W|�t|j|d�|�|dd�}|�||�|dd�d��dS)NuHello world
ሴ噸骼)zutf-8zutf-16zlatin-1r^���zutf-8)rr�encoder1�UnicodeEncodeError)r�sample�encrrrr
�
test_encoding%s
zBaseBytesTest.test_encodingcCs�d}x*dD]"}|�||�}|�|�|�|�q
Wd}|�|d�}|�t|jd�|�|�dd�d�|�|jddd�d�|�|�d	���d
�dS)NuHello world
ሴ噸骼)zutf-8zutf-16uHello world
€þÿzlatin-1zutf-8r^zHello world
)r_�encodings☃u☃)rr�decoder1�UnicodeDecodeError)rr�r�rrrr
�test_decode.s
zBaseBytesTest.test_decodecCsb|�d�}|�||���|�d�}|�||�dgd��|�d�}|�||�dgd��dS)Nrr+i')rr)rrrrr
�
test_from_int<s


zBaseBytesTest.test_from_intcsx|�d��|�d��|���d�|��td�d�|�td��d�|�t�fdd��|�t�fdd��dS)Nsabcsdefsabcdefsdefabccs�dS)N�defrr)rnrr
r&Jr'z+BaseBytesTest.test_concat.<locals>.<lambda>csd�S)Nrqrr)rorr
r&Kr')rrrLr1rS)rr)rnror
�test_concatDs

zBaseBytesTest.test_concatc
s�x�d|�d�fD]��|��dd�|��dd�|��dd�|�t�fdd��|�t�fd	d��|�ttf���tj}WdQRX|�ttf���tj9�WdQRXqWdS)
Nsabcr=s	abcabcabcrr'r-cs�dS)Ng��Q�	@rr)rrr
r&Rr'z+BaseBytesTest.test_repeat.<locals>.<lambda>csd�S)Ng��Q�	@rr)rrr
r&Sr')rrr1rSr[rcr)r*)r�cr)rr
�test_repeatMszBaseBytesTest.test_repeatcCs*|�|�d�d|�td�gd��dS)N�xr,�x)rrrv)rrrr
�test_repeat_1charZszBaseBytesTest.test_repeat_1charcsx|�d��|�td���|�ttd����|�d��|�t�fdd��|�t�fdd��|�t�fdd��|�t�fdd��|�t�fd	d��|�t�fd
d��x�tt	fD]�}|�|d���|�|d���|�|d
���|�|d���|�|d���|�|d���|�|d���|�|d���|�|d���|�|d���|�|d���q�WdS)Nsabcr#��csd�kS)Ni,rr)rrr
r&br'z-BaseBytesTest.test_contains.<locals>.<lambda>csd�kS)Nr-rr)rrr
r&cr'cstjd�kS)Nr()r)r*r)rrr
r&dr'csd�kS)Nrr)rrr
r&er'csttd���kS)Nr#)�floatrvr)rrr
r&fr'csd�kS)Nr#rr)rrr
r&gr'r'�a�b�csabsbcsac�dsdabsabd)
rrBrv�intZassertNotInr1rPrSrLrd)r�fr)rr
�
test_contains]s,
zBaseBytesTest.test_containsc
Cs�|�t|jj�|�t|jjd�|�|j�d�|���tdddg�}|�|j�d�|�|�|j�d�|�|�|j�d�|�x$d	D]}|�|j�|�|���q�Wxd
D]}|�t|jj|�q�W|�|j�d�d�|�t|jjd
�|�t|jjd�|�t|jjd�|�t|jjd�|�t|jjd�|�t|jjd�xJdD]B\}}|�t��}|j�|�WdQRX|�d|t|j	���qPWdS)Nr(r�r7�0�1a2B30z  1A 2B  30   z
 1A
2B	30z	

 u…   
Z0000ss1Br#Zrtz1a b cd�z12      34))z12 x4 56r=)z12 3x 56rb)z12 xy 56r=)u	12 3ÿ 56rbzat position %s)
r1rSr�fromhexrrdrPrBrr�	exception)rrr��data�pos�cmrrr
�test_fromhexus.

zBaseBytesTest.test_fromhexcCs�|�t|jj�|�t|jjd�|�|�d���d�|�tdddg���d�|�|�d���d�|�td���d�dS)	Nr(r'rr�r7r�Z1a2b30s+0)r1rSr�hexrrd�
memoryview)rrrr
�test_hex�szBaseBytesTest.test_hexc	Cs�|�|�d��g�d�|�|�d��dg�d�x�dgddgddgdddggD]d}tt|j|��}|�|�d��|�d�|�|�d��t|��d�|�|�d��t|��d�qPW|�d�j}|�|dd	g�d
�|�|td�d	g�d
�|�|dtd	�g�d
�|�|td�d	g�d
�|�|dtd	�g�d
�dgd}ddd
}|�||�|�|�	t
|�d�jd�|�	t
��|td�ddg�WdQRX|�	t
��|td�ddg�WdQRXdS)Nr'sabcr�sbcsabr�r�s.:scdsab.:cdi�s.:abci�� Zcdsef)rr�joinrArurCrDr�rdr1rS)rZlstZdot_join�seqZexpectedrrr
�	test_join�s*" 
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)Nsmississippi�i�p�w�irbsssr/�wr��pr(r=r~�	)rr�count)rrr:�p�wrrr
�
test_count�s"
zBaseBytesTest.test_countc	Cs�|�d�}|�|���d��|�|�d��|�|�d��|�|�d��|�|�d��|�|�d��|�t��}|�dg�WdQRXt|j�}|�d|�|�d|�dS)	Nshellosanythingshel�hshellowsharLrC)	rrm�
startswithrlr1rSrrr�rB)rrr��excrrr
�test_startswith�s

zBaseBytesTest.test_startswithc	Cs�|�d�}|�t��d��|�|�d��|�|�d��|�|�d��|�|�d��|�|�d��|�t��}|�dg�WdQRXt|j�}|�	d|�|�	d|�dS)	Nshellosanythingsllo�oswhellosnorLrC)
rrmrd�endswithrlr1rSrrr�rB)rrr�r�rrr
�
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�x*ddtjd	fD]}|�td|j|�q�WdS)Nsmississippir�r�sssr/r�r-s
mississippianr(r=rWr~r�r4zbyte must be in range\(0, 256\))rr�findr)r*�assertRaisesRegexrP)rrr:r��indexrrr
�	test_find�s$
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)Nsmississippir�r�sssrWr�r-s
mississippianr+r=rr�r/r(r�r~)rr�rfind)rrr:r�rrr
�
test_rfinds
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)
Nsmississippir�r�sssr/r�s
mississippianr(r=rWr~r�)rrr�r1rP)rrr:r�rrr
�
test_indexs
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)Nsmississippir�r�sssrWr�s
mississippianr+r=rr�r/r(r�r~)rr�rindexr1rP)rrr:r�rrr
�test_rindex/s
zBaseBytesTest.test_rindexcCs�|�d�}|}|d}|�|d�|�|d�|�||k�|�d�}|d}|�|d�|�t|�|j�|�d�}|d}|�|d�|�t|�|j�dS)	Ns
hello, %b!sworlds
hello, world!s%s / 100 = %d%%)sseventy-nine�Osseventy-nine / 100 = 79%s
hello,%b!s
hello,world!)rrrm�assertIsr)rr�origr#rrr
�test_modBs


zBaseBytesTest.test_modcCs�|�d�}|}|d;}|�|d�|�|d�|�||k�|�d�}|d;}|�|d�|�t|�|j�|�d�}|d;}|�|d�|�t|�|j�dS)	Ns
hello, %b!sworlds
hello, world!s%s / 100 = %d%%)sseventy-niner�sseventy-nine / 100 = 79%s
hello,%b!s
hello,world!)rrrmr�r)rrr�rrr
�	test_imodSs


zBaseBytesTest.test_imodc	CsB|�t��t�|�d�WdQRX|�|�d��d�t�dS)Nsabcz%r)r1rS�objectrr��__rmod__�NotImplemented)rrrr
�	test_rmoddszBaseBytesTest.test_rmodcCs6|�d�}|�|�dd�d�|�|�dd�d�dS)Nsmississippir�r�smassassappasssr�s	mixixippi)rr�replace)rrrrr
�test_replaceis
zBaseBytesTest.test_replacecCs|�t|�d�jdd�dS)Nsa b� r')r1rSrr�)rrrr
�test_replace_int_errornsz$BaseBytesTest.test_replace_int_errorcCs0|�t|�d�jd�|�t|�d�jd�dS)Nsa b� )r1rSr�split�rsplit)rrrr
�test_split_string_errorqsz%BaseBytesTest.test_split_string_errorcCs0|�t|�d�jd�|�t|�d�jd�dS)Nsa br�)r1rSrr�r�)rrrr
�test_split_int_errorusz"BaseBytesTest.test_split_int_errorcCsJx(dD] }|�|�}|�|��|g�qW|�d�}|�|��dg�dS)N)sabsabsabsabs		

s)rrr�)rrrrr
�test_split_unicodewhitespaceys



z*BaseBytesTest.test_split_unicodewhitespacecCs |�d�}|�|��dg�dS)Ns		

s)rrr�)rrrrr
�test_rsplit_unicodewhitespace�s
z+BaseBytesTest.test_rsplit_unicodewhitespacecCs2|�d�}|�|�d�d�|�|�d�d�dS)Nsmississippisss)smissssissippir�)smississippir'r')rr�	partition)rrrrr
�test_partition�s
zBaseBytesTest.test_partitioncCsD|�d�}|�|�d�d�|�|�d�d�|�|�d�d�dS)Nsmississippisss)smississssippir�)s
mississippr�r'r�)r'r'smississippi)rr�
rpartition)rrrrr
�test_rpartition�s
zBaseBytesTest.test_rpartitioncCs0|�t|�d�jd�|�t|�d�jd�dS)Nsa br�)r1rSrr�r�)rrrr
�test_partition_string_error�sz)BaseBytesTest.test_partition_string_errorcCs0|�t|�d�jd�|�t|�d�jd�dS)Nsa br�)r1rSrr�r�)rrrr
�test_partition_int_error�sz&BaseBytesTest.test_partition_int_errorcCsVxPttjd�D]>}x8dD]0}|�|�}t�||�}t�|�}|�||�qWqWdS)Nr()r'r�sabcs�ab�s�)r@�pickle�HIGHEST_PROTOCOLr�dumps�loadsr)r�protorZps�qrrr
�
test_pickling�s


zBaseBytesTest.test_picklingcCs�x�ttjd�D]�}x�dD]�}t|�|��}}t|�|��}t�||�}t�|�}|�t	|�t	|��|�t|�|�t�|�}|s�qt
|�t�||�}t�|�}|�t|�|dd��qWqWdS)Nr()r'r�sabcs�ab�s�)r@r�r�rDrrAr�r�rr�next)rr�r�itZitorgr��drrr
�test_iterator_pickling�s



z$BaseBytesTest.test_iterator_picklingcCsX|�|�d��td��d�|�|�d��td��d�|�|�d��td��d�dS)Nsabcsacr�sbcsab)rr�stripr��lstrip�rstrip)rrrr
�test_strip_bytearray�sz"BaseBytesTest.test_strip_bytearraycCsF|�t|�d�jd�|�t|�d�jd�|�t|�d�jd�dS)NsabcZac)r1rSrr�r�r�)rrrr
�test_strip_string_error�sz%BaseBytesTest.test_strip_string_errorcCsF|�t|�d�jd�|�t|�d�jd�|�t|�d�jd�dS)Ns abc r�)r1rSrr�r�r�)rrrr
�test_strip_int_error�sz"BaseBytesTest.test_strip_int_errorcCs>|�d�}x.ttfD]"}|�|�d|d��|�d��qWdS)Nsabcr~�-s--abc--)rrLrdr�center)rr�	fill_typerrr
�test_center�s
zBaseBytesTest.test_centercCs>|�d�}x.ttfD]"}|�|�d|d��|�d��qWdS)Nsabcr~r�sabc----)rrLrdr�ljust)rrr�rrr
�
test_ljust�s
zBaseBytesTest.test_ljustcCs>|�d�}x.ttfD]"}|�|�d|d��|�d��qWdS)Nsabcr~r�s----abc)rrLrdr�rjust)rrr�rrr
�
test_rjust�s
zBaseBytesTest.test_rjustcCsL|�t|�d�jdd�|�t|�d�jdd�|�t|�d�jdd�dS)Nsabcr~r�)r1rSrr�rr)rrrr
�test_xjust_int_error�sz"BaseBytesTest.test_xjust_int_errorcs:|�d��|��fdd�tt���D�dddddg�dS)	NsA��cs g|]}t�||d���qS)r()rv)r9r:)rrr
�
<listcomp>�sz*BaseBytesTest.test_ord.<locals>.<listcomp>r�A�r<rO)rrr@r0)rr)rr
�test_ord�s
zBaseBytesTest.test_ordcCs`d}|�|j�dd�|�d}|�|j�dd�|�|�t|jjdd�|�t|jjdd�dS)	Ns	

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`xyzdefghijklmnopqrstuvwxyz{|}~�����������������������������������������������������������������������������������������������������������������������������sabcsxyzs	

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������xyzs���sxyzqrqr�)rr�	maketransr1rPrS)rZ
transtablerrr
�test_maketrans�s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)
Nshello�lr�r�r�r/r=r.rr(TF)	rrr�r�r�r�r�r�r�)rr�l�hr��orrr
�test_none_arguments�sB




z!BaseBytesTest.test_none_argumentscCsZ|�d�}xJ|j|j|j|j|jfD].}|�t|d�|�t|d�|�t|d�q$WdS)Nshellor-r4i')rr�r�r�r�r�r1rP)rr�methodrrr
�(test_integer_arguments_out_of_byte_ranges

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)
Nshellor�z\bfind\bz	\brfind\bz	\bindex\bz
\brindex\bz	\bcount\bz\bstartswith\bz\bendswith\b)
rr�rSr�r�r�r�r�r�r�)rrr�rrr
�*test_find_etc_raise_correct_error_messagess 

z8BaseBytesTest.test_find_etc_raise_correct_error_messagescCs(tj�|t|j�tj�|t|j�dS)N)rrZcheck_free_after_iteratingrDrrw)rrrr
�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)
Nshellor4�errOr'shellershee�eshllo)�delete)rrdr@rvr1rS�	translaterPrLr�assertIsInstance)rrZrosettar�r�rrr
�test_translate1s.

zBaseBytesTest.test_translateN)Frrrr r%r3rErFrGrMrQrUr\r`rarrfrkrprrsr{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�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	rrrrrrrrrr
r+s�
		
%+rc@s8eZdZeZdd�Zdd�Zdd�Zdd�Zd	d
�Z	dS)�	BytesTestc	Cs(d}|�t|��ddWdQRXdS)Nz'byte indices must be integers or slicesspythonr#)r�rS)r�msgrrr
�test_getitem_errorTszBytesTest.test_getitem_errorc	Cs<t�ttj�}t|ddd��}|�t|jd�WdQRXdS)N�rbr)�	bufferingr')�os�open�__file__�O_RDONLYr1rS�readinto)r�fdr�rrr
�test_buffer_is_readonlyYsz!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@seZdZdd�ZdS)z BytesTest.test_custom.<locals>.AcSsdS)Nsabcr)rrrr
�	__bytes__`sz*BytesTest.test_custom.<locals>.A.__bytes__N)rrrr'rrrr
�A_sr(sabcc@seZdZdS)z BytesTest.test_custom.<locals>.AN)rrrrrrr
r(csc@seZdZdd�ZdS)z BytesTest.test_custom.<locals>.AcSsdS)Nr)rrrr
r'fsz*BytesTest.test_custom.<locals>.A.__bytes__N)rrrr'rrrr
r(esc@seZdZdd�Zdd�ZdS)z BytesTest.test_custom.<locals>.AcSsdS)Nr�r)rrrr
r'jsz*BytesTest.test_custom.<locals>.A.__bytes__cSsdS)Nr5r)rrrr
rlsz*BytesTest.test_custom.<locals>.A.__index__N)rrrr'rrrrr
r(isr�c@seZdZdd�ZdS)z BytesTest.test_custom.<locals>.AcSsdS)Nsabcr)rrrr
r'qsz*BytesTest.test_custom.<locals>.A.__bytes__N)rrrr'rrrr
r(psu€z
iso8859-15��c@seZdZdd�ZdS)z BytesTest.test_custom.<locals>.AcSstd�S)Nsabc)�OtherBytesSubclass)rrrr
r'wsz*BytesTest.test_custom.<locals>.A.__bytes__N)rrrr'rrrr
r(vs)	rrLr1rSrrr�rr*�
BytesSubclass)rr(rrr
�test_custom^s zBytesTest.test_customcsttj�d�}tj�d�}ddlm}m}ddlm}m}m}m	}m
}	m}
m}|j
}||_|�|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%k�r�d&�d|
���fd'd(�}nd)d(�}d*}|�|d+||��d,||��d-��|�|d.|d/��d0�|	d�j}x�d1||jtfd1||jtfd2||jtfd2||jtfd3||jtfd4|
|jtfd4|
|jtfd5|	|tfd6|||ff	D]0\}}}}|�||||��||��d-��f�qXW|�|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�ctypes�	_testcapir)�	pythonapi�	py_object)�c_int�c_uint�c_long�c_ulong�c_size_t�	c_ssize_t�c_char_psformats
Hello %s !sworlds
Hello world !sc=%csc=�@sc=@rOsc=�sd=%d ld=%ld zd=%zdr(r/r=s
d=1 ld=2 zd=3r-r.r�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�|S)Nr)�ptr)�
ptr_formatrr
�
ptr_formatter�sz1BytesTest.test_from_format.<locals>.ptr_formattercSsd|S)Nz%#xr)r;rrr
r=�si�ͫsptr=%pzptr=rYss=%sscstrss=cstrs%ds%lds%lus%zds%zus%ps%5sr�s%.3ssabcdefsabcs%%�%s[%%]s[%]s%%%c�_s%_s%%ss%ssx=%i y=%sx=2 y=%s%cr4r')!rr�
import_moduler-r/r0r1r2r3r4r5r6r7�PyBytes_FromFormatZrestyperrvZsizeofr �name�formatr�rZINT_MINrrZINT_MAXZLONG_MINZLONG_MAXZ	ULONG_MAXZPY_SSIZE_T_MINZPY_SSIZE_T_MAXr1r[)rr-r.r/r0r1r2r3r4r5r6r7rAZ
sizeof_ptrr=r;Zsize_maxZ	formatstrZctypes_typerZpy_formatterr)r<r
�test_from_formats�$







zBytesTest.test_from_formatcCs�Gdd�dt�}ddddg}|�t|�d�|�tt||��Gdd	�d	t�}|�td�d
�|�tt|d��Gdd�dt�}|�td
�d
�|�tt|d
��Gdd�dt�}td
�|d
�}}|�t|�d
�|�tt|�dS)Nc@seZdZdZdS)z7BytesTest.test_bytes_blocking.<locals>.IterationBlockedN)rrrr'rrrr
�IterationBlocked�srErr(r/r=sc@seZdZdZdS)z1BytesTest.test_bytes_blocking.<locals>.IntBlockedN)rrrr'rrrr
�
IntBlocked�srFsc@seZdZdZdS)z;BytesTest.test_bytes_blocking.<locals>.BytesSubclassBlockedN)rrrr'rrrr
�BytesSubclassBlockedsrGsabc@seZdZdZdS)z4BytesTest.test_bytes_blocking.<locals>.BufferBlockedN)rrrr'rrrr
�
BufferBlockedsrH)rArrLr1rSr�rd)rrEr:rFrGrH�ba�bbrrr
�test_bytes_blocking�szBytesTest.test_bytes_blockingN)
rrrrLrrr&r,rDrKrrrr
rQs!qrc@s*eZdZeZdd�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+dCS)D�
ByteArrayTestc	Cs,d}|�t|��td�dWdQRXdS)Nz,bytearray indices must be integers or slicesspythonr#)r�rSrd)rrrrr
rsz ByteArrayTest.test_getitem_errorc	Cs0d}|�t|��td�}d|d<WdQRXdS)Nz,bytearray indices must be integers or slicesspythonZpythonr#)r�rSrd)rrrrrr
�test_setitem_errorsz ByteArrayTest.test_setitem_errorcCs|�ttt��dS)N)r1rS�hashrd)rrrr
�test_nohashszByteArrayTest.test_nohashcCsd}|ddt|�}t��}z�t|d��}|�|�WdQRXt|d��}td�}|�|�}WdQRX|�|t|��|�t|�t|��t|d��}|�|�WdQRXt|d��}|�|�	�|�WdQRXWdyt
�|�Wntk
r�YnXXdS)NsHello world
rV��wbr)
r0�tempfileZmktempr!�writerdr$rrA�readr �remove�OSError)rZshort_sampler�Ztfnr�r�nrrr
�test_bytearray_api s&z ByteArrayTest.test_bytearray_apicCs\td�}|�|��d�|�|d�td�}|��|�|d�t�}|��|�|�dS)Nshellosollehshello1s1olleh)rdrrxrm)rrrrr
�test_reverse:szByteArrayTest.test_reversecCsttd�}|��|�|d�td�}|��|�|d�td�}|�td��|��|�td��|�|d�dS)Nspythonr'�rr�r�)rdrHrrJrv)rrrrr
�
test_clearEszByteArrayTest.test_clearcCs�td�}|��}|�|d�td�}|��}|�|d�td�}|��}|�||�|�||�|�td��|�|d�|�|d�dS)Nsabcr'r�sabcd)rdr!r�assertIsNotrJrv)rrrJrrr
r%TszByteArrayTest.test_copycCs4dd�}|d�}|�t�d|�|d�|d�g�dS)NcSsttt|��S)N)rdrurv)r|rrr
r}gsz&ByteArrayTest.test_regexps.<locals>.byzHello, worlds\w+rtr)r�re�findall)rr}rrrr
�test_regexpsfszByteArrayTest.test_regexpscCsTtdddg�}d|d<|�|tdddg��d|d<|�|tdddg��td�|d<|�|tdddg��yd|d<|�d	�Wntk
r�YnXyd|d
<|�d	�Wntk
r�YnXyd|d<|�d�Wntk
r�YnXytd�|d<|�d�Wntk
�r YnXyd|d<|�d
�Wntk
�rNYnXdS)Nr(r/r=r,r�r-r+rzDidn't raise IndexErrori����r4zDidn't raise ValueErrorzDidn't raise TypeError)rdrr�failr2rPrS)rrrrr
�test_setitemls@zByteArrayTest.test_setitemcCslttd��}|d=|�|ttdd���|d=|�|ttdd���|d=|�|tddddd	d
dg��dS)Nr+rr(r-r�rbr/r=r�r~�)rdr@r)rrrrr
�test_delitem�szByteArrayTest.test_delitemcCs\ttd��}|�t|�ttd���tdddddg�|dd�<|�|tddddddddddg
��|dd	�=|�|tdddddg��tddd
ddg�|dd�<|�|ttd���td
dg�|dd�<|�|tddd
d
ddddg��ddddg|dd�<|�|ttd���dddg|dd�<|�|tddd
ddddddddddg
��d|dd�<|�|tddd
dddg��td�|dd�<|�|tddddddg��g|dd�<|�|tdddddg��xPdd	dtd�ddddgddgggg	D](}|�t��||dd�<WdQRX�q�Wx>dddgdd ggD](}|�t��||dd�<WdQRX�q,WdS)!Nr+r(rrWr�r~rbr�r�r/r=rbr,�ei����r�r5sfoo�f�ogP����KDrrgffffff@r#rr�r�rNrOr4i���i(#)	rdr@rrAr�r�r1rSrP)rr�elemrrr
�
test_setslice�s6$
 *zByteArrayTest.test_setslicecCsvttd��}|�t|�ttd���|dd�=|�t|�ttdd���|�tdd��|�t|�ttdd���dS)Nr,r+�n)rdr@rrA�extend)rrrrr
�test_setslice_extend�s
z"ByteArrayTest.test_setslice_extendcCs,td�}|��|dd�=|td�7}~dS)Nr+r(r/)rd�poprL)rrrrr
�test_fifo_overrun�s

zByteArrayTest.test_fifo_overruncCs2td�}t�|�}|dd�=|�t�|�|�dS)Nr+r()rdr)�	getsizeof�assertLessEqual)rrrerrr
�test_del_expand�s

zByteArrayTest.test_del_expandcCs�dddddddd>tjddd	d
f}x�|D]�}x�|D]�}x�|dd�D]�}ttd��}t|�}||||�}|��|||||�<|||||�<|�|t|��||||�=||||�=|�|t|��qDWq2Wq(WdS)Nrr(r=r�i,iMr-r.i��i���rO)r)r*rAr@rdrxr)rr�r�r�r�r�rr�rrr
�test_extended_set_del_slice�s

z)ByteArrayTest.test_extended_set_del_slicecCs@ttd��}||dd�<|�|tttd��ttd����dS)Nr4rb)rdr@rrA)rrrrr
�test_setslice_trap�sz ByteArrayTest.test_setslice_trapcCs|td�}|}|d7}|�|d�|�||�|�||�|d7}|�|d�y|d7}Wntk
rlYnX|�d�dS)Nsabcsdefsabcdefsxyzs	abcdefxyzrz'bytes += unicode didn't raise TypeError)rdrr�rSr`)rrrnrrr
�test_iconcat�szByteArrayTest.test_iconcatcCs<td�}|}|d9}|�|d�|�||�|�||�dS)Nsabcr=s	abcabcabc)rdrr�)rrrnrrr
�test_irepeatszByteArrayTest.test_irepeatcCs<td�}|}|d9}|�|d�|�||�|�||�dS)Nr�r,sdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)rdrr�)rrrnrrr
�test_irepeat_1charsz ByteArrayTest.test_irepeat_1charcCsht�}|��}|�|d�|g}xBtd�D]6}|d7}|��}|�|t|��||kr*|�|�q*WdS)Nrr,r�)rd�	__alloc__ZassertGreaterEqualr@�
assertGreaterr0rJ)rr�allocr�r:rrr
�
test_allocszByteArrayTest.test_alloccsft����fdd�}��|����t��ttdd�����t��d����}��|t���dS)Nc	3s�xztdd�D]l}|Vt��}��|ttdt|�d�����t��t|����t��|����}��|t���qWdS)Nr(r,)r@rArr0rorvrw)r:r#rx)rrrr
�g"sz(ByteArrayTest.test_init_alloc.<locals>.gr(r,�c)rdrrrAr@r0rvrw)rrzrxr)rrr
�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|jd	d
ddg�|�t|jd	d
dd
g�|�t	|�d	�td�}|�t
td��g�|�|d�dS)NshellorWr'�css|]}t|�VqdS)N)r�)r9r�rrr
r;:sz,ByteArrayTest.test_extend.<locals>.<genexpr>�2r�rr(r/r4r-r#r�)rdrjrrur�rDrAr1rPr0rrv)rr�r#rrr
�test_extend1s2
zByteArrayTest.test_extendcs$td����td��|��d���td��|��d�|�t�fdd��|�t�fdd��|�t�fdd����td	����td
��|��d�|�t�fdd����ttd
���|��d�tddddg�}|�d�|�|tdddg��|�d�|�|tddg��dS)Nshellor
shelosheocs��td��S)Nr
)rUrvr)rrr
r&Sr'z+ByteArrayTest.test_remove.<locals>.<lambda>cs
��d�S)Ni�)rUr)rrr
r&Tr'cs
��d�S)Nr)rUr)rrr
r&Ur'rrrcs
��d�S)Nr)rUr)rrr
r&Zr'rr'�~rr<�)	rdrUrvrr1rPrSrrL)rr�r)rr
�test_removeMs&

zByteArrayTest.test_removecs�td��|����td��|���d�td��|���d�td��|�t�fdd��|�td	d��|�td
���d�dS)Nsworldr�rr�r.rZcs
��d�S)Nr+)rlr)rrr
r&jr'z(ByteArrayTest.test_pop.<locals>.<lambda>cSs
t���S)N)rdrlrrrr
r&kr'��rO)rdrrlrvr1r2)rr)rr
�test_popeszByteArrayTest.test_popcCs|�tdd��dS)NcSs
t���S)N)rd�sortrrrr
r&pr'z+ByteArrayTest.test_nosort.<locals>.<lambda>)r1�AttributeError)rrrr
�test_nosortoszByteArrayTest.test_nosortcs�td����td��|��d�|���d�d�t����td��|�t��d�|�t�fdd��t����ttd���|��d	�dS)
Nshellrshellor,r(r(cs
��d�S)Nr�)rJr)rrr
r&zr'z+ByteArrayTest.test_append.<locals>.<lambda>�A)rdrJrvrr0r1rSr)rr)rr
�test_appendrszByteArrayTest.test_appendcs�td����dtd����dtd����dtd����dtd��|��d�|�t�fdd	��t����d
ttd���|��d�dS)
Nsmssssppr(r:rbr.i�smississippics��dd�S)Nr�1)�insertr)rrr
r&�r'z+ByteArrayTest.test_insert.<locals>.<lambda>rr(r�)rdr�rvrr1rSr)rr)rr
�test_insertszByteArrayTest.test_insertcCsRtd�}|�||�ddd��tdd�td�D��}td�}|�||�|��dS)NsabcscdercSsg|]}|�qSrr)r9r:rrr
r�sz-ByteArrayTest.test_copied.<locals>.<listcomp>r4r')rdr\r�r@r)rr�tr�rrr
�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'�!)rdr�rr\r�)rr#rr�rrr
�0test_partition_bytearray_doesnt_share_nullstring�s$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)Nr(r/r-)r@)rW)rrr
�resize�sz3ByteArrayTest.test_resize_forbidden.<locals>.resize�r�rr(cs
�d=dS)Nr(rr)rrr
�delitem�sz4ByteArrayTest.test_resize_forbidden.<locals>.delitemcsd�ddd�<dS)Nr'r(r-r/rr)rrr
�delslice�sz5ByteArrayTest.test_resize_forbidden.<locals>.delslice)rdr@r�r1�BufferErrorrrlrU)r�vr�r�r�r�r)rr
�test_resize_forbidden�s*z#ByteArrayTest.test_resize_forbiddencCs ddlm}|�t|t��dS)Nr)�getbuffer_with_null_view)r.r�r1r�rd)rr�rrr
�test_obsolete_write_lock�sz&ByteArrayTest.test_obsolete_write_lockc	Cs�td�}td�}�x�ttjd�D�]z}t|�}t�||f|�}t�|�\}}||dd�<|�t	|�t	|��|�t|�|�t
|�t�||f|�}t�|�\}}||dd�<|�t	|�t	|��|�t|�|dd��xtdt|��D]}t
|�q�Wt�||f|�}t�|�\}}||dd�<|�t	|�t	|��|�t|�|t|�d��|�t
t
|�t�||f|�}t�|�\}}||dd�<|�t|�g�q"WdS)Nsabcsqwertyr()rdrAr@r�r�rDr�r�rrr�r0r1�
StopIteration)	rr�r�r�Zitorigr�r�rr:rrr
�test_iterator_pickling2�s6z%ByteArrayTest.test_iterator_pickling2cCs4td�}t|�}t|�|��|�t|�g�dS)Nsab)rdrDr�rHrrA)rrIr�rrr
�test_iterator_length_hint�s
z'ByteArrayTest.test_iterator_length_hintN),rrrrdrrrMrOrXrYr[r%r_rarcrhrkrmrprqrrrsrtruryr|rr�r�r�r�r�r�r�r�rrZcpython_onlyr�r�Z
list_testsZ
CommonTestZtest_exhausted_iteratorr�rrrr
rLsF"	(		


 $
rLc@s�eZdZedd��Zedd��Zdd�Zejj	dd��Z
d	d
�Zedd��Zd
d�Z
dd�Zdd�Zdd�Ze�ejjd�dd��ZdS)�AssortedBytesTestc	Cs�x�ttfD]x}|�|t��d�|�|tdg��d�|�|tddddg��d�|�|d�d	�|�|d
�d�|�|d�d
�q
WdS)Nzbytearray(b'')rzbytearray(b'\x00')r(rNrOzbytearray(b'\x00\x01\xfe\xff')sabczb'abc'�'zb"'"s'"zb'\'"')rr�reprrrd)rr�rrr
�
test_repr_strszAssortedBytesTest.test_repr_strc
Csvxpdtd�fD]`}|�t|�t|��|�t|d�t|��|�tdt�t|�j	���t|d�WdQRXqWdS)Nsabcrz\b%s\br|)
rdrrCrrr�rSr]�escaperr)rrrrr
�test_formats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)NsabcTsabF)rrL)rrrr
�test_compare_bytes_to_bytearrays0z1AssortedBytesTest.test_compare_bytes_to_bytearraycCsH|�tj�|�tj�d�tj�|�tj�|�tj�d�tj�dS)Nz
bytearray(zbytes()ZassertIsNotNonerd�__doc__rlr�rL)rrrr
�test_doc5szAssortedBytesTest.test_doccCs,td�}t|�}t|�}|�|t|��dS)NsHello world
����)rLr�rdr)rr��bufrrrr
�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'��zb'\x80'zbytearray(b'')zbytearray(b'x')zbytearray(b'\x80'))rrrrd)rrrr
�test_to_strBszAssortedBytesTest.test_to_strcCs^ddddg}x"|D]\}}|�|t|d��qWx(tdd�D]}|�ttdt|��q<WdS)	N)sWonderful spamzWonderful spam)sWonderful spam toozWonderful spam too)s��uª€)s\xaa\x00\000\200z\xaa\x00\000\200zlatin-1r<r4zb"%s")rrdr@r1�SyntaxError�eval�chr)rZtestsrr|r�rrr
�test_literalKszAssortedBytesTest.test_literalcCs|�d�td��ddg�dS)Nsa br�r�r�)rr�r�)rrrr
�test_split_bytearrayXsz&AssortedBytesTest.test_split_bytearraycCs|�d�td��ddg�dS)Nsa br�r�r�)rr�r�)rrrr
�test_rsplit_bytearray[sz'AssortedBytesTest.test_rsplit_bytearraycCst�}|�|�dd�|�dS)Nr')rdr\r�)rrrrr
�test_return_self^sz"AssortedBytesTest.test_return_selfz4BytesWarning is needed for this test: use -bb optionc	CsTdd�}|��ddkWdQRX|��ddkWdQRX|��ddkWdQRX|��ddkWdQRX|��td�dkWdQRX|��dtd�kWdQRX|��td�dkWdQRX|��dtd�kWdQRX|��ddkWdQRX|��ddkWdQRX|��ddkWdQRX|��ddkWdQRXdS)NcSstj�dtf�S)Nr)rrrrrrrr
�
bytes_warningfsz5AssortedBytesTest.test_compare.<locals>.bytes_warningr'rrVr)rd)rr�rrr
rpcs2zAssortedBytesTest.test_compareN)rrrrr�r�r�rrZrequires_docstringsr�r�r�r�r�r�r��unittestZ
skipUnlessr)�flagsr�rprrrr
r��s		

r�c@seZdZdd�Zdd�ZdS)�BytearrayPEP3137TestcCst|�S)N)rd)rr�rrr
�marshal�szBytearrayPEP3137Test.marshalcCs�|�d�}x<dD]4}t||�}|d�}|�||�|�|||d�qWx2dD]*}t|�}|�||�|�|||d�qNW|�d�}|�|g�}|�||�|�||�dS)Ns1234)�zfillrrr�r=z" 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')r��getattrrr\r�r�)r�valZmethnamerZnewval�expr�seprrr
�test_returns_new_copy�s 




z*BytearrayPEP3137Test.test_returns_new_copyN)rrrr�r�rrrr
r��sr�cs eZdZ�fdd�ZdZ�ZS)�FixedStringTestcs&t|t�r|�|�d��St��|�S)Nzutf-8)�
isinstancerrrr��super�fixtype)r�obj)rrr
r��s
zFixedStringTest.fixtypeT)rrrr�Zcontains_bytes�
__classcell__rr)rr
r��sr�c@seZdZeZdS)�ByteArrayAsStringTestN)rrrrdrrrrr
r��sr�c@seZdZeZdS)�BytesAsStringTestN)rrrrLrrrrr
r��sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SubclassTestcCs�|�t|j|j��|�|��|j�d\}}|�|�|�|�}}|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||�|�||||�|�||||�|�||||�|�|d|dk�dS)N)sabcdsefghrW)rl�
issubclassr�basetyperr\r)rr#rZ_aZ_brrr
�
test_basic�szSubclassTest.test_basiccCs`|�d�}|���|g�}|�||�|�t|�|jt|��|�dg�}|�t|�|j�dS)Nsabcd)rr�r�r\r�r)r�s1�s2Zs3rrr
r��s
zSubclassTest.test_joincCs�|�d�}d|_|�d�|_x�ttjd�D]�}t�t�||��}|�t	|�t	|��|�
||�|�
|j|j�|�
|j|j�|�
t|�t|��|�
t|j�t|j��q,WdS)Nsabcdr+sefghr()rr��yr@r�r�r�r��assertNotEqual�idrr)rr#r�rrrr
�test_pickle�s
zSubclassTest.test_picklecCs�|�d�}d|_|�d�|_x�tjtjfD]x}||�}|�t|�t|��|�||�|�|j|j�|�|j|j�|�t|�t|��|�t|j�t|j��q*WdS)Nsabcdr+sefgh)	rr�r�r!r"r�r�rr)rr#r$rrrr
r%�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�s+0cseZdZ�fdd�ZdS)z%SubclassTest.test_fromhex.<locals>.B1cs�j�||�}d|_|S)N�bar)r��__new__�foo)�clsr�me)rrr
r�sz-SubclassTest.test_fromhex.<locals>.B1.__new__N)rrrr�r)rrr
�B1sr�r�cseZdZ�fdd�ZdS)z%SubclassTest.test_fromhex.<locals>.B2cs(�jtk	r�jj|f|�|�d|_dS)Nr�)r�rLrr�)r�r	�kwargs)rrr
rs
z.SubclassTest.test_fromhex.<locals>.B2.__init__N)rrrrr)rrr
�B2sr�)rr�rr�rr�r�)rrr�r�r)rr
r��s

zSubclassTest.test_fromhexN)rrrr�r�r�r%r�rrrr
r��s



r�c@seZdZdS)�ByteArraySubclassN)rrrrrrr
r�sr�c@seZdZdS)r+N)rrrrrrr
r+sr+c@seZdZdS)r*N)rrrrrrr
r*sr*c@seZdZeZeZdd�ZdS)�ByteArraySubclassTestcCsNGdd�dt�}|dd�}|ddd�}|�|d�|ddd�}|�|d�dS)Nc@seZdZddd�ZdS)z:ByteArraySubclassTest.test_init_override.<locals>.subclassr(c_stj|f|�|�dS)N)rdr)r��newargr	r�rrr
r&szCByteArraySubclassTest.test_init_override.<locals>.subclass.__init__N)r()rrrrrrrr
�subclass%sr�rbsabcd)�source)r�r�)rdr)rr�r�rrr
�test_init_override$s
z(ByteArraySubclassTest.test_init_overrideN)rrrrdr�r�rr�rrrr
r� sr�c@seZdZeZeZdS)�BytesSubclassTestN)rrrrLr�r+rrrrr
r�/sr��__main__))r�rTr r]r)r!rr�rRr�Ztest.supportrZtest.string_testsZtest.list_testsrrr�r�rrrZTestCaserrLr�r�Zstring_testsZBaseTestr�r�r�r�rdr�rLr+r*r�r�r�mainrrrr
�<module>sX
,?s]