a
    "hIR                     @   s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZzd dl	Z	W n e
yf   dZ	Y n0 G dd dZG dd dejeZG dd dejeZG d	d
 d
ejeZG dd dejZG dd dejZG dd dejeZG dd dejeZG dd dejZdZejdkr$dndZG dd dZeeejkdG dd dejZdd ZG d d! d!ejeZG d"d# d#ejZG d$d% d%ejeZeje e	d&G d'd( d(ejeZ!e"d)kre#  dS )*    )supportNc                   @   s   e Zd Zdd ZdS )HelperMixinc              	   G   s   t t j|g|R  }| || zttjd$}t j||g|R   W d    n1 s\0    Y  ttjd}t |}W d    n1 s0    Y  | || W t	tj nt	tj 0 d S )Nwbrb)
marshalloadsdumpsassertEqualopenr   TESTFNdumploadunlink)selfsampleextranewf r   9/opt/python-3.9.21/usr/lib/python3.9/test/test_marshal.pyhelper   s    2(zHelperMixin.helperN)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )IntTestCasec                 C   s6   t jd }|r2| |fD ]}| | q|d? }q
d S )N      )sysmaxsizer   )r   nexpectedr   r   r   	test_ints   s
    
zIntTestCase.test_intsc                 C   s   d}| d }||| |d?  fD ]L}|r"dt j|dddd }t|}| || |dkrdd	}q&|dL }q&q"td
}| |d td}| |d td}| |d td}| |d d S )Nl    r      I   littleT)signedr   s	   IܺvT2l   \u1Q s	   I#Egl\u1Q s	   I*;L]nl   Tv0ur{ s	   Iĳl	Tv0ur{ )intto_bytesr   r   r	   )r   Zmaxint64Zminint64basesgotr   r   r   
test_int64%   s$    





zIntTestCase.test_int64c                 C   s   dD ]}|  | qd S )N)TFr   )r   br   r   r   	test_bool<   s    zIntTestCase.test_boolN)r   r   r   r!   r,   r/   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )FloatTestCasec                 C   s   d}t jd }||kr>| |fD ]}| t| q |d }qd}t|d}t|}| || t|d}t|}| || t jd }||k r| |fD ]"}t|}| | | |d q|d9 }qd S )Ng}:g6ҫsgS:^@g        r   r   gZ1%)r   r   r   floatr   r   r   r	   )r   Zsmallr   r    r   r*   r+   r   r   r   test_floatsA   s(    





zFloatTestCase.test_floatsN)r   r   r   r2   r   r   r   r   r0   @   s   r0   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )StringTestCasec                 C   s0   ddddd fD ]}|  tt| qd S N    Andrè Previnabc '  )r   r   r   r   r   r*   r   r   r   test_unicode\   s    zStringTestCase.test_unicodec                 C   s$   ddddd fD ]}|  | qd S r4   r-   r:   r   r   r   test_string`   s    zStringTestCase.test_stringc                 C   s$   ddddd fD ]}|  | qd S )N    s   Andr Previn   abc    r9   r-   r:   r   r   r   
test_bytesd   s    zStringTestCase.test_bytesN)r   r   r   r;   r<   r@   r   r   r   r   r3   [   s   r3   c                   @   s   e Zd Zdd ZdS )ExceptionTestCasec                 C   s    t t t}| t| d S N)r   r   r   StopIterationr	   )r   r   r   r   r   test_exceptionsi   s    z!ExceptionTestCase.test_exceptionsN)r   r   r   rD   r   r   r   r   rA   h   s   rA   c                   @   s2   e Zd Zdd Zdd Zdd Zejdd Zd	S )
CodeTestCasec                 C   s(   t jj}tt|}| || d S rB   )rA   rD   __code__r   r   r   r	   )r   cor   r   r   r   	test_coden   s    zCodeTestCase.test_codec                 C   s&   d}t jjf| }tt| d S )Ni  )rA   rD   rF   r   r   r   )r   countZcodesr   r   r   test_many_codeobjectss   s    z"CodeTestCase.test_many_codeobjectsc                 C   sP   t ddd}t ddd}tt||f\}}| |jd | |jd d S )Nxf1execyf2)compiler   r   r   r	   co_filename)r   Zco1Zco2r   r   r   test_different_filenamesy   s
    z%CodeTestCase.test_different_filenamesc                 C   sL   d}t |dd}tt|}|jD ] }t|tjr&| |j	|j	 q&d S )Nzdef f(): pass
