
    daf                        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mZmZ 	 d dl	Z	ddddd	d
dddd ee j                        e j                  fdefddefdefdefdefdefgZ G d de      Z G d dej"                        Z G d dej"                        Z G d de      Z G d dej"                        Zed k(  r ej.                          yy# e
$ r dZ	Y w xY w)!    N)mock)support)VALID_UNDERSCORE_LITERALSINVALID_UNDERSCORE_LITERALS)0r   )1   )9	   )10
   )99c   )100d   )314:  )z 314r   )z314 r   )z  		  314  		  r   z  1x)z  1  r	   z  1      		  u   Ȁc                       e Zd Zy)IntSubclassN__name__
__module____qualname__     (/root/Python-3.12.4/Lib/test/test_int.pyr   r   $   s    r   r   c                       e Zd Zd Zd Zd Zd Zej                  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)IntTestCasesc                 d   | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d	      d       | j                  t        d
      d       | j                  t        d      d       | j                  t        d      d       | j                  t        dd      d       t        D ]I  \  }}dD ]?  }dD ]8  }||z   |z   }|}|dk(  r|t        ur| }	 | j                  t        |      |       : A K t	        dt
        j                  z
        }t        |      }| j                  |dz   t
        j                          | j                  |t               | j                  t        |dd        t
        j                  dz          t        d      }| j                  |t               t        d      }| j                  |t               dt
        j                  z
  }| j                  |dz	  |dz         t        d      }| j                  |t               | j                  t        t        dd       | j                  t        dd      d       | j                  t        dd      d       | j                  t        t        dd       | j                  t        t        dd       | j                  t        t        dd        | j                  t        t        dd       | j                  t        t        d!d       | j                  t        t        d!d       | j                  t        d"d      d#       | j                  t        d$d      d#       | j                  t        d%d&      d#       | j                  t        d'd(      d#       | j                  t        d)d*      d#       | j                  t        d+d,      d#       | j                  t        d-d       d#       | j                  t        d.d/      d#       | j                  t        d0d1      d#       | j                  t        d2d3      d#       | j                  t        d4d      d#       | j                  t        d5d6      d#       | j                  t        d7d8      d#       | j                  t        d9d:      d#       | j                  t        d;d      d#       | j                  t        d<d=      d#       | j                  t        d>d?      d#       | j                  t        d@dA      d#       | j                  t        dBdC      d#       | j                  t        dDdE      d#       | j                  t        dFdG      d#       | j                  t        dHdI      d#       | j                  t        dJdK      d#       | j                  t        dLdM      d#       | j                  t        dNdO      d#       | j                  t        dPdQ      d#       | j                  t        dRdS      d#       | j                  t        dTdU      d#       | j                  t        dVdW      d#       | j                  t        dXdY      d#       | j                  t        dZd[      d#       | j                  t        d\d]      d#       | j                  t        d^d_      d#       | j                  t        d`da      d#       | j                  t        dbdc      d#       | j                  t        ddd      d       | j                  t        ddd      d       | j                  t        ded      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dfd      d&       | j                  t        dgd      d       | j                  t        dhd      d       | j                  t        did      d&       | j                  t              5  t        djd       d d d        | j                  t        dk      dl       | j                  t        dkd1      dl       | j                  t        dd      d       | j                  t        dd       d       | j                  t        dfd      d&       | j                  t        dmd      d       | j                  t        dnd       d       | j                  t        dod      d&       | j                  t        t        dpd       | j                  t        t        dqd       | j                  t        t        drd       | j                  t        t        dsd       | j                  t        t        dtd        | j                  t        t        dud        | j                  t        t        dvd        | j                  t        t        dwd        | j                  t        t        dxd       | j                  t        t        dyd       | j                  t        t        dzd       | j                  t        t        d{d       | j                  t        d|d      d}       | j                  t        d~d      d}       | j                  t        dd&      d}       | j                  t        dd(      d}       | j                  t        dd*      d}       | j                  t        dd,      d}       | j                  t        dd       d}       | j                  t        dd/      d}       | j                  t        dd1      d}       | j                  t        dd3      d}       | j                  t        dd      d}       | j                  t        dd6      d}       | j                  t        dd8      d}       | j                  t        dd:      d}       | j                  t        dd      d}       | j                  t        dd=      d}       | j                  t        dd?      d}       | j                  t        ddA      d}       | j                  t        ddC      d}       | j                  t        ddE      d}       | j                  t        ddG      d}       | j                  t        ddI      d}       | j                  t        ddK      d}       | j                  t        ddM      d}       | j                  t        ddO      d}       | j                  t        ddQ      d}       | j                  t        ddS      d}       | j                  t        ddU      d}       | j                  t        ddW      d}       | j                  t        ddY      d}       | j                  t        dd[      d}       | j                  t        dd]      d}       | j                  t        dd_      d}       | j                  t        dda      d}       | j                  t        ddc      d}       y # t        $ r Y cw xY w# 1 sw Y   xY w)Nr   gQ	@   gQ	g333333@g333333g      @g      z-3z -3 u    -3 r      )r   +-)r   r   	r   r'   r	   g}Ô%ITg}Ô%I   X  111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111   0o123r   S   0x123i#  0x0o   0b!100000000000000000000000000000000l        10200202220122111121110000000000000000   32244002423141   1550104015504   211301422354   4000000000012068657454r   
