Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_buffer.cpython-310.pyc
o

�9j<��@sJddlZddlZddlmZddlmZddlmZmZddl	m
Z
mZmZddl
Z
ddlZddlZddlZddlZddlmZddlmZzddlTWneyWdZYnwzddlZWneyidZYnwzddlZWney{dZYnwz1e���#e_e
���dd	lmZWd�n1s�wYWd�n1s�wYWney�dZYnwzddl Z Wney�dZ Ynwd
Z!dddddddddddddddd�Z"er�e"d=e"d
=e�rze�#dd�de"d<de"d<Wnej$�yYnwddddddddddddddd>dd>fd�Z%dd�Z&e"e"e%e%e%e%d�Z'e�r>e'd D]Z(e&e(�e'd e(<�q2e"�)�Z*e"�)�Z+e"D]Z,e,d!v�rRe+e,=�qHe"�)�Z-e"D]Z,e,d"v�rde-e,=�qZe*e'd#<e*e'd$<e+e'd%<e-e'd&<e-e'd'<dZ.dZ/gd�gd(�fd%gd)gfd)gd)gfd$d#gd)gfd'd&gd)gfd*�Z0d+d,�Z1d-d.�Z2d/d0�Z3d1d2�Z4d�d4d5�Z5d	d6d7�Z6d	d8d9�Z7d:d;�Z8d<d=�Z9d>d?�e'd D�Z:d@dA�Z;dBdC�Z<dDdE�Z=dFdG�Z>dHdI�Z?dJdK�Z@dLdM�ZAdNdO�ZBdPdQ�ZCdRdS�ZDdTdU�ZEdVdW�ZFdXdY�ZGdZd[�ZHd\d]�ZId^d_�ZJd`da�ZKdbdc�ZLddde�ZMdfdg�ZNdhdi�ZOdjdk�ZPd�dodp�ZQdqdr�ZRdsdt�ZSd�dudv�ZTdwdx�ZUd�dydz�ZVd{d|�ZWd�d}d~�ZXdd��ZYd�d��ZZd�d��Z[d�d�d��Z\d�d�d��Z]d�d�d��Z^d�d�d��Z_d�d��Z`d�ZadlZbd�Zce!�r�d�Zad�Zbd�Zce]ZZe^Z[e_Ze�ded��e�ded��Gd�d��d�eje���Zfegd�k�r�e�h�dSdS)��N)�support)�	os_helper)�permutations�product)�	randrange�sample�choice)�Decimal)�Fraction)�*)�ndarrayT)�?�c�b�B�h�H�i�I�l�L�n�N�f�d�Prr�Q������q�r��r�)i�����)i�����)ri)���)rl�l������r���)r
rrrrrrrrrrrrrc	Cs�|dkrd}|S|dkrd}|S|dkrd}|S|dkr'dd	>dd	>f}|Sd
D]}z
t�|d|>d�Wn
tjyBYq)w|d@rPd|>d|>fndd|>f}|S)zReturn range of a native type.rr!r
rrr'rr+r,)
r#��@�?� �����r)�struct�pack�error)�fmt�lh�exp�r<�'/usr/lib/python3.10/test/test_buffer.py�native_type_range_s*�
��	��&r>)��@�<�>�=�!r@�
bBhHiIlLfd�Bbc�m�@m�ar�@b)r?�1�2�3r?)r�array�numpy�
memoryview�bytefmtcCsvtt||�}|dkrt|g�}|dkr|dkrd}|dkr#t|�}|dks+|dkr9t�||�}t�||�d}|S)	zWReturn random item for a type specified by a mode and a single
       format character.rrO��r
rrr)r�fmtdict�bytes�boolr6r7�unpack)�mode�char�obj�xr<r<r=�
randrange_fmt�s
r\cCsJ|�d�\}}g}|D]}|�t|||��qt|�dkr!|dSt|�S)zReturn single random item.�#r+r)�split�appendr\�len�tuple)r9rZrX�charsr[rr<r<r=�gen_item�s
rccCs<|dkr	t||�Sdg|}t|�D]	}t||�||<q|S)z,Return a list of random items (or a scalar).r)rc�range)rr9rZ�lstrr<r<r=�	gen_items�s

rfcCs�tt|t�}|d}|�d�}tdd�}t|�D]$}ttt|��}tt|t�}||t	|r3|nd�7}|||7}qt
|||�}	t||�}
||	|
fS)Nr]�ambr �
r+)r�cap�MODE�striprrdrarT�MULT�intrfrc)rrZrX�xfmtr9�nmemb�_rY�
multiplier�items�itemr<r<r=�struct_items�s



rtrcCs�|durtt|t�}|durttt|��}tt|t�}|d|t|r)|nd�}t|||�}t||�}|�	d�||}|||fS)z"Return random format, items, item.Nr]r+rg)
rrirjrarTrlrmrfrcrk)rrZrXrYrqr9rrrsr<r<r=�	randitems�s

ruccs6�t|tD]}t|D]
}t||||�Vq
qdS)z1Iterate through supported mode/char combinations.N)rirjrTru)rrZrXrYr<r<r=�	iter_mode�s���rvccs4�t||�D]}|Vq|dkrdSt||�VdS)zwYield (format, items, item) for all possible modes and format
       characters plus one random compound format string.rN)rvrt)�nitems�testobj�tr<r<r=�iter_format�s�rzcCsd|vpd|vpd|vS)Nrrrr<)r9r<r<r=�is_byte_format�sr{cCs4t|�}|dks|dko|ddko||dtvS)zformat suitable for memoryviewr+r rr@)r`�
MEMORYVIEW)r9r[r<r<r=�is_memoryview_format�s�r}cCsg|]}t|�s|�qSr<)r{��.0rr<r<r=�
<listcomp>��r�cCst|t�S)z9Tuple items (representing structs) are regarded as atoms.��
isinstance�list�rer<r<r=�atomp��r�cCs
t|t�S�Nr�r�r<r<r=�listp��
r�cCs6t|�dkrdS|d}|dd�D]}||9}q|S)zProduct of list elements.rr+N)r`)rer[�vr<r<r=�prod�s
r�cCs�|dkrdS|dkr.t|dd��|g}t|ddd�D]}||||d9<q|S|gt|dd��}td|�D]}||||d9<q>|S)zOCalculate strides of a contiguous array. Layout is 'C' or
       'F' (Fortran).rr<�Cr+Nr ���)r�rd)�ndim�shape�itemsize�layout�stridesrr<r<r=�strides_from_shapes�r�cCs�t|�r|St|�dkr|dSdg|d}|dr#t|�|dnd}t|d�D]}||}t||||�|dd��||<q+|S)zmConvert flat item list to the nested list representation of a
       multidimensional C array with shape 's'.rr+N)r�r`rd�_ca)rr�sre�strider�startr<r<r=r�s$r�cCslt|�r|St|�dkr|dSdg|d}|d}t|d�D]}t||d|�|dd��||<q!|S)zsConvert flat item list to the nested list representation of a
       multidimensional Fortran array with shape 's'.rNr+)r�r`rd�_fa)rrr�rer�rr<r<r=r�%s"r�cC�2t|�rd|vrt|�t|�krtd��t||�S�Nrzprod(shape) != len(items))r�r�r`�
ValueErrorr��rrr�r<r<r=�carray2� 
r�cCr�r�)r�r�r`r�r�r�r<r<r=�farray7r�r�cCsdd�|D�}t|�S)z(Generate all possible tuples of indices.cSsg|]}t|��qSr<�rd�rr�r<r<r=r�>�zindices.<locals>.<listcomp>)r)r��	iterablesr<r<r=�indices<sr�cCs*d}t|�D]}|||||7}q|S)zAConvert multi-dimensional index to the position in the flat list.rr�)r��indr��retrr<r<r=�getindexAsr�c	Cs�|s|St|�}t||dd�}t||ddd�dd�}dgt|�}t|�D]}t|||�}t||ddd�|�}||||<q&|S)z�Transpose flat item list that is regarded as a multi-dimensional
       matrix defined by shape: dest...[k][j][i] = src[i][j][k]...  r+r�Nr�r)r`r�r�r�)	�srcr�r��sstrides�dstrides�destr��fr�tor<r<r=�	transposeHsr�cCs6|gkr|St|�r
|gSt|d�t|dd��S)zflatten listrr+N�r��_flattenr�r<r<r=r�Ws
r�cCst|�r|St|�S)zflatten list or return scalarr�r�r<r<r=�flatten_sr�cCs4t|�rgSt||d�gt|d|dd��S)zMGet the shape of lst after slicing: slices is a list of slice
       objects.rr+N)r�r`�slice_shape�re�slicesr<r<r=r�es(r�cs&t|�r|S�fdd�|�dD�S)z=Multi-dimensional slicing: slices is a list of slice objects.csg|]}t|�dd���qS�r+N)�
multislice)r�sublst�r�r<r=r�pszmultislice.<locals>.<listcomp>r)r�r�r<r�r=r�lsr�csFt|�r|S��fdd�t|�d|�d�D�}||�d<|S)a�Multi-dimensional slice assignment: llst and rlst are the operands,
       lslices and rslices are lists of slice objects. llst and rlst must
       have the same structure.

       For a two-dimensional example, this is not implemented in Python:

         llst[0:3:2, 0:3:2] = rlst[1:3:1, 1:3:1]

       Instead we write:

         lslices = [slice(0,3,2), slice(0,3,2)]
         rslices = [slice(1,3,1), slice(1,3,1)]
         multislice_assign(llst, rlst, lslices, rslices)
    c	s.g|]\}}t||�dd��dd���qSr�)�m_assign)rr�r��lslices�rslicesr<r=r��s"�zm_assign.<locals>.<listcomp>r)r��zip��llst�rlstr�r�r<r�r=r�rs�r�cCsft||�}t||�}t|�t|�krdStt|��D]}||||kr'dS||dkr0dSqdS)z9Compare the structure of llst[lslices] and rlst[rslices].r�r)r�r`rd)r�r�r�r��lshape�rshaperr<r<r=�
cmp_structure�s

�r�cCs(t||||�dkr
td��t||||�S)z:Return llst after assigning: llst[lslices] = rlst[rslices]rz+lvalue and rvalue have different structures)r�r�r�r�r<r<r=�multislice_assign�sr�cs�|�rdS|dks|�|krdSt�fdd��D��rdS|dkr-|dko,�o,�Sd�vr3dSt��fdd�t|�D��}t��fdd�t|�D��}d||ko\||�|kS)z�Verify that the parameters represent a valid array within
       the bounds of the allocated memory:
           char *mem: start of the physical memory block
           memlen: length of the physical memory block
           offset: (char *)buf - mem
    Frc3s�|]}|�VqdSr�r<r��r�r<r=�	<genexpr>���z#verify_structure.<locals>.<genexpr>Tc3�0�|]}�|dkr�|�|dVqdS�rr+Nr<�r�j�r�r�r<r=r������c3�0�|]}�|dkr�|�|dVqdSr�r<r�r�r<r=r��r�)�any�sumrd)�memlenr�r�r�r��offset�imin�imaxr<)r�r�r�r=�verify_structure�sr�cCs|D]}||}q|Sr�r<)rer�rr<r<r=�get_item�s