def g(): passZmyfilerM   )
rP   r   r   r   	co_consts
isinstancetypesCodeTypeassertIsrQ   )r   r*   rG   objr   r   r   test_same_filename_used   s    
z$CodeTestCase.test_same_filename_usedN)	r   r   r   rH   rJ   rR   r   cpython_onlyrY   r   r   r   r   rE   m   s
   rE   c                	   @   sR   e Zd Zdddddgdddd	Zd
d Zdd Zdd Zdd Zej	dd Z
dS )ContainerTestCasezfoo@bar.baz.spamgHzns@   r   .zyx.41)
r]   r]   r]   r]   r]   r]   r]   r]   r]   r]   Fr6   )ZastringZafloatZanintZ
ashortlongZalistZatupleZabooleanZaunicodec                 C   s   |  | j d S rB   )r   dr   r   r   r   	test_dict   s    zContainerTestCase.test_dictc                 C   s   |  t| j  d S rB   )r   listr^   itemsr_   r   r   r   	test_list   s    zContainerTestCase.test_listc                 C   s   |  t| j  d S rB   )r   tupler^   keysr_   r   r   r   
test_tuple   s    zContainerTestCase.test_tuplec                 C   s&   t tfD ]}| || j  qd S rB   )set	frozensetr   r^   re   )r   constructorr   r   r   	test_sets   s    zContainerTestCase.test_setsc                 C   s&   t  }tt|}| || d S rB   )rh   r   r   r   rW   )r   rX   obj2r   r   r   test_empty_frozenset_singleton   s    z0ContainerTestCase.test_empty_frozenset_singletonN)r   r   r   r^   r`   rc   rf   rj   r   rZ   rl   r   r   r   r   r[      s   
r[   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )BufferTestCasec                 C   s6   t d}| | tt|}| t|t d S Nr>   )	bytearrayr   r   r   r   r	   typebytesr   r.   r   r   r   r   test_bytearray   s    
zBufferTestCase.test_bytearrayc                 C   s6   t d}| | tt|}| t|t d S rn   )
memoryviewr   r   r   r   r	   rp   rq   rr   r   r   r   test_memoryview   s    
zBufferTestCase.test_memoryviewc                 C   s,   t  dd}tt|}| |d d S )NBr>   )arrayr   r   r   r	   )r   ar   r   r   r   
test_array   s    zBufferTestCase.test_arrayN)r   r   r   rs   ru   ry   r   r   r   r   rm      s   rm   c                   @   st   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )BugsTestCasec                 C   s   t dgd  d S )N     )r   r   r_   r   r   r   test_bug_5888452   s    zBugsTestCase.test_bug_5888452c                 C   sF   |  ttjd |  ttjd |  ttjtdd d d  d S )N   0   fr   A   r&   )assertRaises	Exceptionr   r   r   r_   r   r   r   test_patch_873224   s    zBugsTestCase.test_patch_873224c                 C   s8   |  ttddd |  ttddd d S )N   r   r   )r	   r   r   r   r_   r   r   r   test_version_argument   s    z"BugsTestCase.test_version_argumentc              	   C   s>   t dD ]0}t|g}zt| W q ty6   Y q0 qd S )N   )rangerq   r   r   r   )r   icr   r   r   	test_fuzz   s    
zBugsTestCase.test_fuzzc                    s.   dd }|dt j  fdd}|d| d S )Nc                 S   s\   |d|  d  |d|  d  |d|  d  |d|  d d|    |d|  d  d S )Ns   )   Ns   (   s   [   s   {Nr~   s   >   r   )Ncheckr   r   r   	run_tests   s
    z4BugsTestCase.test_loads_recursion.<locals>.run_testsd   c                    s     ttj|  d S rB   r   
ValueErrorr   r   )r*   r_   r   r   r      s    z0BugsTestCase.test_loads_recursion.<locals>.checkr\   )r   r   )r   r   r   r   r_   r   test_loads_recursion   s    z!BugsTestCase.test_loads_recursionc                 C   s   g  }}t jdkrd}nd}t|d D ]}|dg |d }q(t|}t|}| t|t| | t|d t|d  | t|d t|d  |dg | 	t
tj| d S )Nntr|   i  r   r   r&   )osnamer   appendr   r   r   r	   lenr   r   )r   headlastZMAX_MARSHAL_STACK_DEPTHr   dataZnew_headr   r   r   test_recursion_limit   s    



z!BugsTestCase.test_recursion_limitc                 C   s>   t tttttttfD ]$}td|fi }| 	t
tj|  qd S )Nsubtyp)r'   r1   complexrd   ra   dictrg   rh   rp   r   r   r   r   )r   typr   r   r   r   test_exact_type_match  s    z"BugsTestCase.test_exact_type_matchc                 C   s   t d}d| }t| d S )Ng    .Ar7   )r'   r   r   )r   sizeZ
testStringr   r   r   test_large_marshal  s    zBugsTestCase.test_large_marshalc                 C   s   d}|  ttj| d S )Ns	   l       r   )r   Zinvalid_stringr   r   r   test_invalid_longs  s    zBugsTestCase.test_invalid_longsc              
   C   s$  ddddddddgff}d	D ] }t |}g }zttjd
B}|D ],}t|| |r`|| ||  qBW d    n1 s0    Y  ttjdV}t	|D ]<\}}| 
|t| |r|| | 
|| |  qW d    n1 s0    Y  W ttj qttj 0 qd S )Nr   r7   s   def      ?r   rx   r.      c)r=   s   0123r   r   )r   r
   r   r   r   r   writer   tell	enumerater	   r   readr   )r   r   ZinterleavedZilenZ	positionsr   r^   r   r   r   r   test_multiple_dumps_and_loads  s$    

