
    7bhC                     6   d dl Z d dlZd dlZd dlmZ d dlmZ d dlZd dlZ G d deej                        Z
 G d d      Z G d d	ej                        Z G d
 dej                        Z G d dej                        Zd Zedk(  r ej"                          yy)    N)support)AbstractPickleTestsc                   .    e Zd ZddZd ZdZdZd Zd Zy)OptimizedPickleTestsNc                 V    t        j                  t        j                  ||fi |      S N)pickletoolsoptimizepickledumps)selfargprotokwargss       ?/opt/python-3.12.12/usr/lib/python3.12/test/test_pickletools.pyr   zOptimizedPickleTests.dumps   s#    ##FLLe$Fv$FGG    c                 .    t        j                  |fi |S r   )r   loads)r   bufkwdss      r   r   zOptimizedPickleTests.loads   s    ||C(4((r   c                    t        d      D cg c]  }t        |       }}|j                  |d          t        t        j                  dz         D ]  }t        j
                  ||      }t        j                  |      }| j                  ||       | j                  |d   |d          t        j                  |      }t        j                  |      }| j                  ||       | j                  |d   |d          | j                  t        j                  |       | j                  t        j                  |        y c c}w )Ni     )rangestrappendr   HIGHEST_PROTOCOLr   r   assertEqualassertIsr	   r
   assertNotInLONG_BINGETLONG_BINPUT)r   idatar   pickled	unpickledpickled2
unpickled2s           r   test_optimize_long_bingetz.OptimizedPickleTests.test_optimize_long_binget   s    %c
+
1A
+DH622Q67Ell4/GW-IY-MM)B-27"++G4Hh/JZ.MM*R.*R.9V//:V//: 8 ,s   Ec                    d}| j                  t        j                  |       t        j                  |      }| j	                  |g d       | j                  |d   |d          t        j                  |      }t        j                  |      }| j	                  |g d       | j                  |d   |d          | j                  t        j                  |       y )Ns           ](spamqhamhe.)spamhamr-   r      )	assertInr   BINPUTr   r   r    r	   r
   r!   )r   r&   r'   r(   r)   s        r    test_optimize_binput_and_memoizez5OptimizedPickleTests.test_optimize_binput_and_memoize'   s    D 	fmmW-LL)	$:;ilIaL1''0\\(+
%;<jmZ]31r   r   )	__name__
__module____qualname__r   r   test_pickle_to_2x+test_framed_write_sizes_with_delayed_writerr*   r1    r   r   r   r   	   s'    H)  37/; 2r   r   c                       e Zd Zd Zd Zd Zy)SimpleReaderc                      || _         d| _        y )Nr   r%   pos)r   r%   s     r   __init__zSimpleReader.__init__C   s    	r   c                 |    | j                   | j                  | j                  |z    }| xj                  |z  c_        |S r   r;   )r   nr%   s      r   readzSimpleReader.readG   s0    yy488a<0Ar   c                     | j                   j                  d| j                        dz   }|st        | j                         }| j                   | j                  | }|| _        |S )N   
r   )r%   findr<   len)r   nlr%   s      r   readlinezSimpleReader.readlineL   sO    YY^^E488,q0TYYByy2&r   N)r2   r3   r4   r=   r@   rF   r7   r   r   r9   r9   B   s    
r   r9   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	GenopsTestsc           	          t        j                  d      }| j                  |D cg c]  }|d   j                  f|dd  z    c}g d       y c c}w )N   (I123
KJ4Vxt.r   r   ))MARKNr   )INT{   r   )BININT1      )BININT4Vx   )TUPLEN   )STOPN   )r	   genopsr   namer   ititems      r   test_genopszGenopsTests.test_genopsV   sP     BC"E"$47<</T!"X5"E H
 	Es   Ac           	      P   t        j                  d      }| j                  |j                  d      d       t	        j
                  |      }| j                  |D cg c]  }|d   j                  f|dd  z    c}g d       | j                  |j                         d       y c c}w )Ns   prefix(I123
KJ4Vxt.suffixrP   s   prefixr   r   ))rK   NrP   )rL   rM      )rN   rO      )rQ   rR   rW   )rT   N   )rV   N   s   suffix)ioBytesIOr   r@   r	   rX   rY   r   fr[   r\   s       r   test_from_filezGenopsTests.test_from_filea   s    JJEFI.""E"$47<</T!"X5"E H
 	 	9- Fs   B#c           	          t        d      }t        j                  |      }| j                  |D cg c]  }|d   j                  f|dd  z    c}g d       y c c}w )NrJ   r   r   ))rK   NN)rL   rM   N)rN   rO   N)rQ   rR   N)rT   NN)rV   NN)r9   r	   rX   r   rY   re   s       r   test_without_poszGenopsTests.test_without_poso   sZ    ;<""E"$47<</T!"X5"E H
 	Es   Ac                     t        j                  d      }t        |      }| j                  |d   j                  d       | j                  t        d      5  t        |       d d d        y # 1 sw Y   y xY w)N   Nr   NONE#pickle exhausted before seeing STOPr	   rX   nextr   rY   assertRaisesRegex