r�c
Cs:|\}}}}}}|}t|�D]}	|||	||	7}q|S)z-Location of an item in the underlying memory.r�)
r�ryr�r�r�r�r�r��prr<r<r=�memory_index�s
r�cCsR|\}}}}}}d|>}t|�D]}t||�}	d|	>}
||
@r"dS||
O}qdS)z�The structure 't' is overlapping if at least one memory location
       is visited twice while iterating through all possible tuples of
       indices.r+TF)r�r�)ryr�r�r�r�r�r��visitedr�r�bitr<r<r=�is_overlapping�s

r��r2r<csN�s]t|d�}|dkr2|r|||dddfStdd�}||}td�dkr(|n|}|||dd|fSd}	td�}
|
dkrA|rAd}	n|
dkrGd}	dg|�t|�D]}t|	|d��|<qPnt��}d	}td�}
|
dkrq|
d@rqd
nd}
dg|�|t||d��|d<|
s��|ddkr�|�|d<t|ddd�D]2}|�|dr��|dnd9}|
r�|t||d��|<q�d
td�|td|d��|<q�d}}d�vr�t��fdd�t|�D��}t��fdd�t|�D��}||}|�r
||}||d|}n|||}td�dk�r||n|}|||��|fS)z�Return random structure:
           (memlen, itemsize, ndim, shape, strides, offset)
       If 'valid' is true, the returned structure is valid, otherwise invalid.
       If 'shape' is given, use that instead of creating a random shape.
    r+rr<�r �d�_�Zr�TFr��r+r�c3r�r�r<r�r�r<r=r�r�z!rand_structure.<locals>.<genexpr>c3r�r�r<r�r�r<r=r�r�)rrdr`r�)r��valid�maxdim�maxshaper�r�rwr�r��minshaperr�	maxstride�zero_strider�r�r<r�r=�rand_structure�s^

�
 
�
�
r�c
Csp||}t|d�}|r|||nd}td|d�}|||}t|||�}t||�\}}}}	|	|kr6t�|S)z=Create a random slice of len slicelen that fits into listlen.r+)r�slice�
slice_indices�RuntimeError)
�slicelen�listlen�maxstartr��maxstep�step�stopr�rp�controlr<r<r=�randslice_from_slicelen'sr�cCspdg|}dg|}t|�D]!}||}|dkrtd|d�nd}t||�||<t||�||<qt|�t|�fS)zxCreate two sets of slices for an array x with shape 'shape'
       such that shapeof(x[lslices]) == shapeof(x[rslices]).rr+)rdrr�ra)r�r�r�r�rrr�r<r<r=�randslice_from_shape4s

r�cCs�td|d�}d}td�}|dkrd}n|dkrd}td�dkr"dnd	}dg|}dg|}dg|}dg|}	t|�D]�}t||d�}
t||d�}||
krU|
|}}
|r�t|
|
d�}t|
|
d�}
d
td�td|
d�}t||
|�}t||
�\}}}}n|
dkr�td|
d�nd}t||
�}t||�}td�dkr�||
||<||<|||	|<||<q<|
|||<||<|||	|<||<q<||t|�t|	�fS)z�Create (lshape, rshape, tuple(lslices), tuple(rslices)) such that
       shapeof(x[lslices]) == shapeof(y[rslices]), where x is an array
       with shape 'lshape' and y is an array with shape 'rshape'.r+r r�r�rr��PTFr�)rrdr�r�r�ra)r�r�r�r�r�
all_randomr�r�r�r��small�bigr�r�r��s_smallrpr��s_bigr<r<r=�rand_aligned_slices@s<


r�cCs$|\}}}}}}t||d|d�S)zMReturn a list of random items for structure 't' with format
       'fmtchar'.r]rO)rf)r9ryr�r�rpr<r<r=�randitems_from_structureksr�c
Cs(|\}}}}}}	t|||||	t|Bd�S)z:Return ndarray from the tuple returned by rand_structure()�r�r��formatr��flags)r�ND_WRITABLE)
rrr9ryrr�r�r�r�r�r�r<r<r=�ndarray_from_structureqs
�rcCsP|\}}}}}}t|�}	t|�D]\}
}t�||	|
||�qt|	||||d�S)z>Return numpy_array from the tuple returned by rand_structure())�bufferr�r��dtyper�)�	bytearray�	enumerater6�	pack_into�numpy_array)rrr9ryr�r�r�r�r�r��bufr�r�r<r<r=�numpy_array_from_structurews�rcs�|j}|rt|��|krd|fSn$|gkr$|jdks�|kr#d|fSnt|��\}}|g}|dkr6d|fS|�����fdd�tdt����D�}g}|D]}	t�||	�d}
|
|
krbd|fS|�	|
�qN|gkrp||fS|d|fS)a�Interpret the raw memory of 'exporter' as a list of items with
       size 'itemsize'. If shape=None, the new structure is assumed to
       be 1-D with n * itemsize = bytelen. If shape is given, the usual
       constraint for contiguous arrays prod(shape) * itemsize = bytelen
       applies. On success, return (items, shape). If the constraints
       cannot be met, return (None, None). If a chunk of bytes is interpreted
       as NaN as a result of float conversion, return ('nan', None).Nrcsg|]
}�||���qSr<r<)rr�r��memr<r=r���zcast_items.<locals>.<listcomp>�nan)
�nbytesr�r��divmod�tobytesrdr`r6rWr_)�exporterr9r�r��bytelenrr��	byteitemsrrr�rsr<rr=�
cast_items�s,�� rc#s��td�D]}|gVqtdd�}td�dkrdnd��fdd	�t|�D�Vtdd�}td�dkr4dnd��fd
d	�t|�D�VdS)z Generate shapes to test casting.r0��r�r�r+r c�g|]}t�d��qS�r��r�rrp�r�r<r=r���z!gencastshapes.<locals>.<listcomp>crrrrrr<r=r��rN)rdr)rr�r<rr=�
gencastshapes�s�


rcCs0tt||d�t||d�t||d��S)z4Generate all possible slices for a single dimension.r+)rrd)rr<r<r=�	genslices�s0r cs�fdd�t|�D�}t|�S)z/Generate all possible slice tuples for 'shape'.csg|]}t�|��qSr<)r �rr�r�r<r=r��r�z"genslices_ndim.<locals>.<listcomp>)rdr)r�r�r�r<r"r=�genslices_ndim�sr#FcCs,|s|dkrdnd}t||d�}t||�S)z�Generate random slice for a single dimension of length n.
       If zero=True, the slices may be empty, otherwise they will
       be non-empty.rr+)rr�)r�allow_empty�minlenr�r<r<r=�rslice�s