.
6z*BugsTestCase.test_multiple_dumps_and_loadsc                 C   s   d}|  ttj| d S )NT)r   	TypeErrorr   r   )r   Zunicode_stringr   r   r   !test_loads_reject_unicode_strings2  s    z.BugsTestCase.test_loads_reject_unicode_stringsc              	   C   s:   G dd dt j}dD ]}| ttj|t| qd S )Nc                       s   e Zd Z fddZ  ZS )z/BugsTestCase.test_bad_reader.<locals>.BadReaderc                    s(   t  |}|d ur$|dkr$|d7 }|S )N   i@B )superreadinto)r   bufr   	__class__r   r   r   9  s    z8BugsTestCase.test_bad_reader.<locals>.BadReader.readinto)r   r   r   r   __classcell__r   r   r   r   	BadReader8  s   r   )r   y              ?s
   0123456789
0123456789)ioBytesIOr   r   r   r   r   )r   r   valuer   r   r   test_bad_reader7  s
    
zBugsTestCase.test_bad_readerc                 C   s8   t d}tt|D ]}| tt j|d|  qd S )N)helloZdollyNr   )r   r   r   r   r   EOFErrorr   )r   r   r   r   r   r   test_eofB  s    
zBugsTestCase.test_eofN)r   r   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rz      s   
rz   l        l    r#   r   c                   @   s   e Zd Zdd ZdS )
NullWriterc                 C   s   d S rB   r   r:   r   r   r   r   K  s    zNullWriter.writeN)r   r   r   r   r   r   r   r   r   J  s   r   z!test cannot run on 32-bit systemsc                   @   s   e Zd Zdd Zejeddddd Zejeddddd	 Zejee	d
 dddd Z
ejee	d
 dddd Zejee	d eed
  dddd Zejee	d eed
  dddd Zejeddddd ZdS )LargeValuesTestCasec                 C   s   |  ttj|t  d S rB   )r   r   r   r   r   )r   r   r   r   r   check_unmarshallableP  s    z(LargeValuesTestCase.check_unmarshallabler   F)r   Zmemusedry_runc                 C   s   |  d|  d S )N   xr   r   r   r   r   r   r@   S  s    zLargeValuesTestCase.test_bytesc                 C   s   |  d|  d S )NrK   r   r   r   r   r   test_strW  s    zLargeValuesTestCase.test_strr   c                 C   s   |  d|  d S )NrB   r   r   r   r   r   rf   [  s    zLargeValuesTestCase.test_tuplec                 C   s   |  d g|  d S rB   r   r   r   r   r   rc   _  s    zLargeValuesTestCase.test_list   c                 C   s   |  tt| d S rB   )r   rg   r   r   r   r   r   test_setc  s    zLargeValuesTestCase.test_setc                 C   s   |  tt| d S rB   )r   rh   r   r   r   r   r   test_frozenseti  s    z"LargeValuesTestCase.test_frozensetc                 C   s   |  t| d S rB   )r   ro   r   r   r   r   rs   o  s    z"LargeValuesTestCase.test_bytearrayN)r   r   r   r   r   Z