ValueErrorrZ   s      r   test_no_stopzGenopsTests.test_no_stop{   s]    %Bxav.##J57H7 7 7   A++A4c                 0   t        j                  d      }| j                  t        d      5  t	        |       d d d        t        j                  d      }| j                  t        d      5  t	        |       d d d        y # 1 sw Y   IxY w# 1 sw Y   y xY w)Ns   I123-no newline found when trying to read stringnls   J4&not enough data in stream to read int4)r	   rX   rp   rq   ro   )r   r[   s     r   test_truncated_datazGenopsTests.test_truncated_data   s    (##J?AHA -##J8:H: :	A A: :s   B +B B	Bc                     t        j                  d      }t        |      }| j                  |d   j                  d       | j                  t        d      5  t        |       d d d        y # 1 sw Y   y xY w)N   Nr   rl   &at position 1, opcode b'\\xff' unknownrn   rZ   s      r   test_unknown_opcodezGenopsTests.test_unknown_opcode   s]    )Bxav.##J9;H; ; ;rs   c                    t        d      }t        j                  |      }t        |      }| j	                  |d   j
                  d       | j                  t        d      5  t        |       d d d        y # 1 sw Y   y xY w)Nry   r   rl   z.at position <unknown>, opcode b'\\xff' unknown)r9   r	   rX   ro   r   rY   rp   rq   re   s       r   test_unknown_opcode_without_posz+GenopsTests.test_unknown_opcode_without_pos   sk    ""Bxav.##JACHC C Cs   !A66A?N)
r2   r3   r4   r]   rg   ri   rr   rw   r{   r}   r7   r   r   rH   rH   U   s%    	.
r   rH   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)DisTestsNc                     t        j                         }t        j                  |fd|i| | j	                  |j                         |       y Nout)rc   StringIOr	   disr   getvalue)r   r%   expectedr   r   s        r   	check_diszDisTests.check_dis   s9    kkm0#002r   c                     t        j                         }| j                  t        |      5  t	        j
                  |fd|i| d d d        | j                  |j                         |       y # 1 sw Y   *xY wr   )rc   r   rp   rq   r	   r   r   r   )r   r%   r   expected_errorr   r   s         r   check_dis_errorzDisTests.check_dis_error   sY    kkm##J?OOD4c4V4 @2 @?s   A--A6c                 (    | j                  dd       y )N   (N(tl.z    0: (    MARK
    1: N        NONE
    2: (        MARK
    3: t            TUPLE      (MARK at 2)
    4: l        LIST       (MARK at 0)
    5: .    STOP
highest protocol among opcodes = 0
r   r   s    r   	test_markzDisTests.test_mark       y # 	r   c                 ,    | j                  ddd       y )Nr   z    0: (    MARK
    1: N      NONE
    2: (      MARK
    3: t        TUPLE      (MARK at 2)
    4: l      LIST       (MARK at 0)
    5: .    STOP
highest protocol among opcodes = 0
r.   )indentlevelr   r   s    r   test_indentlevelzDisTests.test_indentlevel   s    y #  	 	r   c                 :    | j                  t        d      d       y )Nr   z(    MARK
N        NONE
(        MARK
t            TUPLE      (MARK at unknown opcode offset)
l        LIST       (MARK at unknown opcode offset)
.    STOP
highest protocol among opcodes = 0
)r   r9   r   s    r   test_mark_without_poszDisTests.test_mark_without_pos   s    |I. 1 	r   c                 *    | j                  ddd       y )Ns   Nt.z@    0: N    NONE
    1: t    TUPLE      no MARK exists on stack