r&ccs �td�D]}t||�VqdS)z.Generate random slices for a single dimension.r�N)rdr&)rr$rpr<r<r=r��s��r�c#sr�t|�D]}t�fdd�t|�D��Vqt|�D]}t�fdd�t|�D��Vqtdd�t|�D��VdS)z)Generate random slice tuples for 'shape'.c3s�|]	}t�|�VqdSr��r&r!r"r<r=r����zrslices_ndim.<locals>.<genexpr>c3s �|]}t�|dd�VqdS)T)r$Nr'r!r"r<r=r��s�css�|]	}tddd�VqdSr�)r�rr<r<r=r��r(N)rdra)r�r��
iterationsrpr<r"r=�rslices_ndim�s�r*ccs2�t|�}|dur
t|�n|}tt||��VdSr�)rar`r)�iterabler��poolr<r<r=�rpermutation�s�r-c
Cs�z|��}Wnttfy|��}Ynwt|t�r"|j}|j}nd}d}td||j	|j
|j||j|j
|f�tj��dS)zPrint ndarray for debugging.�unknownz_ndarray(%s, shape=%s, strides=%s, suboffsets=%s, offset=%s, format='%s', itemsize=%s, flags=%s)N)�tolist�	TypeError�NotImplementedErrorrr�rr�r�printr�r��
suboffsetsrr��sys�stdout�flush)�ndr[r�rr<r<r=�
ndarray_print�s �

��r8r�rh�rz%struct module required for this test.z%ndarray object required for this testc@s�eZdZdd�Zddd�dd�Zd�dd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%dIdJ�Z&dKdL�Z'dMdN�Z(dOdP�Z)e*j+Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2d_d`�Z3dadb�Z4e5j6dcdd��Z7dedf�Z8dgdh�Z9didj�Z:dkdl�Z;dmdn�Z<dodp�Z=dqdr�Z>dsdt�Z?dudv�Z@dwdx�ZAdydz�ZBd{d|�ZCd}d~�ZDdd��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRe*jSd�d���ZTd�S)��TestBufferProtocolcCst�|_dSr�)�get_sizeof_void_p�
sizeof_void_p��selfr<r<r=�setUpr�zTestBufferProtocol.setUpF)�sliced�castc
%
s*�	r	t�	���n	�st���n��d��jrg���d�d}td��D]}
�	|
dkr.n�|
dkrA|�|
�	|
d7}q$|gdd�t�d�D���j}�ddkr\|}|gt�dd������j|���	�j
����	�j����	�j�����j
|���	�j����	�jt�	���
r��s���	�jt�����	�jt���t�t�s�t��rɈr����n���}��	|���s�dS|�s�t�}d}t�	�D]<}z&t�|�}t�|�}t|t�r�tj�g|�R�}nt��|�}|�|�Wn
t�yd}Ynw��	||�q�|�s���	���|�t��}d� dd	�|D��}��	|�!�|���r<�nd
}t"��}dD�]s}�}|dk�rht#�d
��rZt#�d��rgt$|�	�}t|�	|t%d�}nt#�d
��ryt#�d��r�|dk�r�t|�	|d�}t&�t'|����	���|���(t)�|���dk�r��qDt|�}|�r�dnt*}t+�dt,����	t��|�����fdd�t|�D�}t|d�dk�r�dd�|D�}t|�	|�d�} ��	t| �t���t����}!��	|!��t��jdd�}!��	|!��t��jdd�}!��	|!��t+�dt,����	t��|�����fdd�t|�D�}t|d�dk�r<dd�|D�}t|�	|t%B�d�} ��	t| �t���t��jdd�}!��	|!��t+�d
t,����	t��|�����fdd�t|�D�}t|d�dk�r�dd�|D�}t#�d��r�t%nd}"t|�	|"|B�d�} ��	t| �t���t��jd
d�}!��	|!���qDt���rzt��}Wnt�y�YdSwt�t��rوjn��|f���������	�
��fdd�	}#|#|�|�-��}$|#|$dd�Wd�n	1�swY|��dSdS)Nr<rr+cS�g|]}d�qS)r�r<r�r<r<r=r��z-TestBufferProtocol.verify.<locals>.<listcomp>Tr?css�|]}d|VqdS)z%02xNr<r~r<r<r=r�Ur�z,TestBufferProtocol.verify.<locals>.<genexpr>r�r��F�ArErFr��r�rr�r�rc�g|]}t���|���qSr<�r6�unpack_fromr!��contigr9r�r<r=r����cS�g|]}|d�qS�rr<r�r<r<r=r��r��r�rr��ordercrIr<rJr!rLr<r=r��rNcSrOrPr<r�r<r<r=r��r�crIr<rJr!rLr<r=r��rNcSrOrPr<r�r<r<r=r��r�cs���|j����|j����|j����|j����|j|���|j����|jt	����	r7�s@��|j
t	�
����|jt	����dkrOdnt��}��t|�|��ra��
�n���}��|����|��dS)Nrr+)�assertIsrZ�assertEqualrr�r�readonlyr�r�rar�r3r`r/r)rG�expected_readonlyr�rep)�ex�expected_lenr9r�rer��resultr>r�r@r�r3r<r=�check_memoryview�sz3TestBufferProtocol.verify.<locals>.check_memoryview)rW).r�r`r3�
assertGreaterrdr<r�rTrZrUrr�rrVr�r�rar�r�rr}r/rrr��get_pointerr�r6r7�extend�BufferErrorrP�join�hexr��
is_contiguousr��
ND_FORTRAN�get_contiguous�
PyBUF_READ�
assertTrue�
cmp_contigr�py_buffer_to_contiguous�
PyBUF_FULL_RO�
toreadonly)%r>r[rZr�r9rVr�r�r�rer@rA�
suboffset0r�stride0rXr�buf_errr��item1�item2r[rGr�ff�	flattenedrS�expected�transro�ro�initlst�y�contig_bytesrr\�mmr<)
rMrYrZr9r�rer�r[r>r�r@r�r3r=�verifys
�


�

�
���

����
�&
��zTestBufferProtocol.verifycCsddd�}|jr||t�s>||t�r|jr>||t�r|jr>||t�r$|jr>||t�s,|j	s>||t
�s4|jr>||t�sI||t�rI|j
tt||d�dSt|t�sSt|j�rX|��}n
t|td�}|��}||t�ridn|j}|j}	|j}
|j}||t�s�d}	|��}||t�s�d}||t�r�|jnd}||t
�r�|jnd}
t||d�}|j|||
|	||||
||d�
dS)	NcSs||@|kSr�r<)�req�flagr<r<r=�match�sz/TestBufferProtocol.verify_getbuf.<locals>.match��getbufFr?r+r<)	rZr�r9rVr�r�r�rer@)rV�PyBUF_WRITABLE�PyBUF_C_CONTIGUOUS�c_contiguous�PyBUF_F_CONTIGUOUS�f_contiguous�PyBUF_ANY_CONTIGUOUS�
contiguous�PyBUF_INDIRECTr3�
PyBUF_STRIDES�PyBUF_ND�PyBUF_FORMAT�assertRaisesr`rr�r}rr/rjr�r�rr�r�rz)r>�orig_exrYr{r@r}rer7rur9r�r�r�r�r<r<r=�
verify_getbuf�sh����������	�	���




�z TestBufferProtocol.verify_getbufcs�tttttttttt	t
ttt
tf}dd�td�D�dfgd�dfgd�dfdd�td�D�d	ff}ggd
fgd�gd
fdggd
fdgdgd
fdgdgd
fdgdgd
fddggd
fddgddgd
fddgddgdfddgddgdff
}d
ttttBtttBf}d
ttttBf}|D]�\}}t�|��|D]�\}}	}
�fdd�|	D�}	|
�9}
|D]�}|	r�|t@r�q�|s�|t@r�q�|r�|n|d
}t|||||	|
d�}
|r�|
ddd�nd}t|
�}|r�t|�}|
jd
ks�|
jdkr�|r�|	r�|�||
�|�r|jdk�r|�r|	�r|�||�|D]4}|D].}|�|
|
||B�|�|
|||B�|�r:|j||||Bdd�|j||||Bdd��q
�q	q�q�q�gd�}t|dgtd�}|�tt|�tdgdg�}t|td�}|jtt|td�|jtt|td�|jtt|td�|jtt|td�|jtt|td�|jtt|td�t|td�}gd�gd�fD]@}d
tfD]8}t|||tBd�}|�t |d��|�t |d ��|D]}t||d�}|�t |d��|�t |d ���qȐq��q�dS)!NcSsg|]
}|dr
dnd�qS)r TFr<�rr[r<r<r=r�rz:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>�r
�r+r r9rr�rr5r4�	rh�r�rrcSs$g|]}|drd|nd|�qS)r r&r%r<r�r<r<r=r�s$rr)r+r9r+r�r�rr ���r9r���r+r4csg|]}|��qSr<r<r�r�r<r=r�)r�)rrr�r�r�T)r@�r�rr�r~)r+r�r+)r5rr5rEr�)!r�r�r��PyBUF_SIMPLEr�r�r��
PyBUF_FULLrj�
PyBUF_RECORDS�PyBUF_RECORDS_RO�
PyBUF_STRIDED�PyBUF_STRIDED_RO�PyBUF_CONTIG�PyBUF_CONTIG_ROrdrrd�ND_PILr�r�r6�calcsizerrPr�rUr��ND_GETBUF_FAILr�r`rgrc)r>�requests�	items_fmt�	structure�ndflags�
real_flagsrrr9r�r�r�r�_items�ex1�ex2�m1�m2r{�bitsrY�baser7rSr<r�r=�test_ndarray_getbuf�s��

�
���
��������!���z&TestBufferProtocol.test_ndarray_getbufc
	Cs�tdgdg�}tdgdgtd�}t|j|jfD�]�}|�t|hd��|�t|gd��|�t|gd��|jt|gd�dhd	�|jt|gd�dgdhd
�|jt|gd�dggd�|jt|dgdgid�|jt|dgdgid
�|jt|dgdgid�|jt|dgdgdgtd�|jt|dggtd
�|jt|gdgd	�|jt|dgdgdd�|jtj	|dgdgdd�|jt|ddgdgdd�|jt|gd�dgdd�t
d}|jt|dg|dg|d	�|jt|dgdgd	�|jt|gd�dgd	�|jt|dgddgd	�|jt|gd�ddgdd�|jt|gd�dgdgd
�|jt|dgdgddgd
�|jt|ddgddgdgd
�|jt|gd�dgdgdd�|jt|gd�dgdd�|jt|gd�dgddd�|jt|gd�dgd d�|jtj	|dgdgd!d�gd"�}|jt||ddgd#d$gd%d&�|jt|t�d'd(�|jt|dgdgt
d�|�t|dg�q|jttd)td*�tdgdgtd�}|jt|jdgdgtd�td)�}|�t|jdgdg�|�t|j�tdgdg�}|�dgdg�t|�}|�t|jdgdg�|�t|j�|��|��|�t|j�~|�ttigd��|�ttd)i�tttd+��dgd+d	�}|�tt|d%g�tttd,��ddgd	�}|�tt|gd-��|�tt|ddg�|�tt|d#dg�|�tt|d.dg�tgd�dgdd�}t|td*�}|�t|j�tgd�dgdd�}t|�}	t|	�}|�t|j�td/gdgd0d�}|�t|j�t
}ttt|��dg|d	�}|�t|j�tdgdgd	�}|�ttddddd%�|�tt|d1d2�|�tt|d.d2�|�tt|td3�|�tt|td4�|�tt|td5�|�tt|d6d7�tdgdgd	�}|�ttddddd%�|�tti|�|�tt|i�tdgdgd	�}|�ttddddd%�|�ttid7�|�tt|d8�dS)9Nr�r+�r>r+r r9)r+r rM)r+r �r9r�r+r r9r9r"r��r�r�rHr�)r�r�r�r�r�XXXri�r�r r9r �QLr�rMr#�r+r r9rr�rK�r+r r9r�r�r�rr)r�r�rr?z@#$)
r+r r9rr�rr5r4r�rh���r�r�)r�r�r�r�r�123r~r�r�)r r9rr*)�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+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+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+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+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+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+��LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL�xyzr��u �Z�rF��)r�ND_VAREXPORT�pushr�r0rdr�r�r6r8�ND_MAX_NDIM�
OverflowErrorrr�r`r��poprP�releaser^r�rdr�r/�memoryview_from_bufferrerf�UnicodeEncodeErrorrhrc)
r>r7�ndmrrrrrGrYr�r�r<r<r=�test_ndarray_exceptionsgs��������z*TestBufferProtocol.test_ndarray_exceptionscCs�ttd��D]F}dgd}tgd�dgtd�}t|�|d<tdd�D]}|jgd�dgd�t|�||<q"td�D]
}|||��q9|�t|j	�~qdS)Nr�rr�r9r�r+r")
rrdrr�rPr�r�r�r`r�)r>�permrGr7rr<r<r=�test_ndarray_linked_lists
�z+TestBufferProtocol.test_ndarray_linked_listcCsLtd�D]\}}}t�|�}t|d|d�}|j|d||dddd|d�	qdS)Nrr<rHT�rZr�r9rVr�r�r�re)rzr6r�rrz)r>r9�scalarrpr�r7r<r<r=�test_ndarray_format_scalars
��z-TestBufferProtocol.test_ndarray_format_scalarc
Csltdd�}t|�D]*\}}}t�|�}dtfD]}t||g||d�}|j|d||dd|f|f|d�	qq	dS)Nr+rhrrGTr�)rrzr6r�r�rrz)r>rwr9rrrpr�rr7r<r<r=�test_ndarray_format_shapes