4294967296r   
1904440554   	9ba461594	535a79889   	2ca5b7464   	1a20dcd81   	100000000a7ffda91   704he7g4   4f5aff66   3723ai4g   281d55i4   1fj8b184   1606k7ic   mb994ag   hek2mgl   dnchbnm   b28jpdm   8pfgih4   76beigg   5qmcpqg   4q0jto4   4000000    3aokq94!   2qhxjli"   2br45qb#   1z141z4$   z 0o123  0000b100z	 0O123   z 0X123  z 0B100 0100123{   0X1230O1230B1000b20b020B20B020o80o080O80O080xg0x0g0Xg0X0g!100000000000000000000000000000001l       102002022201221111212100000000000000013224400242314215501040155052113014223554000000000112068657455
4294967297
1904440555	9ba461595	535a7988a	2ca5b7465	1a20dcd82	100000001a7ffda92704he7g54f5aff673723ai4h281d55i51fj8b1851606k7idmb994ahhek2mgmdnchbnnb28jpdn8pfgih576beigh5qmcpqh4q0jto540000013aokq952qhxjlj2br45qc1z141z5)
assertEqualintL
ValueErrorreprsysmaxsizeassertIsInstanceassertRaises	TypeError)selfsvsignprefixssvvxs           r   
test_basiczIntTestCases.test_basic)   s   S3'TA&UR(S1%TB'S1%TB'TB'Vb)9:B?T"r* 
	DAq$ 	7 F$*BBs{q
':R((R"5	
	 CKK F1s{{l+a%QqrUS[[]3 Ja%Ka% s{{NaA&	Na% 	)S!R0Wa"-Wb)3/ 	*c44*c43*c43*c43*c43*c43 	@!DjQ4a8*E0!4jA-q1:>_a0*=^Q/<]A.
;]A.
;\2.
;\2.
;["-z:["-z:["-z:["-z:["-z:Z,j9Z,j9Z,j9Z,j9Z,j9Z,j9Z,j9Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8 	Z+R0Z+R0UA*Wa"-Wa#.Wa!,[!,b1Z+S1Y*A.z* 	qM	 	Vc*VR#. 	Wb)3/Wa"-Wa!,Wb)3/Wa"-Wa!, 	*c5!4*c615*c5!4*c615*c5!4*c615*c5!4*c615*c5"5*c626*c5"5*c626 	@!DjQ4a8*E0!4jA-q1:>_a0*=^Q/<]A.
;]A.
;\2.
;\2.
;["-z:["-z:["-z:["-z:["-z:Z,j9Z,j9Z,j9Z,j9Z,j9Z,j9Z,j9Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8Y+Z8 & z	 	s   z<z%	z"	!z"	%z/c                    | j                  t              5  t        d       d d d        | j                  t              5  t        d       d d d        | j                  t              5  t        d       d d d        | j                  t              5  t        d       d d d        | j                  t              5  t        d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   WxY w# 1 sw Y   y xY w)Nr&   r'   z- 1z+ 1z + 1 r   r   r   r   s    r   test_invalid_signszIntTestCases.test_invalid_signs   s    z* 	H	z* 	H	z* 	J	z* 	J	z* 	L	 		 		 		 		 		 	s:   CC(C'C3:C?CC$'C03C<?Dc                     | j                  t        d      d       | j                  t        d      d       | j                  t        dd      d       | j                  t        dd      d       y )Nu(   १२३४५६७८९०1234567890l   
>V3&Z
 u   ١٢٣٤٥٦٧٨٩٠iIr   r   r   r   s    r   test_unicodezIntTestCases.test_unicode   s`    GHJ^_34jAGKMab3Q7Dr   c           
         t         D ]r  t        fddD              r| j                  t        d      t	                     | j                  t        d      t        j                  dd      d             t t        D ]3  t        fddD              r| j                  t        t        d       5 | j                  t        dd      d	       | j                  t        d
      d       | j                  t        d      d       | j                  t        t        d       | j                  t        t        d       | j                  t        t        d       | j                  t        t        d       y )Nc              3   &   K   | ]  }|v  
 y wNr   .0chlits     r   	<genexpr>z0IntTestCases.test_underscores.<locals>.<genexpr>        /29/   z.eEjJr   _r   c              3   &   K   | ]  }|v  
 y wr   r   r   s     r   r   z0IntTestCases.test_underscores.<locals>.<genexpr>   r   r   1_00r#   r   0_100r   s   1_00_100z+_1001__00100_)	r   anyr   r   evalreplacer   r   r   )r   r   s    @r   test_underscoreszIntTestCases.test_underscores   s%   , 	HC/w//Sa[$s)4Sa[#ckk#r.BA*FG		H
 / 	7C/w//j#sA6	7
 	VQ+Ws+Ws+*c62*c73*c73*c62r   c                     | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       y )Nr   r   z-1r)   s   10s   -1)assertIsr   r   s    r   test_small_intszIntTestCases.test_small_ints  sL     	c$i$c$i$c%j"%c%j"%r   c                 8    | j                  t               d       y Nr   r   r   s    r   test_no_argszIntTestCases.test_no_args  s    "r   c                    | j                  t        dd      d       | j                  t        d      5  t        d       d d d        | j                  t        d      5  t        dd       d d d        | j	                  t        t        d	       | j	                  t        t        d
       y # 1 sw Y   nxY w# 1 sw Y   NxY w)Nr   r*   baser7   zkeyword argumentg333333?)r   )r   r   r   r   )r   r   assertRaisesRegexr   r   r   s    r   test_keyword_argszIntTestCases.test_keyword_args  s    U+Q/##I/AB 	#J	##I/AB 	!%a 	!)Sr2)Sq1	 		! 	!s   B.B:.B7:Cc                    | j                  t        dd      d       | j                  t              5  t        dd       ddd       | j                  t              5  t        dd       ddd       | j                  t              5  t        dd       ddd       | j                  t              5  t        dddd	z  z
  
       ddd       | j                  t              5  t        ddd	z  
       ddd       t	        dd      D ]  }| j                  t        d|
      d       ! y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   hxY w)z9Testing the supported limits of the int() base parameter.r   r9   r   r	   N%   isr*      r   )r   r   r   r   ranger   r   s     r   test_int_base_limitsz!IntTestCases.test_int_base_limits  s0   S!a(z* 	QK	z* 	RL	z* 	TN	z* 	&!QV*%	&z* 	"!S&!	" !BK 	5DS40!4	5	 		 		 		& 	&	" 	"s;   D)D5E0E!E)D25D>E
EE"c                     | j                  t              5  t        dd       ddd       | j                  t              5  t        dd       ddd       y# 1 sw Y   4xY w# 1 sw Y   yxY w)z2Not integer types are not valid bases; issue16772.r   g      @Ng      @)r   r   r   r   s    r   test_int_base_bad_typesz$IntTestCases.test_int_base_bad_types-  s_    y) 	SM	y) 	SM	 		 		 	s   A A"A"A+c                     G d dt               }ddz  ddz   ddfD ],  }| j                  t              5  t        d|       d d d        . | j	                  t        d |d      	      d
       | j	                  t        d |d      	      d       | j	                  t        d |d      	      d       y # 1 sw Y   xY w)Nc                       e Zd Zd Zd Zy)9IntTestCases.test_int_base_indexable.<locals>.MyIndexablec                     || _         y r   value)r   r   s     r   __init__zBIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__init__6  s	    "
r   c                     | j                   S r   r   r   s    r   	__index__zCIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__index__8  s    zz!r   N)r   r   r   r   r   r   r   r   MyIndexabler   5  s    #"r   r   r*   r   r	   r   43101r   r9   r   e   rr   i  )objectr   r   r   r   )r   r   r   s      r   test_int_base_indexablez$IntTestCases.test_int_base_indexable4  s    	"& 	" sFQVGQ* 	 D"":.  D$   	 
 	UQ8!<UR93?UR99E   s   B66B?	c                     G d dt                G d dt              } G d dt              }t        t        fd||t        g}	 dd	lm |j                  fd
       |D ]  } |d      }| j                  t        |            5  | j                  t        |      d       t        |t         t        t        f      r| j                  t        |d      d       n-d}| j                  t        |      5  t        |d       d d d        | j                  t        d      5  t         |d             d d d        d d d         y # t        $ r Y w xY w# 1 sw Y   SxY w# 1 sw Y   /xY w# 1 sw Y   xY w)Nc                       e Zd Zy)<IntTestCases.test_non_numeric_input_types.<locals>.CustomStrNr   r   r   r   	CustomStrr   H      r   r   c                       e Zd Zy)>IntTestCases.test_non_numeric_input_types.<locals>.CustomBytesNr   r   r   r   CustomBytesr  I  r   r   r  c                       e Zd Zy)BIntTestCases.test_non_numeric_input_types.<locals>.CustomByteArrayNr   r   r   r   CustomByteArrayr  J  r   r   r  c                 0     | j                               S r   )decode)br   s    r   <lambda>z;IntTestCases.test_non_numeric_input_types.<locals>.<lambda>O  s    i
+ r   r   )arrayc                      d|       S )NBr   )r  r
  s    r   r	  z;IntTestCases.test_non_numeric_input_types.<locals>.<lambda>Y  s    uS!} r   s   100r   r*   r7   zcan't convert non-stringzinvalid literals   AAAAAAAAAAAAAAAA)strbytes	bytearray
memoryviewr
  appendImportErrorsubTesttyper   r   
isinstancer   r   r   )	r   r  r  	factoriesfr   msgr   r
  s	          @@r   test_non_numeric_input_typesz)IntTestCases.test_non_numeric_input_typesE  sG    	#"&%&.i. +
		6# 45 	(A&	Ad1g& 	(  Q-a#ui!89$$SAY24C//	3? "Aq	"++J8IJ (+'(	( 	(	(  		" "( (	( 	(sO   E 	A,E,5EE, E 2E,	EEEE, E)%E,,E6	c                    | j                  t        t        d      dd       d       | j                  t        t        d      dd       d       | j                  t        t        d      dd       d       | j                  t        t        d      dd       d       | j                  t        t        d      dd       d       y )	Ns   123r	   r#   rX      123 s   123 s   123As   1234)r   r   r  r   s    r   test_int_memoryviewz IntTestCases.test_int_memoryviewh  s    Z/!45r:Z
3Aa892>Z0156;Z0156;Z0156;r   c                 :    | j                  t        t        d       y )Nz1.2r   r   s    r   test_string_floatzIntTestCases.test_string_floato  s    *c51r   c           	          G d d      }| j                  t        t         |               G d dt              }| j                  t        t         |               G d d      }| j	                  t         |             d        G d d	      }t        |fD ]L  } G d
 d|      }| j	                  t         |             d        G d d|      }| j                  t              5  | j	                  t         |             d       d d d         G d d|      }| j                  t              5  | j                  t              5  t         |              d d d        d d d        t        |fD ]r  }	 G d d|	       G fdd|      }
| j                  t              5  | j	                  t         |
             d       d d d         G d d|	       G fdd|      }| j                  t              5  | j	                  t         |
             d       d d d         G fdd|	       G fdd|      }	 | j                  t              5  t         |              d d d        | j                  d||	f        G d d|	       G fd d!|      }| j                  t              5  | j                  t              5  t         |              d d d        d d d        u O y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   QxY w# 1 sw Y   xY w# 1 sw Y   xY w# t        $ r%}| j	                  t        |      d       Y d }~d }~ww xY w# 1 sw Y   xY w# 1 sw Y   xY w)"Nc                       e Zd Zy)>IntTestCases.test_intconversion.<locals>.ClassicMissingMethodsNr   r   r   r   ClassicMissingMethodsr!  t      r   r"  c                       e Zd Zy)7IntTestCases.test_intconversion.<locals>.MissingMethodsNr   r   r   r   MissingMethodsr%  x  r#  r   r&  c                       e Zd Zd Zy)-IntTestCases.test_intconversion.<locals>.Foo0c                      yN*   r   r   s    r   __int__z5IntTestCases.test_intconversion.<locals>.Foo0.__int__}      r   Nr   r   r   r,  r   r   r   Foo0r(  |      r   r/  r+  c                       e Zd Zy)0IntTestCases.test_intconversion.<locals>.ClassicNr   r   r   r   Classicr2    r#  r   r3  c                       e Zd Zd Zd Zy):IntTestCases.test_intconversion.<locals>.IntOverridesTruncc                      yr*  r   r   s    r   r,  zBIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__int__      r   c                      y)Nir   r   s    r   	__trunc__zDIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__trunc__  s    r   N)r   r   r   r,  r9  r   r   r   IntOverridesTruncr5    s    r   r:  c                       e Zd Zd Zy)2IntTestCases.test_intconversion.<locals>.JustTruncc                      yr*  r   r   s    r   r9  z<IntTestCases.test_intconversion.<locals>.JustTrunc.__trunc__  r7  r   Nr   r   r   r9  r   r   r   	JustTruncr<    s    r   r?  c                       e Zd Zd Zy)9IntTestCases.test_intconversion.<locals>.ExceptionalTruncc                     ddz   y )Nr	   r   r   r   s    r   r9  zCIntTestCases.test_intconversion.<locals>.ExceptionalTrunc.__trunc__  s	    Er   Nr>  r   r   r   ExceptionalTruncrA    s    r   rC  c                       e Zd Zd Zy).IntTestCases.test_intconversion.<locals>.Indexc                      yr*  r   r   s    r   r   z8IntTestCases.test_intconversion.<locals>.Index.__index__      !r   Nr   r   r   r   r   r   r   IndexrE        "r   rI  c                       e Zd Z fdZy);IntTestCases.test_intconversion.<locals>.TruncReturnsNonIntc                             S r   r   )r   rI  s    r   r9  zEIntTestCases.test_intconversion.<locals>.TruncReturnsNonInt.__trunc__  s
    $wr   Nr>  )rI  s   r   TruncReturnsNonIntrL    s    'r   rN  c                       e Zd Zd Zy)0IntTestCases.test_intconversion.<locals>.Intablec                      yr*  r   r   s    r   r,  z8IntTestCases.test_intconversion.<locals>.Intable.__int__  rG  r   Nr.  r   r   r   IntablerP    rJ  r   rR  c                       e Zd Z fdZy)=IntTestCases.test_intconversion.<locals>.TruncReturnsNonIndexc                             S r   r   )r   rR  s    r   r9  zGIntTestCases.test_intconversion.<locals>.TruncReturnsNonIndex.__trunc__  s    &y(r   Nr>  )rR  s   r   TruncReturnsNonIndexrT    s    )r   rV  c                       e Zd Z fdZy)4IntTestCases.test_intconversion.<locals>.NonIntegralc                             S r   r   r   NonIntegrals    r   r9  z>IntTestCases.test_intconversion.<locals>.NonIntegral.__trunc__  s    *},r   Nr>  r[  s   r   r[  rX    s    -r   r[  c                       e Zd Z fdZy)@IntTestCases.test_intconversion.<locals>.TruncReturnsNonIntegralc                             S r   r   rZ  s    r   r9  zJIntTestCases.test_intconversion.<locals>.TruncReturnsNonIntegral.__trunc__  s    *},r   Nr>  r\  s   r   TruncReturnsNonIntegralr^    s    -r   r`  zFailed to raise TypeError with z2__trunc__ returned non-Integral (type NonIntegral)c                       e Zd Zd Zy)/IntTestCases.test_intconversion.<locals>.BadIntc                      yNg      E@r   r   s    r   r,  z7IntTestCases.test_intconversion.<locals>.BadInt.__int__  s    #r   Nr.  r   r   r   BadIntrb    s    $r   re  c                       e Zd Z fdZy);IntTestCases.test_intconversion.<locals>.TruncReturnsBadIntc                             S r   r   r   re  s    r   r9  zEIntTestCases.test_intconversion.<locals>.TruncReturnsBadInt.__trunc__  s
    %xr   Nr>  re  s   r   TruncReturnsBadIntrg    s    (r   rk  )
r   r   r   r   r   assertWarnsDeprecationWarningZeroDivisionErrorfailr  )r   r"  r&  r/  r3  r   r:  r?  rC  trunc_result_baserN  rV  r`  erk  re  rI  rR  r[  s                  @@@@r   test_intconversionzIntTestCases.test_intconversionr  s2   	 	)S*?*AB	V 	)S.*:;	 	 	TVb)	 	W% H	.DD 
 S!2!45r:D  !!"45 7  Y[!12674  ""#45 (!!"45($&'( ( '-g%6 3.!"- "' ' %%&89 D$$S);)=%>CD"/ ")4 ) %%&89 D$$S);)=%>CD-"3 -
-d -	<))*<= 73567 II $&78; <$. $( ( &&y1 .%%&89.*,-. . .c3.+H	.7 7( ( ( (D DD D7 7  =$$SV'<= ==". . . .s   )!K+2LK8L"!L8!L<L8L,"L8-M5M)	M5+K5	8L=LL	LL),L51L88	M&M!!M&)M2.M55M?c                      G d dt               } G d dt               } |d      }| j                  |d       | j                  t        |      d       | j                  t         |             d       y )Nc                       e Zd Zd Zy):IntTestCases.test_int_subclass_with_index.<locals>.MyIndexc                      yr*  r   r   s    r   r   zDIntTestCases.test_int_subclass_with_index.<locals>.MyIndex.__index__  r-  r   NrH  r   r   r   MyIndexru    r0  r   rw  c                       e Zd Zd Zy);IntTestCases.test_int_subclass_with_index.<locals>.BadIndexc                      yrd  r   r   s    r   r   zEIntTestCases.test_int_subclass_with_index.<locals>.BadIndex.__index__      r   NrH  r   r   r   BadIndexry        r   r|  r=   r   )r   r   )r   rw  r|  my_ints       r   test_int_subclass_with_indexz)IntTestCases.test_int_subclass_with_index  s_    	c 		s 	 #Va(XZ!,r   c                     G d dt               } G d dt               } |d      }| j                  |d       | j                  t        |      d        |d      }| j                  |d       | j                  t        t         |       y )Nc                       e Zd Zd Zy)6IntTestCases.test_int_subclass_with_int.<locals>.MyIntc                      yr*  r   r   s    r   r,  z>IntTestCases.test_int_subclass_with_int.<locals>.MyInt.__int__  r-  r   Nr.  r   r   r   MyIntr    r0  r   r  c                       e Zd Zd Zy)7IntTestCases.test_int_subclass_with_int.<locals>.BadIntc                      yrd  r   r   s    r   r,  z?IntTestCases.test_int_subclass_with_int.<locals>.BadInt.__int__  r{  r   Nr.  r   r   r   re  r    r}  r   re  r=   r+  )r   r   r   r   )r   r  re  r~  s       r   test_int_subclass_with_intz'IntTestCases.test_int_subclass_with_int  st    	C 		S 	 q#Vb)#)S&1r   c                   	
  G d d      	 G d dt               } G d d      
 G d dt               } G 	fd	d
      } G 
fdd      } G d d      } 	       }| j                  t              5  t        |      }d d d        | j                  d       | j	                  t        |      t                 |       }t        |      }| j                  |d       | j	                  t        |      t                 
       }| j                  t              5  t        |      }d d d        | j                  |d       | j	                  t        |      t                 |       }| j                  t              5  t        |      }d d d        | j                  |d       | j	                  t        |      t                 |       }| j                  t              5  t        |      }d d d        | j                  |d       | j	                  t        |      t                 |       }| j                  t              5  | j                  t        t         |       d d d         |       }| j                  t              5  t        |      }d d d        | j                  |d       | j	                  t        |      t                | j                  t              5  t        |      }d d d        | j                  |d       | j	                  t        |      t               y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ^xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)Nc                       e Zd Zd Zy)<IntTestCases.test_int_returns_int_subclass.<locals>.BadIndexc                      yNTr   r   s    r   r   zFIntTestCases.test_int_returns_int_subclass.<locals>.BadIndex.__index__  r{  r   NrH  r   r   r   r|  r    r}  r   r|  c                       e Zd Zd Zy)=IntTestCases.test_int_returns_int_subclass.<locals>.BadIndex2c                      yr  r   r   s    r   r   zGIntTestCases.test_int_returns_int_subclass.<locals>.BadIndex2.__index__  r{  r   NrH  r   r   r   	BadIndex2r    r}  r   r  c                       e Zd Zd Zy):IntTestCases.test_int_returns_int_subclass.<locals>.BadIntc                      yr  r   r   s    r   r,  zBIntTestCases.test_int_returns_int_subclass.<locals>.BadInt.__int__  r{  r   Nr.  r   r   r   re  r    r}  r   re  c                       e Zd Zd Zy);IntTestCases.test_int_returns_int_subclass.<locals>.BadInt2c                      yr  r   r   s    r   r,  zCIntTestCases.test_int_returns_int_subclass.<locals>.BadInt2.__int__  r{  r   Nr.  r   r   r   BadInt2r    r}  r   r  c                       e Zd Z fdZy)HIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIndexc                             S r   r   )r   r|  s    r   r9  zRIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIndex.__trunc__   s    z!r   Nr>  )r|  s   r   TruncReturnsBadIndexr    s    "r   r  c                       e Zd Z fdZy)FIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIntc                             S r   r   ri  s    r   r9  zPIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadInt.__trunc__  s
    xr   Nr>  rj  s   r   rk  r    s     r   rk  c                       e Zd Zd Zy)KIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsIntSubclassc                      yr  r   r   s    r   r9  zUIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsIntSubclass.__trunc__  r{  r   Nr>  r   r   r   TruncReturnsIntSubclassr    r}  r   r  r	   r   )	r   rl  rm  r   r   r  r   r   r   )r   r  r  r  rk  r  bad_intngood_intr|  re  s            @@r   test_int_returns_int_subclassz*IntTestCases.test_int_returns_int_subclass  s   	 		 		 		c 		" 	"	  	 	 	 *01 	GA	Ad1gs#+LAd1gs#(01 	GA	Ad1gs#)01 	GA	Ad1gs#&(01 	GA	Ad1gs#$&01 	7ig6	7 +,01 	HA	Ad1gs#01 	&H%A	&Ad1g{+Q	 		 		 		 		7 	7	 		& 	&sT   3LL'8L4M:M:MM&L$'L14L>MMM#&M/c                     d fd	} |d        |d        |d        |d        |dd        |dd        |dd	        |d