bigmemtest
LARGE_SIZEr@   r   pointer_sizerf   rc   r   	getsizeofr   r   rs   r   r   r   r   r   N  s*   





r   c                 C   s~   t || v rdS | t | t|ttttfrF|D ]}t| | q4n0t|trv|	 D ]\}}t| | t| | qXt
| S )z&Collect object ids seen in a structureN)idaddrT   ra   rd   rg   rh   CollectObjectIDsr   rb   r   )ZidsrX   ekvr   r   r   r   s  s    

r   c                   @   s   e Zd ZddddeddhfZdddZdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS ) InstancingTestCase{   獗n?r7   )r   r7   Fc                 C   s   ||f}t t |}tdtjd D ].}t||}t t t|}| || q$|st|d}	t t t|	}
| |
| |s| t	|	t	| n| 
t	|	t	| d S )N   r   r   )r   rg   r   r   versionr   r   r	   ZassertGreaterr   ZassertGreaterEqual)r   Zrsample	recursivesimpler   Zn0r   Zs3Zn3s2Zn2r   r   r   helper3  s    zInstancingTestCase.helper3c                 C   s    d}|  | | j|dd d S )Ni T)r   r   r   )r   Zintobjr   r   r   testInt  s    
zInstancingTestCase.testIntc                 C   s   d}|  | | | d S )Nr   r   )r   Zfloatobjr   r   r   	testFloat  s    
zInstancingTestCase.testFloatc                 C   s   d}|  | | | d S )NZabcdeabcdeabcder   )r   strobjr   r   r   testStr  s    
zInstancingTestCase.testStrc                 C   s   d}|  | | | d S )Ns   abcdeabcdeabcder   )r   Zbytesobjr   r   r   	testBytes  s    
zInstancingTestCase.testBytesc                 C   s,   | j D ] }||g}| | | | qd S rB   re   r   r   )r   rX   Zlistobjr   r   r   testList  s    

zInstancingTestCase.testListc                 C   s,   | j D ] }||f}| | | | qd S rB   r   )r   rX   Ztupleobjr   r   r   	testTuple  s    

zInstancingTestCase.testTuplec                 C   s4   | j D ](}|df|dfh}| | | | qd S Nr   r   r   )r   rX   Zsetobjr   r   r   testSet  s    

zInstancingTestCase.testSetc                 C   s8   | j D ],}t|df|dfh}| | | | qd S r   )re   rh   r   r   )r   rX   Zfrozensetobjr   r   r   testFrozenSet  s    

z InstancingTestCase.testFrozenSetc                 C   s4   | j D ](}d|d||di}| | | | qd S )Nr   goodbyer   )r   rX   Zdictobjr   r   r   testDict  s    