���z,TestBufferProtocol.test_ndarray_format_shapecCs�tdd�}t|�D]V\}}}t�|�}tdd�D]F}|dkrqt|dd|��g}||g}|dkr8||dnd}	dtfD]}
t|||||	|
d�}|j|d||dd|||dd|�d�	q>qq	dS)	Nr+����r�rr�Tr�)	rrzr6r�rdr`r�rrz)r>rwr9rrrpr�r�r�r�r�rr7r<r<r=�test_ndarray_format_strides+s*


�����z.TestBufferProtocol.test_ndarray_format_stridescCs@gd�}t|ddd�}t|ttBd�}|�|��t|d��dS)Nr�r�)r+r9r�r~)rr�r�rUr/r�)r>rrrYr7r<r<r=�test_ndarray_fortran@sz'TestBufferProtocol.test_ndarray_fortrancCsXtd�D]�}dd�t|�D�}t|�}t|�D]�}t|�\}}}t�|�}dtfD]~}	|dkr4|	tkr4q)t||||	d�}
t|||d�}t	||�}|j
|
d||d||||d�	t|�r�t|||d	�}
t|
tt
Bd
�}
|�|
jdk�|
��}|j
|d||d||||d�	t||||	tBd�}
t|||d�}t||�}|j
|
d||d||||d�	q)qqdS)
Nr�cSsg|]}tdd��qS)r rhrrr<r<r=r�Hrz<TestBufferProtocol.test_ndarray_multidim.<locals>.<listcomp>rrGr�Tr�rHr~r<rE)rdr�rrur6r�r�rr�r�rzr}r�r�rgr�r�rdr�)r>r��shape_trwr�r9rrrpr�rr7r�rerY�mvr<r<r=�test_ndarray_multidimFsP

���
����z(TestBufferProtocol.test_ndarray_multidimcCs�tdgdgd�}|�t|jdd�t|�}|�||�|�t|jdd�tdgdgtd�}|�t|jd�t|�}|�||�|�t|jd�tdgdgtd�}|�t|j	d�|�t|jdd�t|�}|�||�|�t
|j	d�|�t
|jdd�gd�}t|t|�gdtd�}|�tj
|jd	d
�|�t|jdd�t|�}|�||�|�t|jd	d
�|�t|jdd�gd�}t|t|�gd
td�}|�t|jd	d
�|�tj
|jdd�dS)Nr+r"r4r�r*�r+r r9rr�rr5r4rrGr i,)r���)�r+r r�)r�r�LQ)s1r�)rr�r0�__setitem__rPrUr�__delitem__r��__getitem__�
IndexErrorr`r6r8r�)r>r7r�rrr<r<r=�test_ndarray_index_invalidss:z-TestBufferProtocol.test_ndarray_index_invalidcCsJtddtd�}t|�}|�||�|d}|�|d�|d}|�|��|���|d}|�|d�|d}|�|��|���|�t|jd�|�t|jd�|�t|jdd�|�t|jdd�|�|��d�|�|��d�d|d<|�|��d�d|d<|�|��d�d|d<|�|��d�d|d<|�|��d�dS)	Nr+r<r�.rr4r�r�)	rrrPrUr/r�r0r�r�)r>r7r�r[r<r<r=�test_ndarray_index_scalar�s"z,TestBufferProtocol.test_ndarray_index_scalarcCsRtttd��ddgtd�}t|td�}|�t|jd�|�t|jtddd��dS)	Nr4r rr�r~r+r9r�)	rr�rdrr�r�r`r�r�)r>rYr7r<r<r=�test_ndarray_index_null_strides�sz2TestBufferProtocol.test_ndarray_index_null_stridescCs�td�D]_\}}}t|dg|d�}tdd�D]}|�||||�q|�t|jd�|�t|jd�t|�rct|�}|�||�tdd�D]}|�||||�qF|�t|jd�|�t|jd�qtd�D]K\}}}t|dgt	|d�}t|t
tBd�}tdd�D]}|�||||�q�t|�r�|��}|�
|�|�t�tdd�D]}|�||||�q�qhgd�}t|dgd�}t|td�}tdd�D]}|�||||�q�gd�}t|dgd�}t|td�}tdd�D]}|�||||�q�dS)	Nr�rHr����rQr~r�r")rzrrdrUr�r�r�r}rPrr�r�r�rT�__eq__�NotImplementedr�r�)r>r9rrrpr7rr�rYr<r<r=�!test_ndarray_index_getitem_single�sH���z4TestBufferProtocol.test_ndarray_index_getitem_singlecCs�td�D]x\}}}t|dg|td�}td�D]
}|||<|||<q|�|��|�|�t|jd|�|�t|jd|�t	|�s@qt|dg|td�}t
|�}|�||�td�D]
}|||<|||<qW|�|��|�|�t|jd|�|�t|jd|�qtd�D]f\}}}t|dg|td�}tdd�D]}||d||<||d||<q�|�|��|�t	|�s�q�t|dg|td�}t
|�}|�||�tdd�D]}||d||<||d||<q�|�|��|�q�dS)Nr�rGr�r�rr+)rzrrrdrUr/r�r�r�r}rP)r>r9rr�single_itemr7rr�r<r<r=�!test_ndarray_index_setitem_single�sF

�z4TestBufferProtocol.test_ndarray_index_setitem_singlec

Cs�d}t|�}t|�D]�}t|�\}}}dtfD]�}t||||d�}t||�}	t|d|d�D]J}
|�|	|
||
���t|d|d�D]1}|�|	|
|||
|���t|d|d�D]}|�|	|
||||
||�qdqHq0t||||t	Bd�}t
||�}	t|d|d�D]I}
|�|	|
||
���t|d|d�D]0}|�|	|
|||
|���t|d|d�D]}|�|	|
||||
||�q�q�q�qq
dS)N�r r9r�rrGr+r )r�rrur�rr�rdrUr/rdr�)
r>r�rwr�r9rrrprr7rerr��kr<r<r=�#test_ndarray_index_getitem_multidims<
 &���
 &�����z6TestBufferProtocol.test_ndarray_index_getitem_multidimcCs�tddd�}|�ttdt��t|�}|�||�|�ttdt��td�D]E\}}}t|dg|d�}t|�D]\}}|�|||�|�	||v�q7t