d        |d
d	        |d        |dd        |d        |dd        |d        |dd       y )Nc                    j                  t        d| d|d      5 }|t        |        nt        | |       d d d        j                  j                  j
                  d   d|dn|| fz         y # 1 sw Y   <xY w)Nzint(z, ))r  r   z*invalid literal for int() with base %d: %rr   )r   r   r   r   	exceptionargs)r   r   cmr   s      r   checkz.IntTestCases.test_error_message.<locals>.check7  s    "":894'@ # B !EG<F4L! R\\..q1<|q123! !s   A66A?   ½u   123½z  123 456  z123 r   z123  245rR   r%   z123 245r  s   123u   123r   r   )r   r  s   ` r   test_error_messagezIntTestCases.test_error_message6  s    		3 	fimiimR mR lBlBjj"jj"kk2r   c                     | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d	       | j                  t        d
d      d       y )N=1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1r*   iUUUU1_2_3_4_5_6_7_0_1_2_3r2   iSpS1_2_3_4_5_6_7_8_9r%   l   gF 1_2_3_4_5_6_7rj   i2Dr   r   s    r   test_issue31619zIntTestCases.test_issue31619W  se    \^_`:	<4a8-H0"5{C_b1:>r   N)r   r   r   r   r   r   r   r   cpython_onlyr   r   r   r   r   r   r  r  r  rr  r  r  r  r  r  r   r   r   r!   r!   '   s    w9r
E3& & &#25"F"!(F<2Z.x-2"F,PB?r   r!   c                   v     e Zd ZeZ fdZ fdZd Zd ZddZ	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Z xZS )IntStrDigitLimitsTestsc                 ~    t         |           t        j                         | _        t        j
                  d       y )Ni   supersetUpr   get_int_max_str_digits_previous_limitset_int_max_str_digitsr   	__class__s    r   r  zIntStrDigitLimitsTests.setUpc  s+    "99;""4(r   c                 `    t        j                  | j                         t        |           y r   r   r  r  r  tearDownr  s    r   r  zIntStrDigitLimitsTests.tearDownh  "    ""4#7#78r   c                    | j                  t        j                         d       | j                  t        j                         d       t	        j
                  d      5  | j                  t        j                         d       | j                  ddz        }t        |       d d d        | j                  t        j                         d       y # 1 sw Y   .xY w)Nr    N  r   )	assertGreaterr   r  