zno MARK exists on stackr   r   s    r   test_no_markzDisTests.test_no_mark   s    V & 	 r   c                 (    | j                  dd       y )Ns   Np0
qr   .z    0: N    NONE
    1: p    PUT        0
    4: q    BINPUT     1
    6: r    LONG_BINPUT 2
   11: \x94 MEMOIZE    (as 3)
   12: .    STOP
highest protocol among opcodes = 4
r   r   s    r   test_putzDisTests.test_put   s    : = 	r   c                     | j                  ddd       | j                  ddd       | j                  ddd       | j                  dd	d
       y )Ns   Np1
p1
.zC    0: N    NONE
    1: p    PUT        1
    4: p    PUT        1
zmemo key 1 already defineds   Np1
q.zC    0: N    NONE
    1: p    PUT        1
    4: q    BINPUT     1
s
   Np1
r   .zD    0: N    NONE
    1: p    PUT        1
    4: r    LONG_BINPUT 1
s   Np1
.zH    0: N    NONE
    1: p    PUT        1
    4: \x94 MEMOIZE    (as 1)
zmemo key None already definedr   r   s    r   test_put_redefinedzDisTests.test_put_redefined   sq    ] - "		#
 	^ . "		#
 	7 : "		#
 	] - %		&r   c                 *    | j                  ddd       y )Ns   p0
z    0: p    PUT        0
z'stack is empty -- can't store into memor   r   s    r   test_put_empty_stackzDisTests.test_put_empty_stack   s    W '.	0r   c                 *    | j                  ddd       y )Ns   (p0
z.    0: (    MARK
    1: p        PUT        0
z"can't store markobject in the memor   r   s    r   test_put_markobjectzDisTests.test_put_markobject   s    X ( *	+r   c                 (    | j                  dd       y )Ns   (Np1
g1
hj   t.z    0: (    MARK
    1: N        NONE
    2: p        PUT        1
    5: g        GET        1
    8: h        BINGET     1
   10: j        LONG_BINGET 1
   15: t        TUPLE      (MARK at 0)
   16: .    STOP
highest protocol among opcodes = 1
r   r   s    r   test_getzDisTests.test_get   s    < 
? 
	r   c                 v    | j                  ddd       | j                  ddd       | j                  ddd       y )N   g1
.z    0: g    GET        1
z%memo key 1 has never been stored intos   h.z    0: h    BINGET     1
s   j   .z    0: j    LONG_BINGET 1
r   r   s    r   test_get_without_putzDisTests.test_get_without_put  sO    X (,	. 	Y ),	. 	2 5,	.r   c                 X    i }| j                  dd|       | j                  dd|       y )Ns   Np1
.z^    0: N    NONE
    1: p    PUT        1
    4: .    STOP
highest protocol among opcodes = 0
)memor   zM    0: g    GET        1
    3: .    STOP
highest protocol among opcodes = 0
r   )r   r   s     r   	test_memozDisTests.test_memo  sC    y #
  	 	 	x " 	 	 	r   c                 (    | j                  dd       y )Ns   (N00N.z    0: (    MARK
    1: N        NONE
    2: 0        POP
    3: 0        POP        (MARK at 0)
    4: N    NONE
    5: .    STOP
highest protocol among opcodes = 0
r   r   s    r   test_mark_popzDisTests.test_mark_pop&  r   r   c                 P    | j                  ddd       | j                  ddd       y )N   az    0: a    APPEND
z1tries to pop 2 items from stack with only 0 itemss   ]az*    0: ]    EMPTY_LIST
    1: a    APPEND