|�rkt|�}t|�D]\}}|�|||�|�	||v�qWq&dS)Nr+r<r"z1 in ndz1 in mvr�rH)rr�r0�eval�localsrPrUrzrrgr})r>r7r�r9rrrprr�r<r<r=�test_ndarray_sequence:s"��z(TestBufferProtocol.test_ndarray_sequencec	Cs�gd�}t|dgtd�}t|�}|�t|jtddd�|�|�t|jtddd�|�t|dgtd�}t|dgtd�}t|td�}|�t|jtddd�|�t|dgdtd�}t|�}|�t	|j
tddd��|�t	|j
tddd��t|d	d
gdtd�}t|�}|�t	|j
tddd�tddd�f�|�t	|j
tddd�tddd�f�|�t|j
d�|�t|j
dtddd�f�|�t|j
tddd�if�|�t|j
tddd�tddd�f�|�t|j
d�t|dgdtd�}t|dgd
d�}t|�}t|�}|�t	|jtddd�|dd��|�|�
�|�|�t	|jtddd�|dd��|�|�
�|�t|dgdtd�}t|dgdd�}	t|�}t|�}|�t	|jtddd�|dd��|�|�
�|�|�t	|jtddd�|dd��|�|�
�|�t|d	d
gd
td�}t|dgd
d�}t|�}t|�}|�t	|jtddd�|dd��|�|�
�gd�gd�g�|�t|jtddd�|dd��t|dgd
td�}t|dgd
d�}t|�}t|�}|�t	|jtdd	d�|dd��|�|�
�|�|�t	|jtdd	d�|dd��|�|�
�|�|�tttddd	�i�|�ttdd�|�t	ttddd�d
�t|dgd
td�}
|�t|
j�t|dgdd�}t|td�}
|�t|
j�dS)Nr�r4r�rr+r~rrGr rz@%$rrrHr5r�)r�rr5r4z###########)rrrPr�r0r�r�r�r`r�r�r1rUr/r�r��add_suboffsetsr�)r>rr�xl�mlrY�xrr7r��mr�yrr[r<r<r=�test_ndarray_slice_invalidMs�
�
�
�"""""
�""z-TestBufferProtocol.test_ndarray_slice_invalidcCsgd�}t|dgdtd�}t|dgdd�}|dd�|dd�<|�|��|�t|�}t|�}|�||�|�||�|dd�|dd�<|�|��|�t|ddgdtd�}t|ddgdd�}|d	d
�dd�f|d	d
�d
d
�f<|�|��t|ddg��dS)Nr�r�rrGrHr�rr9r+r )rrrUr/rPr�)r>rrr[rwr�r�r<r<r=�test_ndarray_slice_zero_shape�s$z0TestBufferProtocol.test_ndarray_slice_zero_shapec
Csd}t|�}t|�}t|�D]z}t|�\}}}t�|�}dtfD]g}	t||||	d�}
t||�}t	||�D]R}d}
zt
||�}WntyT}z	|j}
WYd}~nd}~wwd}z|
|}Wntyr}z	|j}WYd}~nd}~ww|sw|
r~|�
||
�q4|�|��|�q4q qdS�Nr�rrG)r`r�rrur6r�r�rr�r*r��	Exception�	__class__rTrUr/)r>r�r�rwr�r9rrrpr�rr7rer��listerrr@�e�nderr�ndslicedr<r<r=�test_ndarray_slice_multidim�s<

�������z.TestBufferProtocol.test_ndarray_slice_multidimcCs,d}t|�}t|�}t|�D]�}t|�\}}}t�|�}t|||d�}	|	��t|||d�}
|
��t|
�}t	||�}t
||�D]R}
d}zt||
�}Wnty`}z	|j
}WYd}~nd}~wwd}z|	|
}Wnty~}z	|j
}WYd}~nd}~ww|s�|r�|�||�q@|�|��|�q@qdS)N)r r9r�r rH)r`r�rrur6r�rr�rPr�r*r�r�r�rTrUr/)r>r�r�rwr�r9rrrpr�r7rYr�rer�r�r@r�r�r�r<r<r=�'test_ndarray_slice_redundant_suboffsets�s@

������z:TestBufferProtocol.test_ndarray_slice_redundant_suboffsetscCstd�D]�\}}}td�D]�}td�D]�}dtfD]�}|tB}t|dg||d�}t|dg||d�}	t|	�}
d}d}|dd�}
z|
|}|
|}|
||
|<t|�t|�k}Wntyl}z	|j}WYd}~nd}~wwd}z||||<Wnty�}z	|j}WYd}~nd}~ww|r�|�	|t
�n|�|��|
�|�	||�t
|�s�qd}z|
||
|<Wnty�}z	|j}WYd}~nd}~ww|r�|�	|t
�q|�|
��|
�|�|
|�|�	||�|j|
|	|j|d|j|j|j|��d�	qqq
qdS)Nr�rrGFr�)rzr r�rrrPr`r�r�rTr�rUr/r}rzr�r�r�r�)r>r9rrrp�lslicer&rrr7rYr��lsterr�diff_structurere�lval�rvalr�r��mverrr<r<r=� test_ndarray_slice_assign_single�sl�����������z3TestBufferProtocol.test_ndarray_slice_assign_singlec
Cs$d}t|�}t|�}t|�D]�}t|�\}}}dtfD]s}tt�D]l}t||�\}	}
t||||t	Bd�}t
||�}d}
z	t|||	|
�}WntyY}z	|j
}
WYd}~nd}~wwd}z||
||	<Wntyy}z	|j
}WYd}~nd}~ww|s~|
r�|�||
�q!|�|��|�q!qqdSr�)r`r�rrur�rd�
ITERATIONSr�rrr�r�r�r�rTrUr/)r>r�r�rwr�r9rrrprr�r�r7rer�r[r�r�r<r<r=�"test_ndarray_slice_assign_multidim3s@�
�������z5TestBufferProtocol.test_ndarray_slice_assign_multidimc
Cs4tt�D]�}tdD]�}t�|�}t|dttd�}|�t	|��t
||�}t|||�}|��}t
|�}t|�rA|��}	|�|	|�|ddkrqt|||td�}
|
��}|�||�t
|
�}t|�rq|�||
�|��}	|�|	|�tr�|d}d|vr|q
t|||�}
|j|d|
j|d|
j|
j|
j|
��d	�	q
qdS)
Nr@T�r�r�r rr�r9Fr�)rdrrTr6r�r��MAXDIM�MAXSHAPErgr�r�rr/rPr}rUr�r	rrzr�r�r�r�)r>rpr9r�ryrrr[�xlistr��mvlistrw�ylistr��zr<r<r=�test_ndarray_randomTsH
�
����z&TestBufferProtocol.test_ndarray_randomcCs�tt�D]j}tdD]c}t�|�}t|dttd�}|�t	|��t
||�}d}zt|||�}WntyD}z	|j
}WYd}~nd}~ww|�|�trmd}	zt|||�}
Wntyk}z	|j
}	WYd}~nd}~ww	q
qdS)Nr@Fr
)rdrrTr6r�r�rr�assertFalser�r�rr�r�rgr	r)r>rpr9r�ryrrr�r[r��	numpy_errrwr<r<r=�test_ndarray_random_invalid}s8
�
��
�����z.TestBufferProtocol.test_ndarray_random_invalidc
Cs*tt�D�]
}tdD�]}t�|�}tttd�\}}}}t|d|d�}t|d|d�}	|�	t
|��|�	t
|	��t||�}
t||	�}t|
||�}t|||	�}
|
|||<|�
�}|
�
�}t|�}t|
�}|�|�
�|�|�|�
�|�|ddkr�|	ddkr�t|
||td�}t|||	td�}||||<|�
�}|�
�}|�||�|�||�t|�}t|�}|�|�
�|�|�|�
�|�t�rd|vs�d|vr�qt|
||�}t|||	�}||||<t|�s�t|	�s�|j|d|j|d|j|j|j|�
�d	�	|j|
d|j|d|j|j|j|�
�d	�	qqdS)
Nr@r
Tr"r rr�Fr�)rdrrTr6r�r�rrr�rgr�r�rr/rPrUr�r	rr�rzr�r�r�r�)r>rpr9r�r�r�r�r��tl�tr�litems�ritemsr�r��xllist�xrlistr�r��ylr��yllist�yrlist�zl�zrr<r<r=� test_ndarray_random_slice_assign�sh


�


�
����z3TestBufferProtocol.test_ndarray_random_slice_assigncCsvgd�}t|ddgtd�}t|�}|�|jt@�|�|j|�|�|jd�|�|j	�|�|j
�|�|j�dS)Nr�r9rr�)rr�)rr�rgrrTrZrUr3rr�r�r�)r>rrr7rYr<r<r=�test_ndarray_re_export�sz)TestBufferProtocol.test_ndarray_re_exportc	Cs�dtfD]n}tgd�dg|d�}t|�}|�||�|�|��g�|�|��g�tgd�gd�|d�}|�|��g�tgd�gd�|d�}|�|��gggg�tgd�gd�|d�}|�|��ggggggggggggg�qdS)Nrr�r��rr9r9�r9rr9)r9r9r�r�rrPrUr/�r>rr7r�r<r<r=�test_ndarray_zero_shape�s
��z*TestBufferProtocol.test_ndarray_zero_shapecCsddtfD]+}tdgdgdg|d�}t|�}|�||�|�|��gd��|�|��gd��qdS)Nrr+r�r�)r+r+r+r+r+r$r%r<r<r=�test_ndarray_zero_strides�s�z,TestBufferProtocol.test_ndarray_zero_stridescCs>tttd��dgdd�}|�|jd�|�|��gd��dS)N�r9r5r�)r5r4r�)rr�rdrUr�r/�r>r7r<r<r=�test_ndarray_offsetsz&TestBufferProtocol.test_ndarray_offsetcCs>dtfD]}tttd��dg|d�}|��}|�||�qdS�Nrr9r�)r�rr�rdr�rU)r>rr7rGr<r<r=�#test_ndarray_memoryview_from_buffers
�z6TestBufferProtocol.test_ndarray_memoryview_from_buffercCsPdtfD]!}tttd��dg|d�}td�D]}|�||t||g��qqdSr+)r�rr�rdrUr^)r>rr7rr<r<r=�test_ndarray_get_pointers��z+TestBufferProtocol.test_ndarray_get_pointercCs\tttd��gd�d�}t|ttBd�}|�|��|���t|�}|�|��|���dS)Nr()r r r�r"r~)rr�rdr�r�rUr/rP)r>rYr7rGr<r<r=� test_ndarray_tolist_null_stridess
z3TestBufferProtocol.test_ndarray_tolist_null_stridescCs�|�tdd��tttd��ddgd�}tttd��ddgd�}|�t||��tdgdgdd	�}|�t|d
��|�td
|��dS)Nr�s456r�r9rr"r+rrHrS)rrhrr�rdrg)r>r[rwr<r<r=�test_ndarray_cmp_contigsz*TestBufferProtocol.test_ndarray_cmp_contigcCs�t�dgd��}t|�}|�tt|�tttd���}tttd��dgd�}|�t|�t|��tttd��ddgd�}|�t|�t|��tttd��gd�d�}|�t|�t|��tt	ttd��ddgd��}tttd��ddgt
d�}|�t|�t|��tt	ttd��gd	�d��}tttd��gd	�t
d�}|�t|�t|��tttd���}tttd��gd
�td�}|�t|�t|��tttd��gd
�dd�}|�t|�t|����dS)Nrr�r�r"r9r)r9r r r��r r9r �r r r9rH)
rNrr�r��hashrUr�rdrUr�rdr�r)r>rIr7rr<r<r=�test_ndarray_hash&s*z$TestBufferProtocol.test_ndarray_hashc
Cs8tttttttttt	t
tf}|�t
tidt�tdddtd�}dD]}|D]}t|||�}|�||���q%q!tdgdgdtd�}dD]}|D]}t|||�}|�|d	�qGqCtttd
��gd�dtd�}dD]}|D]}t|||�}|�|d	�qkqgdtfD]O}tdgdgd|tBd�}|��}dD]}|D]}t|||�}|�||�q�q�tgd
�dgd|tBd�}|��}dD]}|D]}t|||�}|�||�q�q�qtgd
�dgdgtd�}|��}dD]}ttfD]}t|||�}|�||�q�q�|ddd�}|��}dD]#}|D]}zt|||�}Wnt�yY�qw|�||��q�qttd��}dtfD�]U}t|ddg|tBd�}t�rVtt|�ddgd|dk�rRdndd�}	|tk�rntt|ddg�ddgtd�}
|
��}n|��}|D]B}zt|d|�}Wnt�y�Y�qtw|�||�tdd�|D�ddgtd�}|�t|�t|��t�r�|�||	jdd���qt|dk�r�tt|ddg�ddgtd�}
n	t|ddgtd�}
|
��}tttttfD]D}zt|d|�}Wnt�y�Y�q�w|�||�tdd�|D�ddgttBd�}|�t|�t|��t�r"|�||	jdd���q�|tk�r7t|ddgtd�}
|
��}n|��}tttttfD]D}zt|d|�}Wnt�yWY�qBw|�||�tdd�|D�ddg|tBd�}|�t|�t|��t�r�|�||	jdd���qB�q2tttd��ddgttBd�}t|dt�}|�||���tdd�|D�ddgtd�}|�t|�t|��t|dt�}tt|ddg�ddgtd�}
|�||
���td d�|D�ddgttBd�}|�t|�t|��t|dt�}|�||���td!d�|D�ddgtd�}|�t|�t|��dS)"NrEr�r<rrGrDr+r�r4�r rr5rr�r9rr r�r�r�rr�rr�)rr�rrScS�g|]}|�qSr<r<r�r<r<r=r��rCzCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>rRcSr6r<r<r�r<r<r=r�	rCrFcSr6r<r<r�r<r<r=r�	rCcSr6r<r<r�r<r<r=r�+	rCcSr6r<r<r�r<r<r=r�2	rCcSr6r<r<r�r<r<r=r�8	rC)r�r�r�r�r�rjr�r�r�r�r�r�r�r0rirrrUrr�rdrdr`r	rr�rP�tostringr�)
r>r�r7rS�requestrr�ndbytesre�nar[rsrwr<r<r=�test_py_buffer_to_contiguousKs������������G�
�
��
��� �

�� �� z/TestBufferProtocol.test_py_buffer_to_contiguouscCsvdgfgd�dgfttd��gd�fg}|D]�\}}t||d�}t|�}|�|j�|�|j�t|�}t||dd�}t	||�}|j
||dd	d
||||d�	t|�}	|j
|	|dd	d
||||d�	t|ttBd�}
|�
|
jd
�|
��}|j
|ddd	d
||||d�	t|td�}
|�
|
jd�|�
|
jd
�|�
|
jd
�|
��}|dkr�|gn|}|j
|ddd	d
d|jgd|d�	q|D]K\}}t||td�}t|�}|�|j�|�|j�t|�}t||dd�}t||�}|j
||dd	d
||||d�	t|�}	|j
|	|dd	d
||||d�	q�|dd�D];\}}t||td�}t|�}t|�}t	||�}|j
||dd	d
|||j|d�	t|�}	|j
|	|dd	d
|||j|d�	�q|�ttdd�|�tti�tgd�dgd�}t|td�}
|�tt|
�t|ttBd�}
|�tt|
�tdgddgddd�}
|�tt|
�|�t|
j�|�tt|
td�|�tt|
td�|�tt|
ddd�td�dS)Nr�r�r9r�r�r"r+r�rTr�r~r<r?r�r+r�rE�9r[r#rrHr�)r�rdrrPrgr�r�r`r�r�rzr�r�rUr�r�r�rr�rrdr�r�r�r�r0r`r�rerf)r>�items_shaperrr�rYrGr�r�rer�r7r<r<r=�test_memoryview_construction;	s�(
���
�
��
�
� z/TestBufferProtocol.test_memoryview_constructioncCs�gd�}gd�gd�gd�fD]}t||d�}|�|j�t|�}|�t|jd�qtdd�D]\}}}td�}|�|�}|�|�	�d�|�|�
�g�q/dS)	Nr�r"r#r"rr+rPr4)rrgr�rPr�r0rArzrUrr/)r>rrr�rY�msrcr9rprGr<r<r=�test_memoryview_cast_zero_shape�	s
�z2TestBufferProtocol.test_memoryview_cast_zero_shapecCs�|j}tj}d}d}ttd��}|td�||d|��t|ddgdd	�}|t|�||d|��t|gd
�dd	�}|t|�||d|��dS)NzPnin 2P2n2i5P P�3nr4r4r+r rrrH)r r r r9)�check_sizeofr�calcvobjsizer�rdrPr)r>�check�vsize�base_struct�per_dimrrrIr<r<r=�test_memoryview_sizeof�	sz)TestBufferProtocol.test_memoryview_sizeofcCs�Gdd�dt�}Gdd�dt�}dd�}|d�|d�dtd	�d
tdd�gd
�hd�ddidddddtddtd�td�dddd|dd�g}tdd�D]�\}}}t|dg|td�}t|dg|td�}	t|�}
t	�
||	d|�||
d<|�|
d|	d�t	�|�}d|vr�qI|D]W}d}
z
t	�
||	||�Wn
t	j
y�t	j
}
Ynwd}z||
d <Wnttfy�}z	|j}WYd}~nd}~ww|
s�|r�|�|
d�|�|d�q�|�|
d |	d �q�qIdS)!Nc@�eZdZdd�Zdd�ZdS)z=TestBufferProtocol.test_memoryview_struct_module.<locals>.INTcS�
||_dSr���val�r>rMr<r<r=�__init__�	r�zFTestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__init__cS�|jSr�rLr=r<r<r=�__int__�	�zETestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__int__N)�__name__�
__module__�__qualname__rOrQr<r<r<r=�INT�	�rVc@rJ)z=TestBufferProtocol.test_memoryview_struct_module.<locals>.IDXcSrKr�rLrNr<r<r=rO�	r�zFTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__init__cSrPr�rLr=r<r<r=�	__index__�	rRzGTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__index__N)rSrTrUrOrXr<r<r<r=�IDX�	rWrYcSsdS)Nr5r<r<r<r<r=r�	�z;TestBufferProtocol.test_memoryview_struct_module.<locals>.fr�y������@@z-21.1gffffff(@r�r r�>rr�rr5r4r<�r�TF�asabcrI�abccSs|Sr�r<)r[r<r<r=�<lambda>�	rZzBTestBufferProtocol.test_memoryview_struct_module.<locals>.<lambda>rhrPrGrrr+)�objectr	r
�EllipsisrrzrrrPr6rrUr�r8r0r�r��assertIsNot)r>rVrYr�valuesr9rrrsrYr7rGr�r��
struct_err�mv_errr�r<r<r=�test_memoryview_struct_module�	sR�

�����z0TestBufferProtocol.test_memoryview_struct_modulecCs>tgd�dgdgd�}|�|j�t|�}|�t|jd�dS)Nr�r9rr�r)rrr�rPr�r0rA)r>rYr@r<r<r=�!test_memoryview_cast_zero_strides	
sz4TestBufferProtocol.test_memoryview_cast_zero_stridesc	Cs2tD]C}td�rd|n|}t�|�}tD]/}td�rd|n|}t�|�}tttd��d|g|d�}t|�}|�t	|j
|d|g�qqtd�D]@\}}	}
t|	dg|d�}t|�}td�D]*\}}
}
t|�su|�t
|j
|d|g�q_t|�s�t|�s�|�t	|j
|d|g�q_qJt�d�}t�d�}tttd|��dd|gdd�}t|�}|jt	|j
dd|gdd�tttd	��gd
�d�}t|�}
|�t	|
j
�|�t	|
j
ddd�|�t	|
j
i�|�t
|
j
d
�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�tddgdgdd�}t|�}
|�t|
jd�|�t|
jdd�|�t|
j�tttd	��gd
�d�}t|�}
|jt	|
j
did�tttd	��d	gd�}t|�}
|jt|
j
ddgd�|jt
|
j
ddgd�|jt
|
j
dgd�d�|jt
|
j
dgd�d�|jt	|
j
dgd �d�ttd!d"�td#�D��gd$�d�}t|�}
|jt	|
j
d%gd&�d�tttd'��d'gd%d�}t|�}
|�t
|
j
d%dgd'�ttd(d"�td#�D��d#gd�}t|�}
|jt	|
j
d%gd&�d�ttd)d"�td#�D��d#gd�}t|�}
|jt	|
j
dgd&�d�tttd'��d'gd%d�}t|�}tttd'��d'gdd�}t|�}tjd*k�rv|�t	|j
dgd+��|�t
|j
dgd,��|�t
|j
d%gd-��dS|�t	|j
ddd.g�|�t
|j
dgd/��|�t
|j
d%gd0��dS)1Nr r@r0rHr+rrr�xr�r"r9�Xz@Xz@XYz=Bz!Lz<Pz>l�BI�xBIr�r��IIrr4rr*r�)r r9rr�rr5r�)r r9rr�rr5r)r r9rr�rr5r[cSrBr[r<rr<r<r=r�^
rCzCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>i�)r9r�r5r�r)r r9rr�r#cSrBr[r<rr<r<r=r�h
rCcSrBr[r<rr<r<r=r�m
rCl����)r5r5�Ir-iQiAji��	)�rm�rnr4)rmrmrnrnr ��)rnrnr0r0r )rnrnr0r4r )�NON_BYTE_FORMATrr6r�rr�rdrPr�r0rArzr}r�r{r1r�r�r/r�r4�maxsize)r>�sfmt�sformat�ssize�dfmt�dformat�dsizerYr@�sitemsrp�size_h�size_drGr7r�r�r<r<r=�test_memoryview_cast_invalid
s�

�����


 "  ������z/TestBufferProtocol.test_memoryview_cast_invalidcsjddd�fddd�fddd�ff���fdd	�}t�d
�}tdgd
d�}t|dd
�\}}t|�}|�d�}�j||d
ddd
|d|dd�
t�d
�}tdg||gdd�}t|d
|gd�\}}t|�}|jd
gd�}�j|||d
dddd|dd�
tdd�D]\}	}
}t�|	|
�}t|�}||||
|	�q}tdd�D]\}	}
}t|
dg|	t	d�}t|�}||||
|	�q�dS)NrcSst|���Sr��r�r�rYr<r<r=r^�
sz9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>rcS�dd�t|���D�S)NcSs g|]}|dkr|dn|�qS)r-r"r<r�r<r<r=r��
s �MTestBufferProtocol.test_memoryview_cast.<locals>.<lambda>.<locals>.<listcomp>r|r}r<r<r=r^�
rrcSr~)NcSsg|]	}tt|�d��qS)zlatin-1)rU�chrr�r<r<r=r��
srr|r}r<r<r=r^�
rc

s�t�|�}�D]?\}}|�|�}||�}�j||d|ddd|gd|dd�
|�|�}	��|	|�|��}�j|	|||dddg|f|dd�
qdS)Nr+Fr1r<T�	rZr�r9rVr�r�r�rerA)r6r�rArzrUr/)
rYrGrrr9�srcsizerQ�to_bytelistr�re�m3��bytespecr>r<r=�iter_roundtrip�
s$

�

��z?TestBufferProtocol.test_memoryview_cast.<locals>.iter_roundtriprr�rHr+Tr<r�r"rr<r1rNrPrG)
r6r�rrrPrArzrzrNr)r>r�r�rY�	destitems�	destshaperGr��destsizer9rrrpr<r�r=�test_memoryview_cast�
sD


�

�
��z'TestBufferProtocol.test_memoryview_castcCs�t�D]�}tdD]�}|dkrq	dtd�|}t�|�}t|�|}t|�r)dnd}t||�D]�\}}}	t�|�}
|dkrA|gng}||
g}t|||d�}
t	|
�}t
|
|||d	�\}}|durk|�t|j
||�q0|d
krpq0t|||d�}|j
||d	�}t|�}|j}|��}|j||
||d||||dd�
|�
|�}|j
||d	�}t|�}|
j}|
��}|j||
|
|d||||dd�
|j||
|
|d||||dd�
q0q	qt�r`Gd
d�dtj�}|dd�}t	|�}|�
d�}|�|j|�|�|jd�|�|jd�|�|jd�|�|j|jf�|�|jd�|�|jd�t�d�}t	|�}|�
d�}|�|j|�|�|jd�|�|jd�|�|jd�|�|j|jf�|�|jd�|�|jd�dSdS)Nr@r
)r?r@r rPrQrrHr"rTr�c@s eZdZdejfdejfgZdS)z>TestBufferProtocol.test_memoryview_cast_1D_ND.<locals>.BEPointr[rwN)rSrTrU�ctypes�c_long�c_double�_fields_r<r<r<r=�BEPoint�
�r�r�g33333i@rr+Fr<r<�333333�?r)rrTrr6r�r�r{rzrrPrr�r0rAr`r�r/rzr��BigEndianStructurerUrZr�rTrVr�r�rr3r�)r>�_tshaperY�tfmt�tsizerrZr9rrrp�sizer��tshaperYrG�titemsr7r�r�r�rer��m4r��pointr�r[r<r<r=�test_memoryview_cast_1D_ND�
s�



�
����6



�z-TestBufferProtocol.test_memoryview_cast_1D_NDcCs2t�dttdd���}t|�}|�||�|�|��|���|ddd�}|ddd�}|�||�|�|��|���tttd��gd�dd	�}t|�}|�|��|���td
dgdgdd	�}t|�}|�t|j�td
gdgdd	�}t|�}|�t|j�tgd�ddgdd	�}t|�}|�t|j�dS)Nrr�rr r9i	)r�r r5r9r�rrH)r r�)r5r�r:�12345r+r�)r\�b�c�d�e�f)	rNr�rdrPrUr/rr�r1)r>rIrGrYr<r<r=�test_memoryview_tolists(z)TestBufferProtocol.test_memoryview_tolistcCsHttd��}|��}|�|�d��|��|��}|�|�d��dS)Nr�z<memoryz	<released)rPr�__repr__rg�
startswithr�)r>rGr�r<r<r=�test_memoryview_repr3sz'TestBufferProtocol.test_memoryview_reprcCs|dD]%}td�}t�|d|dg�}t|�}|�d|�|�d|�|�d|�qtdgdd�}t|�}|�ttdt��dS)	N)rrg���?g@g"@rr�z9.0 in m)	�floatrNrP�assertInrr�r0r�r�)r>r9�infrYrGr<r<r=�test_memoryview_sequence<sz+TestBufferProtocol.test_memoryview_sequenceccsN�|�t��}dVWd�n1swY|�t|j�d|f�dS)Nz#index out of bounds on dimension %d)r�r�rU�str�	exception)r>�dim�cmr<r<r=�assert_out_of_bounds_errorJs���z-TestBufferProtocol.assert_out_of_bounds_errorc	CsFtdgdd�}t|�}|�|dd�|�|d|�|�|d|�|�t|jd�tdgdd�}t|�}|�t|jd�tttd	��d	gt	d
�}t|�}|�t
|jd�|�t|jd�|�t|jd
�|�t
|jd�|�t
|jd�tttd��ddgt	d
�}t|�}|�|dd�|�|dd�|�|dd�|�|dd�|�|dd�dD]}|jdd��||dfWd�n1s�wYq�dD]}|jdd��|d|fWd�n1s�wYq�|�t
|jd�|�t
|jd�|�t|jd �|�t|jd!�|�t|jd�|�t|jd�dS)"N�)@rrHr<.rr��iiir5r�r*�@����r4r�r9r�rr)r rr�r��r�r�)r�r��r9r�r+�r��rr�r �r*rr)�rrr�r�r�)rrPrUr�r0r�r1r�rdrr�r�)r>rYrG�indexr<r<r=�test_memoryview_indexQsN����z(TestBufferProtocol.test_memoryview_indexc	Cs�tdgdtd�}t|�}d|d<|�|dd�d|d<|�|dd�|�t|jdd	�tttd
��d
gd�}t|�}|�t|jdd
�tttd
��d
gtd�}t|�}|�t	|jdd�|�t|jdd
�|�t|jdd�|�t	|jdd�|�t	|jdd�t
dD]5}|dks�|dkr�q�tgd�dg|td�}t|�}tdd�}d||<|�||d�|�||||�q�tgd�dgdtd�}t|�}d|d<|�|dd�tgd �dgdtd�}t|�}d!|d"<|�|d"d!�td#gd"gdtd�}t|�}|�t|jdd$�tttd%��gd&�td�}t|�}t
d�
�D]R\}}|dk�r+�q |dk�r2�q |�|�}|\}	}
|d'k�sE|dk�rOdd(dd(}	}
|d)k�rh|�t|jd|	d"�|�t|jdd*�|�t|jd|
��q |�d�}|�t|jdd+�tttd"��d"gd,td�}t|�}|�t|jdd"�td-gd"gd.td�}t|�}|�t|jdd"�tttd/��dd0gtd�}t|�}d1|d2<|�|dd"d1�d3|d4<|�|ddd3�d5D] }|jd"d6��d||df<Wd�n	1�s�wY�q�d7D] }|jdd6��d|d|f<Wd�n	1�swY�q|�t	|jd8d�|�t	|jd9d�|�t|jd:d�|�t|jd;d�|�t|jdddg�dS)<Nr�rrGg�6@r<g�7@.rg33333�8@r5r"r rhr�r*r�r�r�r�r�r(r4�r@rr
r�r9r�)�1�2�3r=)TFTTr+�xr�rgr�rrnrr�s���xLr�r�r�r�*)rr+�+r�r�r�r�r�r)r�r�)rrrPrUr�r0r�r�rdr�rTrrTrrrAr�r1r�)r>rYrGr9rr7r��_ranger��lo�hir�r<r<r=�test_memoryview_assign�s�
��




����z)TestBufferProtocol.test_memoryview_assignc	Cs�tttd��dgtd�}t|�}|�t|jtddd��|�t|j	tddd�t
ddg��|�t|jd�tttd��dgtd�}t|�}|�t|jtddd�tddd�f�|�t|j	tddd�tddd�ft
ddg��|�t|jtddd�if�|�t|j	tddd�ift
ddg��|�t|j	tddd�dg�dt
fD]�}tttd��dgdgdt|Bd	�}tttd
��dgdg|d�}t|�}t|�}|dd�|dd�<|dd�|dd�<|�||�|�||�|dd�ddd�|dd
�ddd�<|dd�ddd�|dd
�ddd�<|�||�|�||�|ddd�ddd�|ddd�ddd�<|ddd�ddd�|ddd�ddd�<|�||�|�||�q�dS)Nr�r�rr r+r<r�r�)r�r�r�r�r�r�r9rr�)rr�rdrrPr�r�r�r�r�rr1r0r�rU)r>rYrGrr�r�r�r�r<r<r=�test_memoryview_slice�sP
�
�
 �
��((,,�z(TestBufferProtocol.test_memoryview_slicecCs�dd�}tdd�D]�}t|d�D]�\}}}t|�D]�}t|�D]�}t�||�}t�||�}	t|	�}
|�|
|�|�|
��|���|�|
��|���|�t|
�t|��||||	|
|�d}d}z||}
||}||||<t|
�t|�k}Wnt	y�}z	|j
}WYd}~nd}~wwd}z|
||
|<Wnt	y�}z	|j
}WYd}~nd}~ww|r�|�|t�q|s�|r�|�||�q|�|
|�|�|
��|���|�|
��|���||||	|
|�qqqq	dS)Nc	Ss�t|�D]K\}}||}||}|�||�|||<||kr+|�||�|�||�n|�||�|�||�|||<|�||�|�||�|||<|||<qdSr�)rrU�assertNotEqual)	�testcaserIrrG�
singleitemrrp�ai�mir<r<r=�cmptest-s 
�z9TestBufferProtocol.test_memoryview_array.<locals>.cmptestr+r�rN)
rdrzr rNrPrUr/rr`r�r�rTr�)r>r�rr9rrr�rr&rIrrG�	array_err�have_resize�al�arr��m_errr<r<r=�test_memoryview_array+sV��������z(TestBufferProtocol.test_memoryview_arrayc	Cs�t�dgd��}t�dgd��}t|�}t|�}dD]}|�t||�|�t�|�t||�|�t�qt|�}|��|�||�|�||�|�||�t|�}t|�}|��|�||�|�||�t|�}|�|gd��tdgdgdt	d�}d	t
d
�f|d<|�t|�|�t�dd
�}t|�}|�||�|�||�tr�Gdd�dtj�}|dd�}t|�}t|�}|�||�|�||�|�||�|�
t|j�dSdS)Nrr�)r+r r5)�__lt__�__le__�__gt__�__ge__r�r+zl x d xrGr�rr�ur�c@� eZdZdejfdejfgZdS)zITestBufferProtocol.test_memoryview_compare_special_cases.<locals>.BEPointr[rwN�rSrTrUr�r�r�r<r<r<r=r��r�r�r�r�)rNrPrT�getattrr�r�rUr�rrr�r�r�r�r1r/)	r>rIrr��w�attrr7r�r�r<r<r=�%test_memoryview_compare_special_casesisH
�z8TestBufferProtocol.test_memoryview_compare_special_casescCsntdgdd�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�|�|�|��|�|�|��d|d<|�||�|�||�|�||�|�||�|�||�|�||�|�|�|��|�|�|��ttt	d��dgtt
Bd	�}ttt	d��dgtt
Bd	�}t|�}|�||�d
|d<|�||�tdgd
d�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�tdgd
d�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�|�||�|�||�dS)N��@LrHrrGi�r<r�r�r�r�)r�r�r��Lf5s�hf5s)i?���r�r�)rrrPrUr�__ne__r�r�r�rdr�)r>�nd1�nd2r�r�r7rYrGr<r<r=�!test_memoryview_compare_ndim_zero�sj��z4TestBufferProtocol.test_memoryview_compare_ndim_zerocCsXtgd�dgdd�}tgd�dgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tgd�dgdd�}tgd�dgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tgd�d	gdd�}tgd�dgdd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gd
d�}tgd�dgdd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gdd�}tgd�dgdtd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gdd�}tgd�dgdtd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��dS)N�����@�����'���r��@hrH)r�r�r�r�i�z<iz>h)r�r�r�r9r r�r�z!hz<lrGzh  0cz>  h)rrPrUr�r��r>r�r�r�r�r<r<r=� test_memoryview_compare_ndim_one�sl  � �$z3TestBufferProtocol.test_memoryview_compare_ndim_onecCs�tddgdgdd�}tddgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tddgdgdd�}tddgdgd	d�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)
N�r�rr�rHi|���i?���z= h0cz@   i�rrPrUr�r<r<r=�"test_memoryview_compare_zero_shape%
s$z5TestBufferProtocol.test_memoryview_compare_zero_shapecCs�tgd�dgdd�}tdgdgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�td	gddgd
d�}td	gdgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)N)r�r�r�r�rr�rHr�rrr�)r�r�z@ Liz!L  hr�r�r<r<r=�$test_memoryview_compare_zero_strides?
s$z7TestBufferProtocol.test_memoryview_compare_zero_stridesc
Cs�d}tdD]7}t|dd|�\}}}dtfD]&}t||g||d�}t|�}|�||�|ddd�}t|�}|�||�qqd}td�D]4}	t|�\}}}dtfD]&}t||g||d�}t|�}|�||�|ddd�}t|�}|�||�qQqDdS)	NrhrHrPr@rrGr�r�)rTrur�rrPrUrd)
r>rrYr9rrr�rr7rGrpr<r<r=�&test_memoryview_compare_random_formatsY
s.�
��z9TestBufferProtocol.test_memoryview_compare_random_formatscCs�tttdd��gd�dd�}tttdd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�d	d�}td
gdgd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�d
d�}tttd��gd�d
d�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgdd�}tdgdddgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�d
d�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)N��r3�r9r r�r�rHrr��rr+r z=f q xxL)g333333�r+r z< f 2Qr�r�r9r5z! b B xLz
= Qx l xxLr�rr�rdrPrUr�r�r<r<r=�"test_memoryview_compare_multidim_cu
sZz5TestBufferProtocol.test_memoryview_compare_multidim_ccCs�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgd	d
dgdtd�}td
gd	d
dgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}tttd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nr�r3)r�r r9r�rGrr��rr�rr r9�=Qq)r�rz=qQr�rr��0llrJ)rr�rdrdrPrUr�r�r<r<r=�(test_memoryview_compare_multidim_fortran�
s�����������z;TestBufferProtocol.test_memoryview_compare_multidim_fortranc	CsPttdd��}t|gd��}t|gd�dd�}t|gd�dtd�}t|�}t|�}|�||�|�||�|�||�dgd	}d
|d<t|gd��}t|gd�dd�}t|gd�d
td�}t|�}t|�}|�||�|�||�|�||�tttd��ddgdd�}|ddd�ddd�f}tttd��ddgdd�}|ddd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgdd�}|ddd�ddd�f}tdgdddgdd�}|ddd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd	��gd�dd�}|dd�ddd�f}tttd	��gd�dd�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd	��gd�dd�}|dd�ddd�f}tttd	��gd�dd�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgd	gd �d!d�}|dd�ddd�f}tdgd	gd �d"d�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)#Nr�r3r��@lrHrrG)gffffff
����r�r�)g�������rr�r�zd b czd h c�(r4�@Ir9r+r�r�r)ror%�r�r z=iiz>iir�rr)r r��r�r9r �b3s�i3s)r�rdr�rrdrPrUr�)	r>�lst1�lst2r�r�r�r�r�r�r<r<r=�&test_memoryview_compare_multidim_mixed�
s�
z9TestBufferProtocol.test_memoryview_compare_multidim_mixedcCstttd��gd�dd�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dd�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nr�)rr9r rrH)r�rr z@ir�r�r<r<r=�+test_memoryview_compare_multidim_zero_shape\s$z>TestBufferProtocol.test_memoryview_compare_multidim_zero_shapecCstdgdgd�dd�}tdggd�gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�|��|���td	gd
ddgd
d�}td	gddgddgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nr�r�)rr�rr�rHr�rr�r�rhr r�z=lQrz<lQ)rrPrUr/r�r<r<r=�-test_memoryview_compare_multidim_zero_stridesvs&z@TestBufferProtocol.test_memoryview_compare_multidim_zero_stridesc	Cs^tttd��ddgdd�}|ddd�ddd	�f}tttd��ddgd
td�}|ddd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgd
td�}d|dd<|ddd�ddd	�f}tdgdddgdttBd�}d|dd<|ddd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}|dd�ddd	�f}tttd��gd�dd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�dttBd�}|dd�ddd	�f}tdgdgd�dd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}|dd�ddd	�f}tttd��gd�dtd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�dttBd�}d|ddd<|dd�ddd	�f}tdgdgd�dttBd�}d|ddd<|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�ttdd ��}t|gd��}t|gd�d!td�}t|gd�d"t	tBd�}t|�}t|�}|�||�|�||�|�||�d#gd}d$|d%<t|gd��}t|gd�d&td�}t|gd�d't	tBd�}t|�}t|�}|�||�|�||�|�||�dS)(Nrr�r4rrHr9r+r�r�rrGrr)r+r�r r5z>Qqr�r�rr�)r�r��Bbr
r)shellor4r+�)r9r9r9�5s0sP)ssushir4r+r�r3rr)ssashimisslicedg�����4@)sramensspicygfffff�"@r�z
< 10p 9p dz
> 10p 9p d)
rr�rdr�rPrUr�rr�rd)	r>r�r�r�r�r�r�r
rr<r<r=�+test_memoryview_compare_multidim_suboffsets�s�������
�z>TestBufferProtocol.test_memoryview_compare_multidim_suboffsetscCsRdD]�}tdgdgd�|dd�}tdgdgd�|dttBd�}d|d	d
ddd<t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�|dd�}tdgdgd�|dttBd�}d
|d	d
ddd<t|�}t|�}|�||�|�||�|�||�|�||�|�||�qdS)N)rCrArBrDr(rg)r9r�r r r rrHrGr+r r9)r(r&r$�QLH)r+r+r+)rrrdrPrUr�)r>�	byteorderr[rwrIrr<r<r=�!test_memoryview_compare_not_equals8����z4TestBufferProtocol.test_memoryview_compare_not_equalcCst�dgd��}t|�}|��|�tt|�|�t|jd�|�tt|�|�t|j�|�t|j�|�tt	dt
��|�t|jd�|�t|jdd�dD]
}|�t|j
|�qPt�dgd��}t|�}t|�}|�||�|��|�||�|�||�|�||�dS)Nr)g�������?g������@gffffff
@rz1.0 in mrr+)rZrrVr�rr�r�r�r3r�r�r�)rNrPr�r�r�rArr/rr�r�r�r��__getattribute__rUr�)r>rIrGr�rr�r�r<r<r=�test_memoryview_check_released/s*z1TestBufferProtocol.test_memoryview_check_releasedcsRd�t�dgdd�}t|�}|�||�|�|��|���t�gdgdd�}t|�}|�||�|�|��|���t�fdd�td	�D�gd
�dd�}t|�}|�||�|�|��|���t�fdd�td
�D�gd�dd�}t|�}|�||�|�|��|���tr�Gdd�dtj�}|dd�}t|�}|�|��t|��dSdS)Nr�r�r�rHr+z>hQiLlc�g|]}��qSr<r<r�ryr<r=r�frCz>TestBufferProtocol.test_memoryview_tobytes.<locals>.<listcomp>r�r1z=hQiLlcrr<r<rrr<r=r�krCrg)r�r r r9r z<hQiLlc@r�)z;TestBufferProtocol.test_memoryview_tobytes.<locals>.BEPointr[rwNr�r<r<r<r=r�tr�r�r�r�)rrPrUrrdr�r�rU)r>r7rGr�r�rIr<rr=�test_memoryview_tobytesWs2$�
�z*TestBufferProtocol.test_memoryview_tobytescCs�|�ttitd�|�ttdtd�tgd�dgdgd�}|�tt|td�tdd	d
d�}dD]}t|t|�}|�||�|�|d	d�q/tdd	d
td
�}dD]}t|t|�}|�||�|�|d	d�qPdD].}d|d	<t|t|�}|�||�|�|d	d�d|d	<|�|d	d�|�|d	d�qitdgdgd
td
�}dD]}t|t|�}|�t	|j
d�|�||�|�|��g�q�ttt
d��gd�d
td
�}dD]}t|t|�}|�t|���ggg�q�tdgdgdtd
�}dD]}t|t|�}|�||�|�|��|���q�tgd�dgdtd
�}dD]}t|t|�}|�||�|�|��|����qtgd�dgdgtd�}dD]2}t|t|�}|�||�|�|��|���|�t|jdd�|�|dd�|�|dd��qB|ddd�}dD]2}t|t|�}|�||�|�|��|���|�t|jdd�|�|dd�|�|dd��q~ttt
d��ddgtd�}dD]}t|t|�}|�t|���|����q�|�tt|td�t|t|�}|�t|���|���ttt
d��ddgttBd�}dD]}t|t|�}|�t|���|����q|�tt|td�t|t|�}|�t|���|���ttt
d��ddgttBd�}dD]}|�tt|t|�t|t|�}|�t|���|����qDtgd�dgdgd�}t|td�}|�|j�dS)NrEr�r�r�r r�rFr�r<rrHrDrGrhr+rr4r5rr9rr�r(r�r�rr�)r�rF)rErFr�)r�r0rerfr`�PyBUF_WRITErrUrr�r�r/r�rdr�rdr�rgr�)r>r7rSrGr<r<r=�test_memoryview_get_contiguouszs����z1TestBufferProtocol.test_memoryview_get_contiguouscCs�t�d�}t�dgd��}t|�}t�|�}td|�}|�|�|�|�	�|�t�d�}t
ttd��gd�dd�}t|�}t�|�}td|�}|�|�|�|�	�|�dS)Nrr�r�rr�r0rH)
r6r�rNrP�io�BytesIOr�readintorUrrr�rd)r>r�rIrGr
rr7r<r<r=�test_memoryview_serializing�s





z.TestBufferProtocol.test_memoryview_serializingc	Cs�tttd���}t|�}|�t|�t|��|jdddgd�}|�t|�t|��|ddd�}tttd��ddd��}|�t|�t|��tttd��gd�td	�}t|�}|�t|�t|��tttd��gd�d�}|ddd
�dd�ddd�f}t|�}|�t|�t|��tttd��gd�t	d	�}|ddd
�dd�ddd�f}t|�}|�t|�t|��tttd��dgd
d�}t|�}tttd��dgdd�}t|�}|�||�|�t|�t|��tttd��gd�dd�}t|�}|�
t|j�tttdd��gd�dd�}t|�}|�
t|j�tttd��gd�dd�}t|�}|�
t|j�tttdd��gd�dd�}t|�}|�
t|j�dS)Nr�rr9rr"r�r�r�r�r r�)r r�r9rrHrr1rr�rrz= Lz< h)
rUr�rdrPrUr2rArrdr�r�r��__hash__)	r>rrG�mc�mxr7r[rIrwr<r<r=�test_memoryview_hash
sJz'TestBufferProtocol.test_memoryview_hashcCs�tgd��}t|�}t|�}|�t|j�~|��tgd��}t|�}t|ttd�}t|ttd�}|�|j	|�|�t|j�~~|��tgd��}t|�}t|�}t|�}|��|�t|j�~|��tgd��}t|�}t|�}t|ttd�}t|ttd�}|�|j	|�|��|�t|j�~~|��tgd�dgt
d�}t|�}|jgd�dgd�t|�}t|�}|�|�
�|�
��t|�}	|�|	�
�|�
��|�|	�
�|�
��|��|	��|��|�|�
�|�
��~|��|��dd	�}
td
�}t|��}|
|�|�|dtd��Wd�n	1�s#wYtttd
��gd�dd�}t|ttd�}	t|	ttd�}|�|j	|�t|��}|
|�|�|dd��
�gd�gd�gg�Wd�n	1�sqwYdtfD�]}td
�}t|��p}~t|t|d�}	t|	��R}~	t|t|d�}t|��4}
~|
|
�|
|�|
|�|�|dtd��|�|dtd��|�|
dtd��~
Wd�n	1�s�wY~Wd�n	1�s�wY~Wd�n	1�s�wYtd
�}t|��p}~t|t|d�}	t|	��S}~	t|t|d�}t|��6}
~|
|�|
|�|
|
�|�|dtd��|�|dtd��|�|
dtd��~~~
Wd�n	1�sZwYWd�n	1�sjwYWd�n	1�szwY�qztd
�}|�t��2t|��}t|�}|dtd�kWd�n1�s�wYWd�dSWd�dS1�s�wYdS)Nr��rrr9r�)rr�rr5r4r�r"cSs.t|��	}Wd�dS1swYdSr�)rP)rr�r<r<r=�catch22�s
"�z;TestBufferProtocol.test_memoryview_release.<locals>.catch22r�rr�r�r1rrHr+r�)r9rr�r�r r�)rrPrr�r`r�rj�ND_REDIRECTrTrZr�r�rUr/r��ordr�rd)r>rIrGr7r�r�r�r�r[rwr)rrr�rYr<r<r=�test_memoryview_releaseIs�
�
(�


�	�
�


������
 ��$�z*TestBufferProtocol.test_memoryview_releasecCs0tdd�td�D�dgdd�}t�ddd�td�D��}||fD]u}t|ttd�}t|ttd�}t|�}|�|j|�|�|j|�|�|j|�|�||�|�||�|�||�|�|dd	�|dd	��|�|dd	�|dd	��|�|dd	�|dd	��~~|�|dd	�|dd	��q dS)
NcS�g|]}d|�qS�r�r<r�r<r<r=r��r�z?TestBufferProtocol.test_memoryview_redirect.<locals>.<listcomp>r�rrHcSr-r.r<r�r<r<r=r��r�r(r+r9)	rrdrNrjr*rPrTrZrU)r>r7rIr[rwrrGr<r<r=�test_memoryview_redirect�s$�z+TestBufferProtocol.test_memoryview_redirectcCs�d}gd�}|�ttddd�t�}t|�}|j||d|dddgdg|d�	td�D]
}|�|||�q*~~t�}t|�}~~t�}t|td	�}t|td	�}t|�}|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~t�}t|ttd
�}t|ttd
�}t|�}|�	|j
|�|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~tdd�}t|�}|j|dd|dddgdg|d�	td�D]
}|�|||�q�~~tdd�}t|�}~~tdd�}t|td	�}t|td	�}t|�}|�	|j
d�|�	|j
|�|j||d|dddgdg|d�	~~~~tdd�}t|ttd
�}t|ttd
�}t|�}|�	|j
d�|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~dS)Nr)rr+r r9rr�rr5r4r�rhr�r+r r9Tr�r�r~r()�legacy_mode)r�r0�staticarrayrPrzrdrUrrjrTrZr*)r>r9rer[rwrrrGr<r<r=�$test_memoryview_from_static_exporter�s�
�
�
�

�


�

�z7TestBufferProtocol.test_memoryview_from_static_exportercCs*tgd�dgttBd�}|�tt|�dS)Nr�r9r�)rr��ND_GETBUF_UNDEFINEDr�r`rPr)r<r<r=�#test_memoryview_getbuffer_undefined?sz6TestBufferProtocol.test_memoryview_getbuffer_undefinedcCs&tgd�dgtd�}|�tt|�dS)Nr�r9r�)rr�r�r`rP)r>r[r<r<r=�test_issue_7385Esz"TestBufferProtocol.test_issue_7385cCs&dD]}|�t�|�t�|��qdS)N)r?�ii�3s)rU�	_testcapi�PyBuffer_SizeFromFormatr6r�)r>rr<r<r=�test_pybuffer_size_from_formatIs
��z1TestBufferProtocol.test_pybuffer_size_from_formatN�F)UrSrTrUr?rzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr	rrr r!r&r'r*r,r-r.r/r3r;r?rArrCrIrerfr{r�r�r�r�r��
contextlib�contextmanagerr�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrrr#r'r,r/r2r4r5�cpython_onlyr:r<r<r<r=r:�s��
K0i
-'	0.Y #6!)>
		%qu
8	s<T	
5m8>5?H>Ha(#u<^r:�__main__)rNN)r�r2r<)r�r2rPr�r;r)ir<�unittest�testr�test.supportr�	itertoolsrr�randomrrr�warningsr4rNr �os�decimalr	�	fractionsr
�_testbuffer�ImportErrorrr6r��EnvironmentVarGuard�environ�catch_warningsrOr	r8�
SHORT_TEST�NATIVEr7r8�STANDARDr>rTr9�copyr|�ARRAYr��BYTEFMTrjrlrir\rcrfrtrurvrzr{r}rpr�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 r#r&r�r*r-r8rrr�
skipUnless�TestCaser:rS�mainr<r<r<r=�<module>s� ���������	���
�	
�
�

�	



	


?
+

!






o�

Youez - 2016 - github.com/yon3zu
LinuXploit