assertLessr   adjust_int_max_str_digitsr   	int_classr  )r   is     r   test_disabled_limitz*IntStrDigitLimitsTests.test_disabled_limitl  s    3557;224f=..q1 	S7791=sV|,AF	 	3557;		 	s   ACCc           	         | j                   }t        j                         } |d|z          |dd|z  z           |d|z  dz           |dd|z  z           |dd|z  z          | j                  t	        t        d|dz
  z              |       y)z&Ignore the +/- sign and space padding.r   r   r&   r'   r   r	   N)r  r   r  r   lenr  )r   r  	maxdigitss      r   test_max_str_digits_edge_casesz5IntStrDigitLimitsTests.test_max_str_digits_edge_casesu  s    NN	..0	#	/"#i'(#	/C'(#i'(#i'(S	A!678)Dr   c                     | j                  t              5  || j                  |       n| j                  ||       d d d        y # 1 sw Y   y xY wr   )r   r   r  )r   r  r   s      r   r  zIntStrDigitLimitsTests.check  sD    z* 	(|q!q$'		( 	( 	(s   'AAc                    t        j                         }| j                  d|dz   z         | j                  dd|dz   z  z          | j                  d|dz   z  dz          | j                  dd|dz   z  z          | j                  dd|dz   z  z          | j                  d|dz   z         d|z  }| j                  t              5  t        |       d d d        y # 1 sw Y   y xY w)Nr   r	   r   r&   r'   r   )r   r  r  r   r   r  )r   r  r  s      r   test_max_str_digitsz*IntStrDigitLimitsTests.test_max_str_digits  s    ..0	

3)a-()