z1tries to pop 2 items from stack with only 1 itemsr   r   s    r   test_too_small_stackzDisTests.test_too_small_stack1  s6    T $8	: 	U % 9	:r   c                 *    | j                  ddd       y )Nrk       0: N    NONE
rm   r   r   s    r   rr   zDisTests.test_no_stop:  s    T $*	,r   c                 P    | j                  ddd       | j                  ddd       y )Ns   NI123r   ru   s   NJ4rv   r   r   s    r   rw   zDisTests.test_truncated_data?  s4    X (4	6 	] --	/r   c                 *    | j                  ddd       y )Nry   r   rz   r   r   s    r   r{   zDisTests.test_unknown_opcodeG  s    X (.	0r   c                 *    | j                  ddd       y )Ns   ]N.z\    0: ]    EMPTY_LIST
    1: N    NONE
    2: .    STOP
highest protocol among opcodes = 1
z$stack not empty after STOP: \[list\]r   r   s    r   test_stop_not_empty_stackz"DisTests.test_stop_not_empty_stackL  s    V &
 -	.r   c                 |    | j                  ddd       | j                  ddd       | j                  ddd       y )	Ns   (Nt.a,      0: (    MARK Push markobject onto the stack.
    1: N        NONE Push None on the stack.
    2: t        TUPLE      (MARK at 0) Build a tuple out of the topmost stack slice, after markobject.
    3: .    STOP                       Stop the unpickling machine.
highest protocol among opcodes = 0
r   )annotatea>      0: (    MARK            Push markobject onto the stack.
    1: N        NONE        Push None on the stack.
    2: t        TUPLE      (MARK at 0) Build a tuple out of the topmost stack slice, after markobject.
    3: .    STOP                       Stop the unpickling machine.
highest protocol among opcodes = 0
rb   s   (((((((ttttttt.a      0: (    MARK            Push markobject onto the stack.
    1: (        MARK        Push markobject onto the stack.
    2: (            MARK    Push markobject onto the stack.
    3: (                MARK Push markobject onto the stack.
    4: (                    MARK Push markobject onto the stack.
    5: (                        MARK Push markobject onto the stack.
    6: (                            MARK Push markobject onto the stack.
    7: t                                TUPLE      (MARK at 6) Build a tuple out of the topmost stack slice, after markobject.
    8: t                            TUPLE      (MARK at 5) Build a tuple out of the topmost stack slice, after markobject.
    9: t                        TUPLE      (MARK at 4) Build a tuple out of the topmost stack slice, after markobject.
   10: t                    TUPLE      (MARK at 3)     Build a tuple out of the topmost stack slice, after markobject.
   11: t                TUPLE      (MARK at 2)         Build a tuple out of the topmost stack slice, after markobject.
   12: t            TUPLE      (MARK at 1)             Build a tuple out of the topmost stack slice, after markobject.
   13: t        TUPLE      (MARK at 0)                 Build a tuple out of the topmost stack slice, after markobject.
   14: .    STOP                                       Stop the unpickling machine.
highest protocol among opcodes = 0
r   r   s    r   test_annotatezDisTests.test_annotateT  s^    w !  	 	 	w !  	 	 	) ," # 	 	r   c                 p    | j                  dd       | j                  dd       | j                  dd       y )Ns   S'abc'
.zQ    0: S    STRING     'abc'
    7: .    STOP
highest protocol among opcodes = 0
s   S"abc"
.s   S'õ'
.zV    0: S    STRING     '\xc3\xb5'
    6: .    STOP
highest protocol among opcodes = 0
r   r   s    r   test_stringzDisTests.test_stringv  s@    | & 	
 	| & 	
 	( + 	r   c                     | j                  ddd       | j                  ddd       | j                  ddd       | j                  ddd	       | j                  d
dd       | j                  ddd       y )Ns   Sabc'
. zno string quotes around b"abc'"s   Sabc"
.zno string quotes around b'abc"'s   S'abc
.z3strinq quote b"'" not found at both ends of b"'abc"s   S"abc
.z3strinq quote b'"' not found at both ends of b'"abc's   S'abc"
.z6strinq quote b"'" not found at both ends of b'\\'abc"'s   S"abc'
.z6strinq quote b'"' not found at both ends of b'"abc\\''r   r   s    r   test_string_without_quotesz#DisTests.test_string_without_quotes  s    ["?	A["?	A["V	X["W	Y]BZ	\]BZ	\r   c                 L    | j                  dd       | j                  dd       y )Ns	   T   abc.zQ    0: T    BINSTRING  'abc'
    8: .    STOP
highest protocol among opcodes = 1
s   T   õ.zV    0: T    BINSTRING  '\xc3\xb5'
    7: .    STOP
highest protocol among opcodes = 1
r   r   s    r   test_binstringzDisTests.test_binstring  s,    / 2 	
 	4 7 	r   c                 L    | j                  dd       | j                  dd       y )Ns   Uabc.zV    0: U    SHORT_BINSTRING 'abc'
    5: .    STOP
highest protocol among opcodes = 1
s   Uõ.z[    0: U    SHORT_BINSTRING '\xc3\xb5'
    4: .    STOP
highest protocol among opcodes = 1
r   r   s    r   test_short_binstringzDisTests.test_short_binstring  s+    | & 	
 	( + 	r   c                 L    | j                  dd       | j                  dd       y )Ns   cmodule
name
.zY    0: c    GLOBAL     'module name'
   13: .    STOP
highest protocol among opcodes = 0
s   cmödule
näme
.u[       0: c    GLOBAL     'mödule näme'
   15: .    STOP
highest protocol among opcodes = 0
r   r   s    r   test_globalzDisTests.test_global  s,    * - 	
 	8 ; 	r   c                 (    | j                  dd       y )Ns   (imodule
name
.zz    0: (    MARK
    1: i        INST       'module name' (MARK at 0)
   14: .    STOP
highest protocol among opcodes = 0
r   r   s    r   	test_instzDisTests.test_inst  s    + . 	r   c                 (    | j                  dd       y )Ns   Pabc
.zQ    0: P    PERSID     'abc'
    5: .    STOP
highest protocol among opcodes = 0
r   r   s    r   test_persidzDisTests.test_persid  s    z $ 	r   )r2   r3   r4   maxDiffr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rr   rw   r{   r   r   r   r   r   r   r   r   r   r7   r   r   r   r      s    G3
3			 	&,0
+	.	:,
/0
. D"\


r   r   c                       e Zd Zd Zy)MiscTestCasec                 D    h d}t        j                  | t        |       y )N>O   int4long1long4pyintpysetuint1uint2uint4uint8bytes1bytes4bytes8float8pyboolpydictpylistpylongpynonecode2opfloatnlopcodespybytespyfloatpytuplestring1string4pybufferpystringstringnl	anyobject	pyunicode	read_int4
OpcodeInfo
bytearray8
markobject
read_long1
read_long4
read_uint1
read_uint2
read_uint4
read_uint8
stacksliceStackObjectbytes_typespybytearraypyfrozensetread_bytes1read_bytes4read_bytes8read_float8read_floatnlread_string1read_string4UP_TO_NEWLINEread_stringnldecimalnl_longpybytes_or_strunicodestring1unicodestring4unicodestring8decimalnl_shortread_bytearray8unicodestringnlpyinteger_or_boolstringnl_noescapeArgumentDescriptorread_decimalnl_longread_unicodestring1read_unicodestring4read_unicodestring8TAKEN_FROM_ARGUMENT1TAKEN_FROM_ARGUMENT4read_decimalnl_shortread_unicodestringnlTAKEN_FROM_ARGUMENT4UTAKEN_FROM_ARGUMENT8Uread_stringnl_noescapestringnl_noescape_pairread_stringnl_noescape_pair)not_exported)r   check__all__r	   )r   r  s     r   test__all__zMiscTestCase.test__all__  s    
8 	T;\Jr   N)r2   r3   r4   r  r7   r   r   r   r     s    Kr   r   c                 V    |j                  t        j                  t                     |S r   )addTestdoctestDocTestSuiter	   )loadertestspatterns      r   
load_testsr#    s    	MM'&&{34Lr   __main__)rc   r   r	   testr   test.pickletesterr   r  unittestTestCaser   r9   rH   r   r   r#  r2   mainr7   r   r   <module>r*     s    	    1  62.0A0A 62r &G(## GTgx   gT	K8$$ KB
 zHMMO r   