zInstancingTestCase.testDictc                 C   s`   t td}| }W d    n1 s(0    Y  tdrHt|td}| | | | d S Nr   z.pyrM   )r
   __file__r   endswithrP   r   r   )r   r   coder   r   r   
testModule  s    &

zInstancingTestCase.testModulec                 C   sN   d}d|d||di}||d< | j |dd ||g}|| | j |dd d S )Nr   r   r   r   T)r   )r   r   )r   rX   r^   lr   r   r   testRecursion  s    
z InstancingTestCase.testRecursionN)FF)r   r   r   rh   re   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s   
r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )CompatibilityTestCasec                 C   sb   t td}| }W d    n1 s(0    Y  tdrHt|td}t||}t| d S r   )r
   r   r   r   rP   r   r   r   )r   r   r   r   r   r   r   r   _test  s    &
zCompatibilityTestCase._testc                 C   s   |  d d S )Nr   r   r_   r   r   r   test0To3  s    zCompatibilityTestCase.test0To3c                 C   s   |  d d S )Nr   r   r_   r   r   r   test1To3  s    zCompatibilityTestCase.test1To3c                 C   s   |  d d S Nr   r   r_   r   r   r   test2To3  s    zCompatibilityTestCase.test2To3c                 C   s   |  d d S )Nr   r   r_   r   r   r   test3To3  s    zCompatibilityTestCase.test3To3N)r   r   r   r   r   r   r   r   r   r   r   r   r     s
   r   c                   @   s*   e Zd ZdZeeZdd Zdd ZdS )InterningTestCasezthis is an interned stringc                 C   sX   t t | j}| || j | t|t| j t|}| t|t| d S rB   )r   r   r   r   r	   r   r   internr   r*   r   r   r   r   
testIntern  s
    
zInterningTestCase.testInternc                 C   sZ   t t | jd}| || j | t|t| j t|}| t|t| d S r   )	r   r   r   r   r	   ZassertNotEqualr   r   r   r   r   r   r   testNoIntern  s
    
zInterningTestCase.testNoInternN)r   r   r   r   r   r   r   r   r   r   r   r   r     s   
r   zrequires _testcapic                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )CAPI_TestCasec              	   C   st   t tjd D ]`}tdtj| ttjd}| }W d    n1 sL0    Y  t	tj | 
|d qd S )Nr   xV4r   s   xV4)r   r   r   	_testcapiZpymarshal_write_long_to_filer   r   r
   r   r   r	   )r   r   r   r   r   r   r   test_write_long_to_file  s    &z%CAPI_TestCase.test_write_long_to_filec              	   C   s   ddddddd f}t tjd D ]f}t|tj| ttjd	}| }W d    n1 s`0    Y  t	tj | 
t|| q"d S )
N   €r>   r   F@      @       @z
long line r|   r   r   )r   r   r   r   Zpymarshal_write_object_to_filer   r   r
   r   r   r	   r   )r   rX   r   r   r   r   r   r   test_write_object_to_file  s    &z'CAPI_TestCase.test_write_object_to_filec                 C   s   t tjd}|d W d    n1 s,0    Y  ttj\}}ttj | |d | |d t tjd}|d W d    n1 s0    Y  | t	 ttj W d    n1 s0    Y  ttj d S )Nr   s   4xxxxi4  r      )
r
   r   r   r   r   Zpymarshal_read_short_from_filer   r	   r   r   r   r   rpr   r   r   test_read_short_from_file  s    ((*z'CAPI_TestCase.test_read_short_from_filec                 C   s   t tjd}|d W d    n1 s,0    Y  ttj\}}ttj | |d | |d t tjd}|d W d    n1 s0    Y  | t	 ttj W d    n1 s0    Y  ttj d S )Nr   s   xV4xxxxr   r   s   V4)
r
   r   r   r   r   Zpymarshal_read_long_from_filer   r	   r   r   r  r   r   r   test_read_long_from_file+  s    ((*z&CAPI_TestCase.test_read_long_from_filec              	   C   s
  d}t tjd D ]}t||}ttjd}||d  W d    n1 sR0    Y  t	tj\}}t
tj | || ttjd"}||d d  W d    n1 s0    Y  | t t	tj W d    n1 s0    Y  t
tj qd S N)r  r>   r   r  r  r   r   s   xxxx)r   r   r   r   r
   r   r   r   r   Z$pymarshal_read_last_object_from_filer   r	   r   r   r   rX   r   r   r   r  r  r   r   r   test_read_last_object_from_file9  s    ,0*z-CAPI_TestCase.test_read_last_object_from_filec              	   C   s  d}t tjd D ]}t||}ttjd}||d  W d    n1 sT0    Y  t	tj\}}t
tj | || | |t| ttjd"}||d d  W d    n1 s0    Y  | t t	tj W d    n1 s0    Y  t
tj qd S r  )r   r   r   r   r
   r   r   r   r   Zpymarshal_read_object_from_filer   r	   r   r   r   r  r   r   r   test_read_object_from_fileI  s    ,0,z(CAPI_TestCase.test_read_object_from_fileN)	r   r   r   r   r  r	  r
  r  r  r   r   r   r   r     s   	r   __main__)$testr   rw   r   r   r   Zunittestr   rU   r   ImportErrorr   ZTestCaser   r0   r3   rA   rE   r[   rm   rz   r   r   r   r   ZskipIfr   r   r   r   r   rZ   Z
skipUnlessr   r   mainr   r   r   r   <module>   sF   
$  $`
Q