3	A../

3)a-(3./

3	A../

3	A../

3)a-())Oz* 	F	 	 	s   CC#c                 T   t        j                         }|dk  sJ |       t        j                  } |       dk  rt        j                  }t        dddz   d      }d}t        j                  |      5   |       }t        |      }d	d	d	        |       z
  }| j                  t              |       |d
k  rt        j                  d| d      t        j                  t        d|z              5  | j                  t              5 } |       }t        |       d	d	d	        |       |z
  }	d	d	d	       | j                  dt        j                                | j#                  	|dz         t        dddz   d      }
| j                  t              5 } |       }t        |
       d	d	d	        |       |z
  }| j                  dt        |j                                | j%                  ||dz         y	# 1 sw Y   sxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   sxY w)?Regression test: ensure we fail before performing O(N**2) work.iP  r   r0   ci  r%   r   i1 N      ?"slow" conversion took only 	 seconds.gףp=
?
conversionr*   i  )r   r  timeprocess_time	monotonicr   r   r  r  r   r  unittestSkipTestr   r   assertInr  assertLessEqualr  )r   r  get_timehuge_intdigitsstarthuge_decimalseconds_to_converterrseconds_to_fail_hugeextra_huge_intseconds_to_fail_extra_huges               r   +test_denial_of_service_prevented_int_to_strzBIntStrDigitLimitsTests.test_denial_of_service_prevented_int_to_str  s   ..0	6!,9,!$$:?~~HCJ<(r2..v6 	)JEx=L	) &Z%/\*F3 $##$B'9&:)%E F F
 ..s4&=/AB 	6"":. # 
H $,:#5 		6
 	lC$6713Ea3GH r#g+/b9z* 	 cJE	  &.Z%%7"lC$6724Fq4HI?	) 	) 	6 	6	  	 s<   5G94H
HHH9HH	HHH'c                    t        j                         }|dk  sJ |       t        j                  } |       dk  rt        j                  }d}d|z  }t        j                  |      5   |       }t        |       ddd        |       z
  }|dk  rt        j                  d| d      t        j                  |d	z
        5  | j                  t              5 } |       }t        |       ddd        |       |z
  }ddd       | j                  d
t        j                               | j                  |dz         ddz  }	| j                  t              5 } |       }t        |	       ddd        |       |z
  }
| j                  d
t        |j                               | j                  |
|dz         y# 1 sw Y   AxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   sxY w)r  順 r   iD
 8Nr  r  r  r	   r  r*   7iO )r   r  r  r  r  r   r  r   r  r  r   r   r  r  r  r  )r   r  r  r  huger  r  r  r  
extra_huger  s              r   +test_denial_of_service_prevented_str_to_intzBIntStrDigitLimitsTests.test_denial_of_service_prevented_str_to_int  s   ..0	7"-I-"$$:?~~H6z..v6 	JEI	 &Z%/ $##$B'9&:)%E F F ..vz: 	6"":. # 
D	 $,:#5 		6
 	lC$6713Ea3GH ]
z* 	cJE
O	 &.Z%%7"lC$6779KA9MN9	 	 	6 	6	 	s<   'F9GG+GG9GG	GGG'c                     t        j                         }dD ]Q  }| j                  |      5  | j                  d|dz   z  |       |dk  sJ | j                  ddz  |       ddd       S y# 1 sw Y   ^xY w)z-The limit does not apply to power of 2 bases.)r*   r7   r2   r%   rj   r   r   r	   r  N)r   r  r  r  )r   r  r   s      r   !test_power_of_two_bases_unlimitedz8IntStrDigitLimitsTests.test_power_of_two_bases_unlimited  s~    ..0	% 	4D4( 4si!m4d; 7***sW}d34 4	44 4s   5A,,A5	c                     t        j                         }|dz  }d|z  }d|z  }| j                  |       | j                  |       | j                  | d       | j                  | d       y )Nr#   1111_11_111)r   r  r  r  )r   r  triplesr   s_s        r   test_underscores_ignoredz/IntStrDigitLimitsTests.test_underscores_ignored  sh    ..0	q.GOgqr

aS9

bT;r   c                     | j                   }t        j                         }d|z  } ||      } |d|       }||k(  sJ  |d|       }| |k(  sJ t        |       t        |       y )N5r&   r'   )r  r   r  r  )r   r  
max_digitsr   r  pos_ineg_is          r   test_sign_not_countedz,IntStrDigitLimitsTests.test_sign_not_counted  st    NN	//1
*aLAaS'"EzzAaS'"vE
E
r   c                 b   | j                   }t        j                         }d|z  } |||      }|dkD  r*| j                  t              5  t        |       d d d        n|dk  rt        |       | j                  t              5 } || d|       d d d        y # 1 sw Y   4xY w# 1 sw Y   y xY w)N2r   r   )r  r   r  r   r   r  )r   r   r  r  r   r  r  s          r   _other_base_helperz)IntStrDigitLimitsTests._other_base_helper
  s    NN	//1
*a"9"":. A BYFz* 	%c1gt$	% 	%	 	% 	%s   	BB%B"%B.c                     d}| j                  |      5  | j                  |       d d d        d}| j                  |      5  | j                  |       d d d        y # 1 sw Y   8xY w# 1 sw Y   y xY w)Nr#   r   rr   )r  r  r   s     r   test_int_from_other_basesz0IntStrDigitLimitsTests.test_int_from_other_bases  ss    \\t\$ 	*##D)	*\\t\$ 	*##D)	* 	*	* 	*	* 	*s   AA*A'*A3c                    d}t        j                  d      5  t        j                         }| j	                  t        j
                  |      dd       t        j                         }| j	                  ||       d d d        y # 1 sw Y   y xY w)Na8  if 1:
        # Subinterpreters maintain and enforce their own limit
        import sys
        sys.set_int_max_str_digits(2323)
        try:
            int('3'*3333)
        except ValueError:
            pass
        else:
            raise AssertionError('Expected a int max str digits ValueError.')
        i  r   z%subinterp code failure, check stderr.)r   r  r   r  r   run_in_subinterp)r   codebefore_valueafter_values       r   *test_int_max_str_digits_is_per_interpreterzAIntStrDigitLimitsTests.test_int_max_str_digits_is_per_interpreter  s{    
 ..t4 	8557LW55d;QDF446K\;7	8 	8 	8s   A!BBr   )r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  __classcell__r  s   @r   r  r  _  sS    I)
<
E()JV&OP4	 
%*8r   r  c                       e Zd ZeZy)IntSubclassStrDigitLimitsTestsN)r   r   r   r   r  r   r   r   r  r  4  s    Ir   r  c                       e Zd Z fdZ fdZd Zd Z ej                  d      d        Z	d Z
d Zej                   ej                  ed	      ej"                  j%                  ed
      d                      Zej                   ej                  ed	      ej"                  j%                  ed      d                      Z xZS )PyLongModuleTestsc                 ~    t         |           t        j                         | _        t        j
                  d       y r   r  r  s    r   r  zPyLongModuleTests.setUp<  s+    "99;""1%r   c                 `    t        j                  | j                         t        |           y r   r  r  s    r   r  zPyLongModuleTests.tearDownA  r  r   c                     t        |      }| j                  |dd  |       t        |       }| j                  |d|z          d|z  }| j                  ||       d|z  }| j                  ||j                  d             y )Nir'   z%ds   %dascii)r  r   encode)r   r  suffixr   s2s3s4s          r   _test_pylong_int_to_decimalz-PyLongModuleTests._test_pylong_int_to_decimalE  s{    F34&)!WS1W%AXQQYQXXg./r   c                     | j                  ddz  d       | j                  ddz  dz
  d       | j                  ddz  d       | j                  ddz  dz
  d       | j                  d	d
z  d       y )Nr	   r  
9883109376
9883109375r   i0u  
0000000000
9999999999r#   i`  
9313200001r  r   s    r   test_pylong_int_to_decimalz,PyLongModuleTests.test_pylong_int_to_decimalO  so    ((!w,F((!w,!);\J((V\B((VaF((FLAr   cpuc                     | j                  ddz  d       | j                  ddz  d       | j                  ddz  d	       y )
Nr*   i@B 
2747109376r   i r#  r#   i'	 
3132000001r&  r   s    r   test_pylong_int_to_decimal_2z.PyLongModuleTests.test_pylong_int_to_decimal_2V  s>    ((I|D((WlC((G\Br   c                 P    ddz  }t        |dz  dz   |      \  }}|dk(  r|dk(  sJ y )Nr	   r  r#   )divmod)r   r  ar  s       r   test_pylong_int_divmodz(PyLongModuleTests.test_pylong_int_divmod\  s8    '\acAgq!1Av!q&  &r   c                    ddz  }t        |      }t        |      }||k(  sJ t        d|z         }| |k(  sJ t        d|z   dz         }||k(  sJ | j                  t              5 }t        |dz          d d d        | j                  t              5 }t        |dz          d d d        | j                  t              5 }t        d|z          d d d        y # 1 sw Y   bxY w# 1 sw Y   BxY w# 1 sw Y   y xY w)Nr	   r  z -z +r   zr   )r  r   r   r   )r   v1r   v2v3v4r  s          r   test_pylong_str_to_intz(PyLongModuleTests.test_pylong_str_to_inta  s    '\GVRxx]sbyyC Rxxz* 	cCL	z* 	cCL	z* 	caL	 			 		 		 	s$   &CC">C.C"C+.C7z_pylong module requiredint_to_decimal_stringc                    t        j                  d      5  t        ddz        }d |_        | j	                  t
              5 }t        |       d d d        | j                  dt        j                               t        d      |_
        | j	                  t              5  t        |       d d d        d d d        y # 1 sw Y   pxY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr  r  N  z%_pylong.int_to_decimal_string did nottestABC)r   r  r   return_valuer   r   r  r  r  RuntimeErrorside_effect)r   mock_int_to_str	big_valuectxs       r   )test_pylong_misbehavior_error_path_to_strz;PyLongModuleTests.test_pylong_misbehavior_error_path_to_strq  s    
 ..v6 		CJI+/O(""9- IMMAcmm,.*6y*AO'""<0 I		 		 
 		 		s<   +CB<ACC+C<C	CC	CCint_from_stringc                    ddz  }t        j                  d      5  d|_        | j                  t              5 }t        |       d d d        | j                  dt        j                               t        d      |_
        | j                  t              5  t        |       d d d        d d d        y # 1 sw Y   pxY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr  r:  r  s
   not an intz_pylong.int_from_string did nottest123)r   r  r<  r   r   r   r  r  r  r=  r>  )r   mock_int_from_strr@  rA  s       r   +test_pylong_misbehavior_error_path_from_strz=PyLongModuleTests.test_pylong_misbehavior_error_path_from_str  s    
 J	..v6 		-:*""9- IMM;cmm,. -9,C)""<0 I		 		  		 		s;   CB3ACB?"C3B<	8C?C	CC)r   r   r   r  r  r  r'  r   requires_resourcer,  r0  r7  r  r  
skipUnless_pylongr   patchr   rB  rG  r  r  s   @r   r  r  8  s    &
0B Wu%C &C
!
  X";<	ZZw 78 9 =  X";<	ZZw 12 3 = r   r  __main__)r   r  r  r   testr   test.test_grammarr   r   rJ  r  r   r   r   r   r   r   TestCaser!   r  r  r  r   mainr   r   r   <module>rQ     s   
    <
 	$	ckk	CKK(		Z 	Z	j	Z 	:%*	# 	u?8$$ u?pR8X.. R8j%; X)) Xv zHMMO O  Gs   C CC