
    dafEe                    Z   d dl Z d dlmZ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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d dlZ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 d dlmZ d dlmZ d dlmZ d d	lm Z m!Z!m"Z" 	 d dl#Z#	 d dl%Z%	 d dl&Z&	 d dl'Z( ejT                  d
      Z+d dl,Z,dZ-d Z.d Z/d Z0 G d d      Z1 G d dejd                        Z3e G d dejd                               Z4 G d dejd                        Z5 G d dejd                        Z6 G d dejd                        Z7 G d dejd                        Z8 G d dejd                        Z9 G d dejd                        Z: G d  d!ejd                        Z; ejx                  e%du d"       G d# d$ejd                               Z= G d% d&ejd                        Z>d'Z? G d( d)ejd                        Z@eAd*k(  r ej                          yy# e$$ r dZ#Y ww xY w# e$$ r dZ%Y w xY w# e$$ r dZ&Y w xY w# e)$ r dZ(Y w xY w)+    N)OrderedDictdeque)support)MISSING_C_DOCSTRINGS)import_helper)threading_helper)warnings_helper)requires_limited_api)assert_python_failureassert_python_okrun_python_until_end	_testcapic                 F    | j                  dd      j                  dd      S )Nzutf-8replace )decoder   )errs    3/root/Python-3.12.4/Lib/test/test_capi/test_misc.pydecode_stderrr   8   s     ::gy)11$;;    c                 F     t        j                  t        du d      |       S )z>Decorator to skip a test if subinterpreters are not supported.Nzsubinterpreters required)unittestskipIf_interpreters)meths    r   requires_subinterpretersr   <   s)    78??=D0577;= =r   c                     | S )zsome doc selfs    r   testfunctionr"   B   s    Kr   c                   P    e Zd Zej	                  e      Zej	                  e      Zy)InstanceMethodN)__name__
__module____qualname__r   instancemethodidr"   r   r   r   r$   r$   G   s"    		!	!"	%B++L9Lr   r$   c                   ~   e Zd Zd Z ej
                         d        Zd Z ej                  e
d      d        Z ej                  e
d      d        Z ej                  ed      d        Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Z ej                   eed      d      d        Z ej                   eed      d       ej8                  dddd      d               Zd Z ej>                  d      d        Z  ej>                  d      d        Z!d Z" ej                  ed      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- Z0d. Z1d/ Z2d0 Z3d1 Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9 e:jv                  e<7      d8        Z=d9 Z>d: Z?d; Z@d< ZAd= ZBd> ZCd? ZDd@ ZEdA ZFdB ZGdC ZHdD ZIdE ZJdF ZKdG ZLdH ZMdI ZNyJ)KCAPITestc                 <   t               }| j                  t        |      |j                                | j                  |j	                         |u        | j                  |j                  j
                  t        j
                         | j                  t         j                  j
                  t        j
                         dt         j                  _        | j                  t        j                  d       | j                  t        t        |j                  dd       y )Ntest	attribute)
r$   assertEqualr)   
assertTruer"   __doc__r.   assertRaisesAttributeErrorsetattrr!   insts     r   test_instancemethodzCAPITest.test_instancemethodM   s    D4779-))+t34**22L4H4HI44<<l>R>RS06##-//8.'43D3DkSYZr   c                     t        j                  d      }t        d|      \  }}|\  }}}| j                  |d       dj	                         }| j                  |j                         j                  |      |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.crash_no_current_thread()
        -cr   zFatal Python error: PyThreadState_Get: the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL))textwrapdedentr   r/   encoder0   rstrip
startswith)r!   code
run_result	_cmd_line_rcoutr   msgs           r    test_no_FatalError_infinite_loopz)CAPITest.test_no_FatalError_infinite_loopX   s{        !5T4 @
I"S#c"; =CFH	 	
 	

//4	r   c                 L    | j                  t        t        j                         y N)r2   
ValueErrorr   !make_memoryview_from_NULL_pointerr    s    r   !test_memoryview_from_NULL_pointerz*CAPITest.test_memoryview_from_NULL_pointern   s    *i&Q&QRr   z(_posixsubprocess required for this test.c                 v    G d dt               }| j                  t        d      5  t        j                  d |       ddddd	d
ddddddddddddddd       d d d         G d dt               }| j                  t        t        j                  d |       ddddd	d
ddddddddddddddd       y # 1 sw Y   YxY w)Nc                       e Zd Zd Zy)1CAPITest.test_seq_bytes_to_charp_array.<locals>.Zc                      yN   r   r    s    r   __len__z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__u       r   Nr%   r&   r'   rQ   r   r   r   ZrM   t       r   rT   indexingrP   TrP                  	   
                  F            c                       e Zd Zd Zd Zy)rM   c                 "    t         j                  S rG   )sysmaxsizer    s    r   rQ   z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__|   s    {{"r   c                      y)N   xr   )r!   is     r   __getitem__z=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__~       r   N)r%   r&   r'   rQ   ro   r   r   r   rT   z1CAPITest.test_seq_bytes_to_charp_array.<locals>.Z{   s    #r   )objectassertRaisesRegex	TypeError_posixsubprocess	fork_execr2   MemoryErrorr!   rT   s     r   test_seq_bytes_to_charp_arrayz&CAPITest.test_seq_bytes_to_charp_arrayq   s    	 	 ##Iz: 	k&&ACVAa!AbBr"T$rRWXZ[]^`acdik	k	 	
 	+'7'A'AACVAa!AbBr"T$rRWXZ[]^`acdi	k	k 	ks   1B//B8c                      G d dt               }| j                  t        t        j                   |       dgdddddd	d
dddddddddddddd       y )Nc                       e Zd Zd Zy)-CAPITest.test_subprocess_fork_exec.<locals>.Zc                      yrO   r   r    s    r   rQ   z5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__   rR   r   NrS   r   r   r   rT   r{      rU   r   rT      1TrW   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   Frd   re   rf   rg   )rq   r2   rs   rt   ru   rw   s     r   test_subprocess_fork_execz"CAPITest.test_subprocess_fork_exec   sd    	 	
 	)%5%?%?#tfT&1Qq2bBr$tTVW\]_`bcefhin	pr   z6Signature information for builtins requires docstringsc                 D   | j                  t        j                  j                  d        | j                  t        j                  j                  d        | j                  t        j
                  j                  d        | j                  t        j
                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  t        j                  j                  d       y )Nz This docstring has no signature.z[docstring_with_invalid_signature($module, /, boo)

This docstring has an invalid signature.zedocstring_with_invalid_signature2($module, /, boo)

--

This docstring also has an invalid signature.z%This docstring has a valid signature.z($module, /, sig)z>
This docstring has a valid signature and some extra newlines.z($module, /, parameter))r/   r   no_docstringr1   __text_signature__docstring_emptydocstring_no_signature docstring_with_invalid_signature!docstring_with_invalid_signature2docstring_with_signature#docstring_with_signature_but_no_doc+docstring_with_signature_and_extra_newlinesr    s    r    test_docstring_signature_parsingz)CAPITest.test_docstring_signature_parsing   s    	//77>//BBDI22::DA22EEtL99AA.	099LLdSCCKK7	
 	CCVVX\]DDLL<	 	DDWWY]^;;CC3	5;;NNPcdFFNNPTUFFYY	! 	NNVVM	ONNaa%	'r   c                 x   t         j                  } |       } |       }| j                  ||z  d||f       | j                  |dz  d|df       | j                  d|z  dd|f       |}||z  }| j                  |d||f       |}|dz  }| j                  |d|df       d}||z  }| j                  |dd|f       y )Nmatmul*   imatmul)r   
matmulTyper/   )r!   Mm1m2os        r   &test_c_type_with_matrix_multiplicationz/CAPITest.test_c_type_with_matrix_multiplication   s      SSb8R"45b8R"45b8R"45	RYB/0	RYB/0	RXr2./r   c                     t         j                         }| j                  |j                  d      d       | j                  |j                  dd      d       y )NrP   )rP   NrX   )rX   rX   )r   ipowTyper/   __ipow__)r!   r   s     r   test_c_type_with_ipowzCAPITest.test_c_type_with_ipow   sE      A	2Aq)62r   c                 p   t         j                  rCt        j                  d      }t	        d|      \  }}}t        |      }| j                  |d       y | j                  t              5 }t        j                          d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nz
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            r9   a#  Fatal Python error: _Py_CheckFunctionResult: a function returned NULL without setting an exception\nPython runtime state: initialized\nSystemError: <built-in function return_null_without_error> returned NULL without setting an exception\n\nCurrent thread.*:\n  File .*", line 6 in <module>\nzFreturn_null_without_error.* returned NULL without setting an exception)r   Py_DEBUGr:   r;   r   r   assertRegexr2   SystemErrorr   return_null_without_errorstr	exceptionr!   r?   rcrC   r   cms         r   test_return_null_without_errorz'CAPITest.test_return_null_without_error   s     ?? $ D 1t<LBS$CS45 "";/ 623356S.JK6 6   )B,,B5c                 p   t         j                  rCt        j                  d      }t	        d|      \  }}}t        |      }| j                  |d       y | j                  t              5 }t        j                          d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nz
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            r9   aq  Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set\nPython runtime state: initialized\nValueError\n\nThe above exception was the direct cause of the following exception:\n\nSystemError: <built-in function return_result_with_error> returned a result with an exception set\n\nCurrent thread.*:\n  File .*, line 6 in <module>\nzBreturn_result_with_error.* returned a result with an exception set)r   r   r:   r;   r   r   r   r2   r   r   return_result_with_errorr   r   r   s         r   test_return_result_with_errorz&CAPITest.test_return_result_with_error   s    ?? $ D 1t<LBS$CS78  "";/ 522245S.GH5 5r   c                     t        j                  d      }t        d|      \  }}}t        |      }d|vr| j	                  |d       y | j                  d|       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.getitem_with_error({1: 2}, 1)
        r9   zSystemError: a  Fatal Python error: _Py_CheckSlotResult: Slot __getitem__ of type dict succeeded with an exception set\nPython runtime state: initialized\nValueError: bug\n\nCurrent thread .* \(most recent call first\):\n  File .*, line 6 in <module>\n\nExtension modules: _testcapi \(total: 1\)\nz'returned a result with an exception set)r:   r;   r   r   r   assertInr!   r?   r   rC   r   s        r   test_getitem_with_errorz CAPITest.test_getitem_with_error  se         -T48CC #%S	C
D MMCSIr   c           	      N
   t         j                  }| j                   |d      d        | j                   |d      d       | j                   |d      g        | j                   |d      i        | j                   |d      dg i f       | j                   |dd      d       | j                   |d	d      d
       | j                   |dd      dg       | j                  t        |dd       | j                   |ddd      d       | j                   |ddd      d       | j                   |ddd      ddg       | j                   |ddd      ddi       | j                   |ddddd      ddd       | j                   |dd      d       | j                   |ddd      d       | j                   |d      d        | j                   |dd      d       | j                   |dd      d       | j                   |ddd      d       | j                   |ddd      d       | j                   |d dd      d       | j                   |d!dd      d       | j                   |d"dd      d       | j                   |d#dd      d       | j                   |d$dd      d       | j                   |d%dd      d       | j                   |d&dd      d       | j                   |d'dd      ddg       | j                   |d(dd      ddg       | j                   |d)dd      ddg       | j                   |d*dd      ddi       | j                   |d+dddd      ddd       | j                   |d,dddd      ddd       | j                   |d-dddd      ddd       | j                   |d.dddd      ddd       | j                  t        |dt
               | j                  t        |d	t
               | j                  t        |dt
               | j                  t        |dt
               | j                  t        |ddt
               | j                  t        |dt
        d       | j                  t        |ddt
               | j                  t        |dt
        d       | j                  t        |ddt
               | j                  t        |dt
        d       | j                  t        |ddt
               | j                  t        |dt
        d       y )/Nr   ()r   z[]z{}z()[]{}OrP   z(O)rP   z[O]z{O}OOrX   rW   z(OO)z[OO]z{OO}z{OOOO}      )rP   r   z((O)))r   z((OO)))rW   z 	,:z   O   z	O	zO,OzO, OzO,	OzO OzO	Oz(O,O)z(O, O)z ( O O) z	(	O	O)	z[O,O]z[O, O]z [ O O] z{O:O}z	{O:O,O:O}z{O: O, O: O}z { O O O O} z	{	O	O	O	O}	)r   py_buildvaluer/   r2   r   NULL)r!   
buildvalues     r   test_buildvaluezCAPITest.test_buildvalue-  s   ,,
B.D)2.D)2.D)2.H-B|<C+Q/E1-t4E1-s3+z5!<D!Q/8FAq16:FAq1Aq6:FAq1Aq6:HaAq9qQ<HGQ/9Ha3Y?G,d3Iq115GQ/3E1a0&9FAq16:GQ2F;E1a0&9FAq16:GQ2F;Ha3V<J15v>NAq96BGQ2QF;Ha3aV<J151v>GQ2QF;KAq!<!lKNAq!Q?Q1NNAq!Q?Q1N$8!Q1E1QR|T+z3=+z5$?+z5$?+z5$?+z4DA+z4qA+z61dC+z64C+z61dC+z64C+z61dC+z64Cr   c                 f   t         j                  }ddl m}m}m}m}m}m} | j                   |d|      |       | j                   |d|      |       | j                   |d|      |       | j                   |d|      |       | j                   |d|      |       | j                   |d|      |       | j                   |dd      d       | j                   |dd	      d	       | j                   |d
d      d       | j                   |dt        d            d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      t        d             | j                   |dd      t        d             | j                   |dt        j                        t        t        j                               | j                  t        |dd       | j                  t        |dt        j                  dz          y )Nr   )SHRT_MINSHRT_MAX	USHRT_MAXINT_MININT_MAXUINT_MAXrn   IhHb   iB   cA   A          CrP   )r   py_buildvalue_intsr   r   r   r   r   r   r/   ordchrrj   
maxunicoder2   rH   )r!   r   r   r   r   r   r   r   s           r   test_buildvalue_intszCAPITest.test_buildvalue_intsc  s   11
WWC17;C17;C2H=C2H=C2H=C3Y?C-s3C.5C-s3CS2D9C-w7C-w7C,g6C-s3x8C-s3x8C8#cnn:MN*j#r:*j#s~~a7GHr   c                 ,    t         j                          y rG   )r   test_buildvalue_Nr    s    r   r   zCAPITest.test_buildvalue_N}  s    ##%r   c                 r    t        j                  |      }t        d|      \  }}}| j                  |d       y )Nr9   s`   _testcapimodule\.c:[0-9]+: _Py_NegativeRefcount: Assertion failed: object has negative ref count)r:   r;   r   r   r   s        r   check_negative_refcountz CAPITest.check_negative_refcount  s9     t$,T48C;	<r   negative_refcountz"need _testcapi.negative_refcount()c                 *    d}| j                  |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.negative_refcount()
        r   r!   r?   s     r   test_negative_refcountzCAPITest.test_negative_refcount  s     	$$T*r   decref_freed_objectz$need _testcapi.decref_freed_object()zuse after free on purposeT)addressmemoryubc                 *    d}| j                  |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.decref_freed_object()
        r   r   s     r   test_decref_freed_objectz!CAPITest.test_decref_freed_object  s    
 	$$T*r   c                 F    ddl m} d }t        d      D ]  } ||f      } y )Nr   MyList  )r   r   range)r!   r   Lrn   s       r   test_trashcan_subclasszCAPITest.test_trashcan_subclass  s*     	%t 	AtA	r   cpuc                 .    | j                  t               y rG   )do_test_trashcan_python_classlistr    s    r   test_trashcan_python_class1z$CAPITest.test_trashcan_python_class1  s    **40r   c                 2    ddl m} | j                  |       y )Nr   r   )r   r   r   )r!   r   s     r   test_trashcan_python_class2z$CAPITest.test_trashcan_python_class2  s    $**62r   c                      G d d|      }dD ]b  }d }t        d      D ]  } ||f      }||_         |r|f}| j                  |j                  d       ~| j	                  |j                  d       d y )Nc                   ,     e Zd ZdZ fdZ fdZ xZS )6CAPITest.do_test_trashcan_python_class.<locals>.PyListr   c                 H    xj                   dz  c_         t        |   |  y rO   )numsuper__init__)r!   args	__class__s     r   r   z?CAPITest.do_test_trashcan_python_class.<locals>.PyList.__init__  s    " $'r   c                 0    xj                   dz  c_         y rO   )r   r!   r   s    r   __del__z>CAPITest.do_test_trashcan_python_class.<locals>.PyList.__del__  s    "r   )r%   r&   r'   r   r   r   __classcell__r   s   @r   PyListr     s     C(# #r   r   )r   rP   i   r   )r   attrassertGreaterr   r/   )r!   baser   parityr   rn   s         r   r   z&CAPITest.do_test_trashcan_python_class  s    	#T 	#  	,FA 5\ A4L Dvzz1-VZZ+	,r   c                     | j                  t        j                  j                  d       | j                  t        j                  j                  d       y )Nsomedocz(arg1, arg2))r/   r   HeapDocCTyper1   r   r    s    r   &test_heap_ctype_doc_and_text_signaturez/CAPITest.test_heap_ctype_doc_and_text_signature  s<     	//77C//BBNSr   c                 X    | j                  t        j                  j                  d        y rG   )r/   r   NullTpDocTyper1   r    s    r   test_null_type_doczCAPITest.test_null_type_doc  s    0088$?r   c                 0    G d dt         j                        } |       }t        j                  |      }| j	                  |j
                  d       | j	                  |j                  d       ~| j	                  |dz
  t        j                  |             y )Nc                        e Zd Z fdZ xZS )`CAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclassc                 0    d| _         t        | 	          y Nre   value2r   r   r   s    r   r   ziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclass.__init__        "r   r%   r&   r'   r   r   r   s   @r   HeapGcCTypeSubclassr
        # #r   r  r^   re   rP   )r   HeapGcCTyperj   getrefcountr/   valuer  )r!   r  subclass_instancetype_refcnts       r   :test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_oncezCCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once  s    	#)"7"7 	#
 01oo&9: 	*00"5*1126 q#//:M*NOr   c                     G d dt         j                         G fdd              }t        j                        }t        j                        }| j	                  |j
                  d       | j	                  |j                  d       ~t        j                  r| j	                  |j                         n| j	                  |dz
  j                         | j	                  |dz   j                         | j	                  |dz
  t        j                               | j	                  |t        j                               y )Nc                        e Zd Z fdZ xZS )dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Ac                 0    d| _         t        | 	          y r  r  r   s    r   r   zmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.A.__init__  r  r   r  r   s   @r   r   r    r  r   r   c                   ,     e Zd Z fdZfdZ xZS )dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Bc                 "    t         |           y rG   )r   r   r   s    r   r   zmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__init__  s     "r   c                 |    | _         t        j                        _        t        j                        _        y rG   )r   rj   r  refcnt_in_del)r!   r   r   s    r   r   zlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__del__  s*    !""%//!"4"%//!"4r   )r%   r&   r'   r   r   r   )r   r   r   s   @r   r   r    s    #5 5r   r   r^   re   rP   )
r   r  rj   r  r/   r  r  r   r   r!  )r!   r  r  new_type_refcntr   r   s       @@r   Ptest_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_oncezYCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once  s   	#	%% 	#
	5 	5 Cooa(//!, 	*00"5*1126  [!//:[1_aoo>1,aoo> 	q#//!*<= 	#//!*<=r   c                 Z   t         j                         }d|_        | j                  |j                  d       | j                  |j                  |j
                         | j                  |j                  ddi       t         j                         }| j                  i |j
                         y Nr   foo)r   HeapCTypeWithDictr&  r/   dictobj__dict__r5   s     r   test_heaptype_with_dictz CAPITest.test_heaptype_with_dict  s}    **,2&t}}5r{3**,T]]+r   c                 ~   t         j                         }d|_        | j                  |j                  d       | j                  |j                  ddi       t         j                         }| j                  i |j                         t         j                         }t         j                         }||_        ||_        ~~y r%  )r   HeapCTypeWithManagedDictr&  r/   r)  r   a)r!   r6   r-  r   s       r   test_heaptype_with_managed_dictz(CAPITest.test_heaptype_with_managed_dict  s    1132&4113T]]+..0..0qr   c                 T     G d dt         j                        } |       }||_        ~y )Nc                       e Zd Zy)2CAPITest.test_sublclassing_managed_dict.<locals>.CNr%   r&   r'   r   r   r   r   r1  .      r   r   )r   r,  spam)r!   r   rn   s      r   test_sublclassing_managed_dictz'CAPITest.test_sublclassing_managed_dict,  s'    		22 	 Cr   c                 Z   t         j                         }d|_        | j                  |j                  d       | j                  |j                  |j
                         | j                  |j                  ddi       t         j                         }| j                  i |j
                         y r%  )r   HeapCTypeWithNegativeDictr&  r/   r(  r)  r5   s     r    test_heaptype_with_negative_dictz)CAPITest.test_heaptype_with_negative_dict5  s}    2242&t}}5r{3224T]]+r   c                     t         j                         }t        j                  |      }| j	                   |       |       | j	                  |j
                  |       y rG   )r   HeapCTypeWithWeakrefweakrefrefr/   weakreflistr!   r6   r<  s      r   test_heaptype_with_weakrefz#CAPITest.test_heaptype_with_weakref?  sF    --/kk$%))3/r   c                     t         j                         }t        j                  |      }| j	                   |       |       y rG   r   HeapCTypeWithManagedWeakrefr;  r<  r/   r>  s      r   "test_heaptype_with_managed_weakrefz+CAPITest.test_heaptype_with_managed_weakrefE  s0    446kk$%r   c                      G d dt         j                        } |       }t        j                  |      }| j	                   |       |       y )Nc                       e Zd Zy)5CAPITest.test_sublclassing_managed_weakref.<locals>.CNr2  r   r   r   r   rF  L  r3  r   r   rA  )r!   r   r6   r<  s       r   !test_sublclassing_managed_weakrefz*CAPITest.test_sublclassing_managed_weakrefJ  s=    		55 	 skk$%r   c                     G d dt         j                  t         j                        } G d dt         j                  t         j                        }||fD ]n  } |       }t        j                  |      }| j                   |       |       ||_        ~t        j                   |             }| j                   |       d        p y )Nc                       e Zd Zy)3CAPITest.test_sublclassing_managed_both.<locals>.C1Nr2  r   r   r   C1rJ  U  r3  r   rK  c                       e Zd Zy)3CAPITest.test_sublclassing_managed_both.<locals>.C2Nr2  r   r   r   C2rM  X  r3  r   rN  )r   rB  r,  r;  r<  r/   r4  assertIs)r!   rK  rN  clsr6   r<  s         r   test_sublclassing_managed_bothz'CAPITest.test_sublclassing_managed_bothS  s    	66	8Z8Z 		33Y5Z5Z 	 8 	'C5D++d#CSUD)DI++ce$CMM#%&	'r   c                 f    t         j                         }t        |      }| j                  |d       y )Ns   1234)r   HeapCTypeWithBufferbytesr/   )r!   r6   r   s      r   test_heaptype_with_bufferz"CAPITest.test_heaptype_with_bufferd  s)    ,,.$KG$r   c                 P   t         j                         }t        j                  t         j                        }| j	                  |j
                  d       | j	                  |j                  d       ~| j	                  |dz
  t        j                  t         j                               y Nr^   re   rP   )r   HeapCTypeSubclassrj   r  r/   r  r  )r!   r  r  s      r   9test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncezBCAPITest.test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncei  s}    %779ooi&A&AB 	*00"5*1126 q#//):U:U*VWr   c                 &   t         j                         }t        j                  t         j                        }t        j                  t         j                        }| j                  |j                  d       | j                  |j                  d       ~t        j                  r+| j                  |t         j                  j                         n-| j                  |dz
  t         j                  j                         | j                  |dz   t         j                  j                         | j                  |dz
  t        j                  t         j                               | j                  |t        j                  t         j                               y rW  )r   HeapCTypeSubclassWithFinalizerrj   r  rX  r/   r  r  r   r   r!  )r!   r  r  r"  s       r   Otest_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_oncezXCAPITest.test_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_onceu  s   %DDFooi&N&NO//)*E*EF 	*00"5*1126   [)*R*R*`*`a[1_i.V.V.d.de1,i.I.I.W.WX 	q#//):b:b*cd 	#//):U:U*VWr   c                     t         j                         }| j                  |j                  d       d|_        | j                  |j                  d       |`| j                  |j                  d       y )Nr^   r`   r   )r   HeapCTypeSetattrr/   pvaluer  )r!   objs     r   test_heaptype_with_setattroz$CAPITest.test_heaptype_with_setattro  sX    ((*R(	R(IQ'r   c                    t         j                  }| j                  t        |t                     t         j                  |      }| j                  |t               | j                  |j                  d       | j                  t	        |      |        |ddi       }| j                  |t               | j                  |j                  d       y )NHeapCTypeViaMetaclassPyClassViaMetaclassr   )
r   HeapCTypeMetaclassr0   
issubclasstypepytype_fromspec_metaassertIsInstancer/   r%   rO  r!   	metaclassts      r   #test_heaptype_with_custom_metaclassz,CAPITest.test_heaptype_with_custom_metaclass  s    00	
9d34 **95a&%<=d1gy) +R4a&%:;r   c                    t         j                  }| j                  t        |t                     t         j                  |      }| j                  |t               | j                  |j                  d       | j                  t	        |      |       | j                  t        d      5   |ddi        d d d        y # 1 sw Y   y xY w)Nrc  zcannot create .* instancesrd  r   )r   HeapCTypeMetaclassNullNewr0   rf  rg  rh  ri  r/   r%   rO  rr   rs   rj  s      r   ,test_heaptype_with_custom_metaclass_null_newz5CAPITest.test_heaptype_with_custom_metaclass_null_new  s    77	
9d34 **95a&%<=d1gy) ##I/KL 	5+R4	5 	5 	5s   (B<<Cc                    t         j                  }| j                  t        t         j                  t                     d}| j                  t        |      5  t         j                  |      }d d d        y # 1 sw Y   y xY w)Nz1Metaclasses with custom tp_new are not supported.)r   HeapCTypeMetaclassCustomNewr0   rf  rg  rr   rs   rh  )r!   rk  rD   rl  s       r   .test_heaptype_with_custom_metaclass_custom_newz7CAPITest.test_heaptype_with_custom_metaclass_custom_new  s`    99	
9#H#H$OPA##Is3 	:..y9A	: 	: 	:s   A55A>c                     t         j                  } G d d|      }t        j                  dt        f      5  t         j                  |      }d d d        | j                  t        |             | j                  ||       y # 1 sw Y   7xY w)Nc                       e Zd Zy)FCAPITest.test_heaptype_with_custom_metaclass_deprecation.<locals>.BaseNr2  r   r   r   Baserv    r3  r   rw  )rk  z8.* _testcapi.Subclass .* custom tp_new.*in Python 3.14.*)	r   rr  r	   check_warningsDeprecationWarningmake_type_with_baser0   rf  ri  )r!   rk  rw  subs       r   /test_heaptype_with_custom_metaclass_deprecationz8CAPITest.test_heaptype_with_custom_metaclass_deprecation  s~    99	
	Y 	 ++KM_` 	6 //5C	6 	
3-.c9-	6 	6s   BBc                 L   | j                  t              5   G d dt        j                  t        j                        }d d d        | j                  t              5   G d dt        j                  t        j                        }d d d        y # 1 sw Y   PxY w# 1 sw Y   y xY w)Nc                       e Zd Zy)MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both1Nr2  r   r   r   Both1r        r   r  c                       e Zd Zy)MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both2Nr2  r   r   r   Both2r    r  r   r  )r2   rs   r   r:  r'  )r!   r  r  s      r   5test_multiple_inheritance_ctypes_with_weakref_or_dictz>CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict  s    y) 		66	8S8S 	 y) 		33Y5S5S 	 		 		 	s   )B)BBB#c                 0   | j                  t              5   G d dt        j                  t              }d d d        | j                  t              5   G d dt        j
                  t              }d d d         G d dt        j                  t              } G d dt        j                  t              } |       }|j                  d	       t        |j                          |       }|j                  d	       t        |j                         t        j                  t        j                  fD ]K  }t        j                  t        j
                  fD ]  } G d
 d||      }  G d d||      }	 G d d||      }
M y # 1 sw Y   KxY w# 1 sw Y   xY w)Nc                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C1Nr2  r   r   r   rK  r    r  r   rK  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C2Nr2  r   r   r   rN  r    r  r   rN  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C3Nr2  r   r   r   C3r    r3  r   r  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C4Nr2  r   r   r   C4r    r3  r   r  r   c                       e Zd Zy)[CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.SNr2  r   r   r   Sr    s    r   r  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.B1Nr2  r   r   r   B1r    r  r   r  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.B2Nr2  r   r   r   B2r    r  r   r  )r2   rs   r   r'  r   r:  r,  rB  appendr   r)  __weakref__)r!   rK  rN  r  r  r6   rP  cls2r  r  r  s              r   Gtest_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtinzPCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin  sD   y) 	Y00$ 	 y) 	Y33T 		33T 		66 	 tADMMtAD66	8]8]^ 	C"44i6T6TU T R R 	+	 		 	s   E>F>FFc                     t        d      D ]P  }| j                  |      5  | j                  t              5  t        j                  |       d d d        d d d        R y # 1 sw Y   xY w# 1 sw Y   ixY w)NrX   )variant)r   subTestr2   r   r   create_type_from_repeated_slots)r!   r  s     r   (test_pytype_fromspec_with_repeated_slotsz1CAPITest.test_pytype_fromspec_with_repeated_slots  sy    Qx 	GGg. G&&{3 G==gFGG G	GG GG Gs"   A,A A, A)%A,,A5	categoryc                    t        j                  dd        G d d      }| j                  t              5  t        j                  |      }d d d                }| j                  |j                         d       | j                  t        d      5  d |_        d d d        | j                  |j                         d       d	 |_        | j                  |j                         d
       y # 1 sw Y   xY w# 1 sw Y   ^xY w)Nz-creating immutable classes with mutable bases)r   rb   )removec                       e Zd Zd Zy)CCAPITest.test_immutable_type_with_mutable_base.<locals>.MutableBasec                      y)Noriginalr   r    s    r   r   zHCAPITest.test_immutable_type_with_mutable_base.<locals>.MutableBase.meth  s    !r   N)r%   r&   r'   r   r   r   r   MutableBaser    s    "r   r  r  z-cannot set 'meth' attribute of immutable typec                      y)N
overriddenr   r    s    r   <lambda>z@CAPITest.test_immutable_type_with_mutable_base.<locals>.<lambda>      r   c                      y)Nchangedr   r    s    r   r  z@CAPITest.test_immutable_type_with_mutable_base.<locals>.<lambda>  r  r   r  )
warnings_deprecatedassertWarnsry  r   make_immutable_type_with_baser/   r   rr   rs   )r!   r  ImmutableSubclassinstances       r   %test_immutable_type_with_mutable_basez.CAPITest.test_immutable_type_with_mutable_base  s     	;G	M	" 	" 01 	 ) G G!	 %&*5 ##?A 	? &?"	? 	*5 2)4!	 		? 	?s   C,	C8,C58Dc           	         ddl m} d}d} G d d      }d}|D ]  \  }}}| j                  |||      5  | j                   |||      |       | j                   || |      d	|z          | j                   | ||      |      |       | j                   |||      |       | j                   || |      d	|z          | j                   | ||      |      |       d d d         | j	                  t
        | |d
      d       | j	                  t
        | |d      d       | j	                  t
        |d
d       | j	                  t
        |dd       | j	                  t        |dd       y # 1 sw Y   _xY w)Nr   )pynumber_tobase{   l            c                       e Zd Zd Zd Zy)*CAPITest.test_pynumber_tobase.<locals>.IDXc                     || _         y rG   val)r!   r  s     r   r   z3CAPITest.test_pynumber_tobase.<locals>.IDX.__init__   s	    r   c                     | j                   S rG   r  r    s    r   	__index__z4CAPITest.test_pynumber_tobase.<locals>.IDX.__index__"  s    xxr   N)r%   r&   r'   r   r  r   r   r   IDXr    s     r   r  ))rX   	0b1111011C0b10000000000000000000000000000000000000000000000000000000000000000)r\   0o1730o2000000000000000000000)r^   12318446744073709551616)   0x7b0x10000000000000000)r   stlt-g     ^@r^   r  )r   r  r  r/   r2   rs   r   )	r!   r  small_numberlarge_numberr  
test_casesr   small_targetlarge_targets	            r   test_pynumber_tobasezCAPITest.test_pynumber_tobase  s{   -	  	 ;
 1; 		Y,D,4L\J Y  t!DlS  ,!Es\GYZ  \1BD!I<X  t!DlS  ,!Es\GYZ  \1BD!I<XY Y		Y 	)_c%j"E)_c%j"E)_eR@)_eR@+Q?Y Ys   B+E..E8	c                 P    t         j                         }| j                  |d       y Nz<NULL>)r   pyobject_repr_from_nullr/   r!   ss     r   test_pyobject_repr_from_nullz%CAPITest.test_pyobject_repr_from_null9  s     --/H%r   c                 P    t         j                         }| j                  |d       y r  )r   pyobject_str_from_nullr/   r  s     r   test_pyobject_str_from_nullz$CAPITest.test_pyobject_str_from_null=  s     ,,.H%r   c                 P    t         j                         }| j                  |d       y )Ns   <NULL>)r   pyobject_bytes_from_nullr/   r  s     r   test_pyobject_bytes_from_nullz&CAPITest.test_pyobject_bytes_from_nullA  s     ..0I&r   c                     t         j                  }d} ||      }t        |dd      }| j                  |j                  |j                         y )Ns%   # -*- coding: latin1 -*-
print('¤')
z<string>exec)r   Py_CompileStringcompiler/   	co_consts)r!   _compiler?   resultexpecteds        r   test_Py_CompileStringzCAPITest.test_Py_CompileStringE  sE    --?$4V4))8+=+=>r   c                 b   t        j                  d      }g }t        t        d      r|j	                  d       t
        j                  dk7  r|j	                  d       |D ]B  }| j                  |      5  | j                  t        |j                  |             d d d        D y # 1 sw Y   OxY w)Nctypesget_native_idPyThread_get_thread_native_idntPy_FrozenMain)name)
r   import_modulehasattr_threadr  osr  r  r0   	pythonapi)r!   r  namesr  s       r   test_export_symbolszCAPITest.test_export_symbolsM  s     ,,X6 7O,LL89 77d?LL) 	AD4( A(8(8$ ?@A A	AA As   4&B%%B.	c                 4    G d d      } |       }t         j                  |       | j                  |j                  i         |       }| j                  |j                  ddi       t         j                  |       | j                  |j                  i        y )Nc                       e Zd Zd Zy)+CAPITest.test_clear_managed_dict.<locals>.Cc                     d| _         y rO   r-  r    s    r   r   z4CAPITest.test_clear_managed_dict.<locals>.C.__init__g  s	    r   N)r%   r&   r'   r   r   r   r   r   r  f  s    r   r   r-  rP   )r   clear_managed_dictr/   r)  )r!   r   r   s      r   test_clear_managed_dictz CAPITest.test_clear_managed_dictd  sx    	 	 C$$Q'R(Cc!W-$$Q'R(r   c                    d } G d d      }| j                  t        j                  |      d       | j                  t        j                  |j                        d       | j                  t        j                   |       j                        d       | j                  t        j                  t              d       | j                  t        j                  |      d       y )Nc                       y rG   r   r   r   r   function_examplez:CAPITest.test_eval_get_func_name.<locals>.function_examples      r   c                       e Zd Zd Zy)+CAPITest.test_eval_get_func_name.<locals>.Ac                      y rG   r   r    s    r   method_examplez:CAPITest.test_eval_get_func_name.<locals>.A.method_examplev      cr   Nr%   r&   r'   r  r   r   r   r   r  u      )r   r   r  r  sumrg  )r/   r   eval_get_func_namer  r  r!   r  r   s      r   test_eval_get_func_namez CAPITest.test_eval_get_func_namer  s    #	* 	* 	556FG+	-55a6F6FG)	+55ac6H6HI)	+55c:EB55a8&Ar   c                    d } G d d      }| j                  t        j                  |      d       | j                  t        j                  |j                        d       | j                  t        j                   |       j                        d       | j                  t        j                  t              d       | j                  t        j                  |      d       y )Nc                       y rG   r   r   r   r   r  z:CAPITest.test_eval_get_func_desc.<locals>.function_example  r  r   c                       e Zd Zd Zy)+CAPITest.test_eval_get_func_desc.<locals>.Ac                      y rG   r   r    s    r   r  z:CAPITest.test_eval_get_func_desc.<locals>.A.method_example  r  r   Nr	  r   r   r   r   r    r
  r   r   r   z object)r/   r   eval_get_func_descr  r  r  s      r   test_eval_get_func_descz CAPITest.test_eval_get_func_desc  s    #	* 	* 	556FG	55a6F6FG	55ac6H6HI	55c:DA55a8)Dr   c                 *   dd l }d }t        j                  |      }| j                  ||j                         | j                  ||j                         | j                  t              5  t        j                  d        d d d        y # 1 sw Y   y xY w)Nr   c                       y rG   r   r   r   r   somez-CAPITest.test_function_get_code.<locals>.some      r   )	typesr   function_get_coderi  CodeTyper/   __code__r2   r   )r!   r  r  r?   s       r   test_function_get_codezCAPITest.test_function_get_code  su    	 **40dENN3t}}-{+ 	.''-	. 	. 	.s   *B		Bc                    d }t         j                  |      }| j                  |t               | j	                  ||j
                         | j                  t              5  t         j                  d        d d d        y # 1 sw Y   y xY w)Nc                       y rG   r   r   r   r   r  z0CAPITest.test_function_get_globals.<locals>.some  r  r   )r   function_get_globalsri  dictr/   __globals__r2   r   )r!   r  globals_s      r   test_function_get_globalsz"CAPITest.test_function_get_globals  sp    	 11$7h-4#3#34{+ 	1**40	1 	1 	1    A??Bc                    d }t         j                  |      }| j                  |t               | j	                  ||j
                         | j                  t              5  t         j                  d        d d d        y # 1 sw Y   y xY w)Nc                       y rG   r   r   r   r   r  z/CAPITest.test_function_get_module.<locals>.some  r  r   )r   function_get_moduleri  r   r/   r&   r2   r   )r!   r  modules      r   test_function_get_modulez!CAPITest.test_function_get_module  sn    	 ..t4fc*1{+ 	0))$/	0 	0 	0r&  c                    	 	 dddd}t         j                  |      }| j                  |d       | j                  ||j                         | j	                  t
              5  t         j                  d        d d d        y # 1 sw Y   y xY w)NTkw2c                    y rG   r   	pos_only1	pos_only2zerooptionalkw1r.  s         r   r  z1CAPITest.test_function_get_defaults.<locals>.some       r   pr   N)r   function_get_defaultsr/   __defaults__r2   r   r!   r  defaultss      r   test_function_get_defaultsz#CAPITest.test_function_get_defaults  s    !$!	 	 2248>24#4#45{+ 	2++D1	2 	2 	2s   "BB
c                    	 	 dddd}d}| j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  |d       d d d        | j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  dd       d d d        | j                  t        j                  |      |       | j                  |j                  |       d}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       d}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |        G d d	t              } |d
ddgd f      }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       t        j                  |d        | j                  t        j                  |      d        | j                  |j                  d        y # 1 sw Y   =xY w# 1 sw Y   xY w)NTr-  c                    y rG   r   r0  s         r   r  z1CAPITest.test_function_set_defaults.<locals>.some  r6  r   r7  rP   r   )qrP   Nc                       e Zd Zy)5CAPITest.test_function_set_defaults.<locals>.tuplesubNr2  r   r   r   tuplesubrB        r   rC  rW   r-  r   )r/   r   r9  r:  r2   r   function_set_defaultstuple)r!   r  old_defaultsnew_defaultsrC  s        r   test_function_set_defaultsz#CAPITest.test_function_set_defaults  sG   !$!	 	 &88>M**L9{+ 	5++D!4	588>M**L9{+ 	3++Ar2	388>M**L9%''l;88>M**L9 ''l;88>M**L9"u"#sT :;''l;88>M**L9 	''d388>E**D1A	5 	5
	3 	3s   "J4K4J>Kc                    	 	 dddd}t         j                  |      }| j                  |ddi       | j                  ||j                         | j	                  t
              5  t         j                  d        d d d        y # 1 sw Y   y xY w)NTr-  c                    y rG   r   r0  s         r   r  z4CAPITest.test_function_get_kw_defaults.<locals>.some  r6  r   r.  r7  )r   function_get_kw_defaultsr/   __kwdefaults__r2   r   r;  s      r   test_function_get_kw_defaultsz&CAPITest.test_function_get_kw_defaults  s    !$!	 	 55d;E4=14#6#67{+ 	5..t4	5 	5 	5s   $BBc                    	 	 d	ddd}ddi}| j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  |d       d d d        | j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  di        d d d        | j                  t        j                  |      |       | j                  |j                  |       ddi}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       i }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |        G d dt              } |dd i      }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       t        j                  |d        | j                  t        j                  |      d        | j                  |j                  d        y # 1 sw Y   <xY w# 1 sw Y   xY w)
NTr-  c                    y rG   r   r0  s         r   r  z4CAPITest.test_function_set_kw_defaults.<locals>.some	  r6  r   r.  rP   rP   rX   r   c                       e Zd Zy)7CAPITest.test_function_set_kw_defaults.<locals>.dictsubNr2  r   r   r   dictsubrS  ,  rD  r   rT  r7  )r/   r   rL  rM  r2   r   function_set_kw_defaultsr"  )r!   r  rG  rH  rT  s        r   test_function_set_kw_defaultsz&CAPITest.test_function_set_kw_defaults  sI   !$!	 	 t};;DA<P,,l;{+ 	8..tQ7	8;;DA<P,,l;{+ 	6..q"5	6;;DA<P,,l;y)**4>;;DA<P,,l; **4>;;DA<P,,l; d t}-**4>;;DA<P,,l; 	**46;;DA4H,,d3A	8 	8
	6 	6s   $J5K5J?Kc                 P    G d dt         j                        } |       }d|_        d|_        d|_        | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       |`| j                  |j                         y )Nc                       e Zd ZdZy);CAPITest.test_unstable_gc_new_with_extra_data.<locals>.Data)xyN)r%   r&   r'   	__slots__r   r   r   DatarY  :  s    "Ir   r]  r^   re      )r   ObjExtraDatarZ  r[  extrar/   assertIsNone)r!   r]  ds      r   $test_unstable_gc_new_with_extra_dataz-CAPITest.test_unstable_gc_new_with_extra_data9  s    	#9)) 	# Fb!b!"%G!''"r   N)Or%   r&   r'   r7   r   requires_subprocessrE   rJ   r   
skipUnlessrt   rx   r~   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   skip_if_sanitizerr   r   requires_resourcer   r   r   r  r  r  r#  r*  r.  r5  r8  r?  rC  rG  rQ  rU  rY  r\  ra  rm  rp  rs  r|  r  r  r  r	   ignore_warningsry  r  r  r  r  r  r  r  r  r  r  r  r%  r+  r=  rI  rN  rV  rc  r   r   r   r+   r+   K   s   	[ !W  " #*S X)+UVk Wk" X)+UVp Wp X__)MO''O''R0"3K: HDJ<4DlI4&< X,?@=?+?+ X,AB?AW:'+DTC+CA+ Wu%1 &1 Wu%3 &3,8 X__)MOTOT@P"&>P,,0&
&'"%

XX6(<5:."@G %_$$.@A5 B56@<&&'?A.)BE.	1	02$/2b5$/4b#r   r+   c                   D    e Zd ZdZed        Zd Zd Zd Zd Z	d Z
d Zy	)
TestHeapTypeRelativez-Test API for extending opaque types (PEP 697)c                 0     fd}t        dddddddd	t        j                  t        j                  dz
  t        j                  dz   h      }|D ]9  }|D ]2  }t        ||
      }  j                  di |5   |di | d d d        4 ; y # 1 sw Y   AxY w)Nc                    t         j                  | |       \  }}}}}}|dk(  r9
j                  |j                  |j                         
j                  |d       nd|j                  df|df||z   df||z   df|j                  dfg}t	        |t        j                  d            }	
j                  ||	d	|	 
       
j                  |j                  ||z          
j                  ||z
  t         j                         
j                  |t         j                  z  d       
j                  |t         j                  z  d       y )Nr   )r   zstart of objectzend of base datazsubclass datazend of requested subcls datazend of reserved subcls datazend of object)keyz$Offsets not in expected order, got: rD   )	r   make_sized_heaptypesr/   __basicsize__sortedoperator
itemgetter
assertLessALIGNOF_MAX_ALIGN_T)extra_base_size
extra_sizerw  Subr  data_ptrdata_offset	data_sizeoffsetsordered_offsetsr!   s             r   checkz@TestHeapTypeRelative.test_heaptype_relative_sizes.<locals>.checkO  s\   ..#j[2 BD#x;	
 Q  !3!3S5F5FG  A.
 +'');< /2 :-/MN 9,.KL&&8 #)h6I6I!6L"M  _>>OP ! R
   !2!2K)4KL 	J 6 ) = =? [9+H+HH!LY)F)FFJr   r   rP   rX   r   r   r[   r\   r  rv  rw  r   )rq  rq   rp  r"  r  )r!   r~  sizesrv  rw  r   s   `     r   test_heaptype_relative_sizesz1TestHeapTypeRelative.test_heaptype_relative_sizesL  s    "	KH 1aAq!S,,,,Q.,,Q.0 1  % 	"O# "
O'13!T\\)D) "MDM" ""	"" "s   6	BBc                 l    t         j                  ddd      }| j                  t        |      g d       y)z2Make sure HeapCCollection works properly by itselfrP   rX   r   rQ  N)r   HeapCCollectionr/   r   )r!   
collections     r   test_HeapCCollectionz)TestHeapTypeRelative.test_HeapCCollection~  s+    ..q!Q7
j)95r   c                 B   t        ddddddddt        j                  t        j                  dz
  t        j                  dz   h      }|D ]  }| j                  |	      5  t        j                  t        j                  | dd      } |ddd      }|j                          | j                  t        |      g d
       |j                         }| j                  t        |      |       | j                  t        |      dhk  d|       ddd        y# 1 sw Y   xY w)-Test HeapCCollection subclasses work properlyr   rP   rX   r   r   r[   r\   r  )rw  rQ  zgot N)rq  rq   rp  r  r   subclass_var_heaptyper  set_data_to_3sr/   r   get_dataassertGreaterEquallenr0   set)r!   r  rw  rx  r  mems         r   test_heaptype_inherit_itemsizez3TestHeapTypeRelative.test_heaptype_inherit_itemsize  s   1aAq!S,,,,Q.,,Q.0 1   
	AJ4 	A55--
{AqB Aq\
))+  j!19= ))+''C*=CQC4w@	A 	A
	A	A 	As   B,DD	c                     | j                  t        d      5  t        j                  t        dd       d d d        y # 1 sw Y   y xY w)NzACannot extend variable-size class without Py_TPFLAGS_ITEMS_AT_ENDrn  r   )r2   r   r   subclass_heaptypeintr    s    r   !test_heaptype_invalid_inheritancez6TestHeapTypeRelative.test_heaptype_invalid_inheritance  sE    {$;  < 	4 ''R3	4 	4 	4s	   =Ac                    t        ddddddddt        j                  t        j                  dz
  t        j                  dz   h      }|D ]  }|D ]  }|D ]N  }| j                  |||	      5  ||k  rt        j                  || |d
      }|j                         d   } |       }| j                  |j                  |j                                |j                  d       | j                  |j                  |j                                | j                  |j                         d       d|_        | j                  |j                  |j                                | j                  |j                         d       | j                  |j                         |j                         | j                  |j                         |j                         | j                  t              5  |j!                          ddd       | j                  t              5  |j#                  d       ddd       n7| j                  t              5  t        j                  || |d
      }ddd       | j                  t              5  t        j                  |||d
      }ddd       ddd       Q | j                  ||      5  | j                  t              5  t        j                  || dd
      }ddd       d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   xY w# 1 sw Y   VxY w# 1 sw Y   xY w)r  r   rP   rX   r   r   r[   r\   r  )rv  rw  offsetTra   rb   Nr  r   )rq  rq   rp  r  r   make_heaptype_with_membermror/   membget_membset_membr  get_memb_offsetrt  r2   r   get_memb_relativeset_memb_relative)r!   r  rv  rw  r  rx  rw  r  s           r   test_heaptype_relative_membersz3TestHeapTypeRelative.test_heaptype_relative_members  s$   1aAq!S,,,,Q.,,Q.0 1  %  	DO# D
# KFoR\ekl K!J."+"E"E /*fd#LC#&779Q<D'*uH ,,X]]H<M<M<OP$--b1 ,,X]]H<M<M<OP ,,X->->-@"E,.HM ,,X]]H<M<M<OP ,,X->->-@"E 33H4L4L4NPTPbPbc OOH,D,D,FHYHYZ!%!2!2;!? = ( : : <=!%!2!2;!? > ( : :1 => > "&!2!2;!? P&/&I&I$3j[&$'PP "..{; K"+"E"E /VT#KCK/K KK6 \\/j\Y D**;7 D'AA+j["dDDD D9D 	D$= => >P PK K/K K6D DD Ds   -E9L2	&L7L2	L&L2	LL2	;L&L2	:ML?	*MLL2	LL2	L#L2	&L/+L2	2L<?MMMc                    | j                  t        d      5  t        j                  dddd       d d d        | j                  t        d      5  t        j                  dddd       d d d        | j                  t        d      5  t        j                  dddd       d d d        t        j                  dddd      } |       }| j                  t        d      5  |j	                          d d d        | j                  t        d	      5  |j                  d       d 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   y xY w)
Nz3With Py_RELATIVE_OFFSET, basicsize must be negativer   i  Tz.Member offset out of range \(0\.\.-basicsize\)r  r   z,PyMember_GetOne used with Py_RELATIVE_OFFSETz,PyMember_SetOne used with Py_RELATIVE_OFFSET)rr   r   r   r  r  r  )r!   rx  r  s      r   %test_heaptype_relative_members_errorsz:TestHeapTypeRelative.test_heaptype_relative_members_errors  sb   ##FH 	B //4DA	B ##NP 	C//2tTB	C ##NP 	A//2r4@	A 11!RDA5##LN 	)&&(	) ##LN 	*&&q)	* 	*!	B 	B	C 	C	A 	A	) 	)	* 	*s;   D%D1D=E	
E%D.1D:=E	EEc                     | j                  t              5  t        j                  d       ddd       | j                  t              5  t        j                  d       ddd       y# 1 sw Y   =xY w# 1 sw Y   yxY w)z4Test PyObject_GetItemData fails on unsupported typesNr   )r2   rs   r   pyobject_getitemdatar    s    r   test_pyobject_getitemdata_errorz4TestHeapTypeRelative.test_pyobject_getitemdata_error  sm    y) 	1**40	1 y) 	. **1-	. 	.	1 	1	. 	.s   A(	A4(A14A=N)r%   r&   r'   r1   r
   r  r  r  r  r  r  r  r   r   r   rj  rj  H  s9    7/" /"b6
A$4&DP**.r   rj  c                       e Zd Zd ZddZ ej                         d        Zd Zd Z	d Z
 G d d	ej                        Z ej                         d
        Z ej                         d        Zed        Zy)TestPendingCallsc                     fd}t        |      D ]C  }t        j                  t        j                         dz         	 t        j                  |      rD y )Nc                  (     j                  d        y rG   r  )ls   r   callbackz6TestPendingCalls.pendingcalls_submit.<locals>.callback  s     HHTNr   g{Gz?)r   timesleeprandomr   _pending_threadfunc)r!   r  nr  rn   s    `   r   pendingcalls_submitz$TestPendingCalls.pendingcalls_submit  sO    	
 q 	AJJv}}t+, 00: 	r   Nc                     d}t        |      |k7  rj	 t	        d      D ]  }||z  }	 |r|j
                  j                         sA|dz  }| j                  |dk  d|t        |      fz         t        |      |k7  rjy )Nr   r   rP   i'  z(timeout waiting for %i callbacks, got %i)r  r   verboseprintr   eventis_setr0   )r!   r  r  contextcountrn   r-  s          r   pendingcalls_waitz"TestPendingCalls.pendingcalls_wait  s    !fk 4[ aCw}}335QJEOOEEM:As1v;FH !fk r   c                 
   d}g } G d dt               } |       }g |_        d|_        ||j                  z  |_        d|_        t        j                         |_        t        j                         |_	        t        |j                        D cg c]$  }t        j                  | j                  |f      & }}t        j                  |      5  | j                  |j                  ||       d d d        y c c}w # 1 sw Y   y xY w)N    c                       e Zd Zy)8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooNr2  r   r   r   r&  r    rD  r   r&  rX   r   targetr   )rq   r  r  nThreads	nFinished	threadingLocklockEventr  r   Threadpendingcalls_threadr   start_threadsr  )r!   r  threadsr&  r  rn   s         r   test_pendingcalls_threadedz+TestPendingCalls.test_pendingcalls_threaded  s     &%				> ~~'!) "'"2"235 ##4+C+C*15 5 5 ++G4 	:""799a9	: 	:5	: 	:s   )C4C99Dc                    	 | j                  |j                  |j                         |j                  5  |xj                  dz  c_        |j                  }	 d d d        |j                  k(  r|j                  j                          y y # 1 sw Y   4xY w# |j                  5  |xj                  dz  c_        |j                  }	 d d d        n# 1 sw Y   nxY w|j                  k(  r|j                  j                          w w xY wrO   )r  r  r  r  r  r   r  r  r  r  r  )r!   r  r  s      r   r  z$TestPendingCalls.pendingcalls_thread   s    		$$$WYY		: ;!!Q&!#--	;
 G,,,!!# -; ; ;!!Q&!#--	; ; ;
 G,,,!!# -s.   &B "B

BD#"C	DC2Dc                 T    g }d}| j                  ||       | j                  ||       y )N@   )r  r  )r!   r  r  s      r   test_pendingcalls_non_threadedz/TestPendingCalls.test_pendingcalls_non_threaded,  s.    
   A&q!$r   c                 v    d } |       }| j                  t        j                  |      |j                         y )Nc               3      K   d  y wrG   r   r   r   r   genfz0TestPendingCalls.test_gen_get_code.<locals>.genf7  s     E   )r/   r   gen_get_codegi_code)r!   r  gens      r   test_gen_get_codez"TestPendingCalls.test_gen_get_code6  s+    f//4ckkBr   c                   J    e Zd Zej                  ZddZd Zd Zd Z	d Z
d Zy)	TestPendingCalls.PendingTaskNc                     || _         || _        || _        t        j                         | _        d | _        d | _        d | _        y rG   )	r)   reqnotify_doner  	get_identcreator_tidrequester_tid
runner_tidr  )r!   r  taskidr  s       r   r   z%TestPendingCalls.PendingTask.__init__?  s?    DGDH*D(224D!%D"DODKr   c                     | j                   J t        j                         | _        | j	                          | j
                  | j                          y y rG   )r  r  r  r  _runr  r    s    r   runz TestPendingCalls.PendingTask.runI  sH    ;;&&&'113DOIIK+  " ,r   c                 &    | j                   | _        y rG   )r  r  r    s    r   r  z!TestPendingCalls.PendingTask._runP  s    ((DKr   c                       j                   t        j                  u sJ t        j                          _         fd j                  d       y )Nc                      j                   J t        j                         vrj                   d       y j	                          y )NTensure_added)r  r  r  _add_pendingr  )r  r!   worker_tidss   r   r  zBTestPendingCalls.PendingTask.run_in_pending_call.<locals>.callbackV  sE    {{*** &&(;%%hT%B
r   Tr  )r  _testinternalcapipending_threadfuncr  r  r  )r!   r  r  s   ``@r   run_in_pending_callz0TestPendingCalls.PendingTask.run_in_pending_callS  sI    $$(9(L(LLLL!*!4!4!6D hT:r   c                 F    t        j                  | j                  |f      S )Nr  )r  r  r  )r!   r  s     r   create_threadz*TestPendingCalls.PendingTask.create_threada  s#    ##//!^ r   c                 b    | j                   #t        j                  d       | j                   "y y N{Gz?)r  r  r  r    s    r   wait_for_resultz,TestPendingCalls.PendingTask.wait_for_resultg  s$    ++%

4  ++%r   )NN)r%   r&   r'   r  r  r  r   r  r  r  r  r  r   r   r   PendingTaskr  ;  s+    (;;		#	#	;		!r   r  c                     d}| j                  |      fd}t        j                  |      }t        j                  |g      5  	 d d d        | j                  j                  |       y # 1 sw Y   &xY w)Nz1Spam spam spam spam. Lovely spam! Wonderful spam!c                      t        j                         } j                  | h      }t        j                  |g      5  j                          d d d        y # 1 sw Y   y xY wrG   )r  r  r  r   r  r  )tidrl  tasks     r   do_the_workzNTestPendingCalls.test_subthreads_can_handle_pending_calls.<locals>.do_the_workp  sT    %%'C""C5)A!//4 '$$&' ' 's   AA!r  )r  r  r  r   r  r/   r  )r!   payloadr  rl  r  s       @r   (test_subthreads_can_handle_pending_callsz9TestPendingCalls.test_subthreads_can_handle_pending_callsk  sm    E(	'
 K0++QC0 		 	g.	 	s   A--A6c                 p   t        j                         }| j                  t        j                         j                  |       t               t               t        j                         fd}fdfd}fdfd}g }t        d      D ]2  }| j                  d| ||      }|j                  |        ||       4 j                          fd	}d
fd}	t        d      D 
cg c]  }
t        j                  |	       }}
t        j                  |      5  	 |D cg c]  }|j                   }}t        d      D 
cg c]  }
t        j                  ||f       }}
t        j                  |      5  	 	 d d d         |        d	 d d d        |D cg c]  }|j                   }}| j!                  ||       |D ]  }| j#                  d|j$                         5  | j'                  |j(                  |       | j'                  |j(                  |j                         | j!                  |j(                  |       d d d         y c c}
w c c}w c c}
w # t        $ r d w xY w# 1 sw Y   xY w# t        $ r d w xY w# 1 sw Y   xY wc c}w # 1 sw Y   xY w)Nc                 J    j                  |        j                  d       y )NTr  )r  _active_queues    r   	queue_putzQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_put  s    MM$NN4 r   c                  d    	 j                         } | S # t        $ r t        j                  w xY wrG   )popleft
IndexErrorqueueEmpty)r  r   s    r   	queue_getzQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_get  s6    "~~' K  "kk!"s    /c                       j                           s	 j                          y y # t        $ r j                         rJ Y y w xY wrG   )popreleaseRuntimeErrorlocked)r  
_done_locks   r   queue_task_donezWTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_task_done  sK    KKM3&&(  $ 3)0022223s   ' AAc                  
      S rG   r   )r   s   r   queue_emptyzSTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_empty  s    :r   c                  F     j                           j                          y rG   )acquirer
  )r  s   r   
queue_joinzRTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_join  s      r   re   zrequest )r  r  r  c                 r    	 ry 	         }|j                  |        # t         j                  $ r Y y w xY wrG   )r  r  r  )r  r  doner  s     r   	add_taskszQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.add_tasks  sE    $;D ((5 
 {{ s     66Fc                              s  ry t        j                  d               s  st        j                  d        sy y r  )r  r  )r  r  s   r   	run_taskszQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.run_tasks  s7    !m

4  "m
 

4  r   r   r  r  Tztask )r  r  r/   main_threadidentr   r  r   r  r  r  r  r   r  BaseExceptionr  assertNotInr  r)   assertNotEqualr  )r!   main_tidr  r  r  tasksrn   r  r  r  _worker_threadsrl  r  r  runner_tidsr  r  r   r  r  r  s                   @@@@@@r   -test_many_subthreads_can_handle_pending_callsz>TestPendingCalls.test_many_subthreads_can_handle_pending_calls{  s   &&(..066A '^^%
	!		3		! r 	A##qcN+ $ D
 LLdO	 		6 	! $)8- $**)< - -++N; 	0>?1qww??$)!H.  %++9K>R . .%33G<  	& .33q||33;/ 	BDdggY/0 B##D$6$6A##D$6$6H  !3!3[AB B	B1-
 @.
 ) #  ! !	 	& 4B Bsy   9I -J/J3I%JI*4JI?J,J'6AJ,%
J/I<<I??J	JJJJ$,J5	c                 	    d}dt        j                         t        j                  d        fd} j                  d      5   |       \   |       \  t	        j                         dz   fd}t        j                  |      }t        j                  |g      5  t        j                  d	       t        j                        }t        j                  d
       d d d         j                  t                     d d d         j                  d      5   |       \   |       \  t	        j                         dz   fd}t        j                  |      }t        j                  |g      5  t        j                  d	       t        j                        }t        j                  d
       d d d         j                  t                     d d d         j                  d      5   |       \   |       \   |       \  }t	        j                         dz   fd}ddt        j                  ffd	}t        j                  |      }	t        j                  |      }
t        j                  |	|
g      5  s	 st        j                  d
       s:t	        j                   d       t	        j                         kD  rt#        d      s:t        j                  |d	      }d d d        t        j%                  d      } j                  |t                     d d d         j                  d      5   |       \   |       \   |       \  }t	        j                         dz   fd}ddt        j                  ffd	}fd}t        j                  |      }	t        j                  |      }
t        j                  |      }t        j                  |	|
|g      5  	 d d d        t        j                  |d	      }t        j%                  |d      } j                  |t                     d d d        y # 1 sw Y   xY w# 1 sw Y   zx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   rxY w# 1 sw Y   xY w# 1 sw Y   y xY w)N   r   zif True:
            import json
            import os
            import threading
            import time
            import _testinternalcapi
            from test.support import threading_helper
            c                       t        j                         \   j                   fd       j                  fd        fS )Nc                  .    t        j                         S rG   r  close)rs   r   r  zTTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe.<locals>.<lambda>      BHHQK r   c                  .    t        j                         S rG   r(  )ws   r   r  zTTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe.<locals>.<lambda>  r+  r   )r  pipe
addCleanup)r*  r-  r!   s   @@r   create_pipezBTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe  s5    779DAqOO/0OO/0a4Kr   z"add in main, run in subinterpreterr^  c            
      F    t        j                   d d d d       y )Na<  if True:
                    # Wait until this interp has handled the pending call.
                    waiting = False
                    done = False
                    def wait(os_read=os.read):
                        global done, waiting
                        waiting = True
                        os_read(a
  , 1)
                        done = True
                    t = threading.Thread(target=wait)
                    with threading_helper.start_threads([t]):
                        while not waiting:
                            pass
                        os.write(, b'\0')
                        # Loop to trigger the eval breaker.
                        while not done:
                            time.sleep(0.01)
                            if time.time() > zT:
                                raise Exception('timed out!')
                    r   
run_stringinterpidr_donetimeoutw_readys   r   do_workz>TestPendingCalls.test_isolated_subinterpreter.<locals>.do_work  sA    (( 8! "( )" #* +. /6Y 7#4 r   r  rP   r   z-add in main, run in subinterpreter sub-threadc            
      F    t        j                   d d d d       y )Nzif True:
                    waiting = False
                    done = False
                    def subthread():
                        while not waiting:
                            pass
                        os.write(r2  aO  :
                                raise Exception('timed out!')
                    t = threading.Thread(target=subthread)
                    with threading_helper.start_threads([t]):
                        # Wait until this interp has handled the pending call.
                        waiting = True
                        os.read(z=, 1)
                        done = True
                    r3  r5  s   r   r:  z>TestPendingCalls.test_isolated_subinterpreter.<locals>.do_work  sA    (( 8" #* +. /6Y 7! "( )!4 r   z"add in subinterpreter, run in mainc            
      r    t        j                  d       t        j                   d d d d       y NrP   zif True:
                    # Add the pending call and wait for it to finish.
                    actual = _testinternalcapi.pending_identify(zX)
                    # Signal the subinterpreter to stop.
                    os.write(z&, b'\0')
                    os.write(z4, actual.to_bytes(1, 'little'))
                    r  readr   r4  r6  main_interpidr_readyw_dataw_dones   r   add_jobz>TestPendingCalls.test_isolated_subinterpreter.<locals>.add_jobA  K    #(( 8AAN P$X &$X &4 r   Fc                      d | d       dy NTrP   r   os_readr  r7  waitings    r   waitz;TestPendingCalls.test_isolated_subinterpreter.<locals>.waitM      "r   r  
timed out!littlez(add in subinterpreter, run in sub-threadc            
      r    t        j                  d       t        j                   d d d d       y r=  r>  r@  s   r   rE  z>TestPendingCalls.test_isolated_subinterpreter.<locals>.add_jobh  rF  r   c                      d | d       dy rH  r   rI  s    r   rL  z;TestPendingCalls.test_isolated_subinterpreter.<locals>.waitt  rM  r   c                      s	 st        j                  d        s;t        j                  d       t        j                         kD  rt	        d       s:y y )Nr   r  rN  )r  writer  r  	Exception)r  r8  r9  rK  s   r   	subthreadz@TestPendingCalls.test_isolated_subinterpreter.<locals>.subthready  sI    ! "%(JJt$yy{W,'55 r   )r   creater4  r  r  r  r  r   r  r  r?  r  pending_identifyrS  r/   r  r  rT  
from_bytesstartjoin)r!   maxtextr0  r:  rl  actualr_datarE  rL  t1t2textrU  t3r  r6  rA  r7  rB  r8  rC  rD  r9  rK  s   `             @@@@@@@@@@r   test_isolated_subinterpreterz-TestPendingCalls.test_isolated_subinterpreter  s-     '')   0 		 \\>? "	4*}GW'MNFFiikB&G*   0A!//4 (#*;;HE'( VS]3E"	4H \\IJ !	4*}GW'MNFFiikB&G(   0A!//4 (#*;;HE'( VS]3C!	4F \\>? %	9*}GW'MNFF'MNFFiikB&G  GDWW 
 !!1B!!.B!//R9 	*! "%(JJt$yy{W,'55  wwvq)	* ^^D(3FVS%78K%	9N \\DE (	9*}GW'MNFF'MNFFiikB&G  GDWW 
6 !!1B!!.B!!3B!//R= 7761%D^^D(3FVS%78Q(	9V 	}( (7"	4 "	4|( (5!	4 !	4x	* 	*3%	9 %	9T G(	9V 	s   A R0AR 2#R.A R'AR#R'BS)R40AR4R49S*B<S&S(AS R
	RRR$	R''R14R>	9SSS	SS#rG   )r%   r&   r'   r  r  r   requires_working_threadingr  r  r  r  r  SimpleNamespacer  r  r#  r   rb  r   r   r   r  r    s    $& 1002: 3:(
$%C
.!e++ .!` 1002/ 3/ 1002\B 3\B| ^4 ^4r   r  c                   ~   e Zd Z ej                   eed      d      d        Z ej                   eed      d      d        Zd Z	 ej                   eed      d      d        Z
 ej                  edu d       ej                   eed      d      d	               Zd
 Z ej                  edu d      d        Zy)SubinterpreterTestr.  zrequires os.pipe()c                    dd l }t        j                         \  }}dj                  |      }t	        |d      5 }t        j                  |      }| j                  |d       | j                  t        j                  |      t        t        j                               | j                  t        j                  |      t        |             d d d        y # 1 sw Y   y xY w)Nr   zif 1:
            import sys, builtins, pickle
            with open({:d}, "wb") as f:
                pickle.dump(id(sys.modules), f)
                pickle.dump(id(builtins), f)
            rb)builtinsr  r.  formatopenr   run_in_subinterpr/   r  pickleloadr)   rj   modules)r!   ri  r*  r-  r?   frets          r   test_subinterpsz"SubinterpreterTest.test_subinterps  s    wwy1
 q	 	 !T] 	>a**40CS!$A3;;@A8=		> 	> 	>s   BCCc                 4   t        j                         \  }}dj                  |      }t        |d      5 }t	        j
                  |      }| j                  |d       | j                  t        j                  |      ddd       d d d        y # 1 sw Y   y xY w)Naa  if 1:
            import pickle
            with open({:d}, "wb") as f:

                @(lambda x:x)  # Py 3.9
                def noop(x): return x

                a = (b := f'1{{2}}3') + noop('x')  # Py 3.8 (:=) / 3.6 (f'')

                async def foo(arg): return await arg  # Py 3.5

                pickle.dump(dict(a=a, b=b), f)
            rh  r   123xr  )r-  r   )	r  r.  rj  rk  r   rl  r/   rm  rn  )r!   r*  r-  r?   rp  rq  s         r   (test_subinterps_recent_language_featuresz;SubinterpreterTest.test_subinterps_recent_language_features  s    wwy1 q	 	 !T] 	Ha**40CS!$V[[^6-FG	H 	H 	Hs   ABBc                    d}t        j                         }|d   dk7  sJ | j                  t        j                  |      dd       t        j                         }| j                  ||d       | j                  ||d       y )Na  if 1:
        import sys, _testinternalcapi

        # Any config value would do, this happens to be the one being
        # double checked at the time this test was written.
        config = _testinternalcapi.get_config()
        config['int_max_str_digits'] = 55555
        config['parse_argv'] = 0
        _testinternalcapi.set_config(config)
        sub_value = _testinternalcapi.get_config()['int_max_str_digits']
        assert sub_value == 55555, sub_value
        int_max_str_digitsi  r   z%subinterp code failure, check stderr.z7Expected get_config() to return a new dict on each callzJCAUTION: Tests executed after this may be running under an altered config.)r  
get_configr/   r   rl  assertIsNot)r!   r?   before_configafter_configs       r   (test_py_config_isoloated_per_interpreterz;SubinterpreterTest.test_py_config_isoloated_per_interpreter  s    
 *44612e;;;11$7@	B(335|I	K 	<	=r   c                 
   ddl }d}d}d}d}d}d}||z  |z  |z  |z  |z  }g d	}	|	D 
cg c]  }
d
|
 	 }}
d|d<   d|d<   d|d<   |df|df||z  dfdj                         D ]  \  }}t        t        ||            }|\  }}||d}| j	                  |      5  t        j                         \  }}t        j                  d| d      }t        j                  |      5 }t        j                  |fi |}| j                  |d       |j                         }ddd        |j                        }| j                  ||       ddd        dD ]z  }t        t        ||            }| j	                  |      5  t        j                  d      }| j                  t               5  t        j                  |fi | ddd       ddd       | yc c}
w # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   2xY w# 1 sw Y   xY w)z
        The config with which an interpreter is created corresponds
        1-to-1 with the new interpreter's settings.  This test verifies
        that they match.
        r   Nr  r               )obmallocforkr  r  daemon_threads
extensionsown_gilallow_use_main_obmalloccheck_multi_interp_extensionsr  r   TF))TTTTTTT)TFFFFFF)FFFTFTFfeature_flagsr  z
                    import _testinternalcapi, json, os
                    settings = _testinternalcapi.get_interp_settings()
                    with os.fdopen(zX, "w") as stdin:
                        json.dump(settings, stdin)
                    ))FFFFFFFz
                    import _testinternalcapi
                    _testinternalcapi.get_interp_settings()
                    raise NotImplementedError('unreachable')
                    )jsonitemsr"  zipr  r  r.  r:   r;   fdopenr   run_in_subinterp_with_configr/   r?  loadsr2   r  )r!   r  OBMALLOC
EXTENSIONSTHREADSDAEMON_THREADSFORKEXEC	ALL_FLAGSfeaturesr  kwlistconfigr  kwargs	exp_flagsexp_gilr*  r-  scriptstdoutrq  rC   settingss                           r   test_configured_settingsz+SubinterpreterTest.test_configured_settings  s`    	
_t+g5F!"	
 )111F1#,11'q	4r
r

 D!5!:%u-!
 %'	5FH #ff-.F!)Iw!*"H f% 5wwy1! .$ %&3 '*  YYq\ (V!>>vPPC$$S!, ++-C( &4::c?  845 5	5>
 	KF #ff-.Ff% K! . 
 &&|4 K88J6JKK K		KK 28( (5 56K KK KsN   GAG  9G,G :+G9%G-<G9GG  G*	-G62G99H	Nz%test requires _testsinglephase modulec                    	
 ddl 
d}dd}d}d}d}||z  |z  |z  |z  d	d	d	d	d	d
d		
 fd}d _         j                  d      5   |d
d       ddd        j                  d      5   |d
d       ddd        j                  d      5   |d
d       ddd        j                  d      5   |d	d       ddd        j                  d      5   |d	d       ddd        j                  d      5   |d	d       d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   txY w# 1 sw Y   ]xY w# 1 sw Y   yxY w)z
        PyInterpreterConfig.check_multi_interp_extensions can be overridden
        with PyInterpreterState.override_multi_interp_extensions_check.
        This verifies that the override works but does not modify
        the underlying setting.
        r   Nr  r   r~  r  r  r  TF)r  
allow_fork
allow_execallow_threadsallow_daemon_threadsr  c                    t        |       }| rz  n}|dd}|d|d||||  |r|dkD  n|  |  d
}t        j                         \  }}t        j                  d| d| d      }t        j
                  |      5 }	t        j                  |fi |}
j                  |
d       |	j                         }d d d         j                        }j                  ||       y # 1 sw Y   .xY w)	N)r  Fr  r   )
	requestedoverride__initialoverride_afteroverride_restoredsettings__initialsettings_aftersettings_restoredallowed__initialallowed_afterallowed_restoredzu
                from test.test_capi.check_config import run_singlephase_check
                run_singlephase_check(z, z)
                )r"  r  r.  r:   r;   r  r   r  r/   r?  r  )enabledoverrider  flagsr  r  r*  r-  r  r  rq  rC   results
BASE_FLAGSr  base_kwargsr  r!   s                r   r~  zTSubinterpreterTest.test_overridden_setting_extensions_subinterp_check.<locals>.checkn  s   .5F 07J+JE!& H &%&"*%&%-"*%-(/K8@x!|g!N(/KH 779DAq__ *''/j1# 6& F 1 $::6LVL  a(kkm$ !djjoGWh/$ $s   <9C""C+z*config: check disabled; override: disabledr   z,config: check disabled; override: use configz)config: check disabled; override: enabledrP   z)config: check enabled; override: disabledz+config: check enabled; override: use configz(config: check enabled; override: enabled)r  maxDiffr  )r!   r  r  r  r  r  r~  r  r  r  r  s   `      @@@@r   2test_overridden_setting_extensions_subinterp_checkzESubinterpreterTest.test_overridden_setting_extensions_subinterp_checkS  sw    	
_t+g5F
!%!$(
%	0 %	0N  \\FG 	%	\\HI 	%O	\\EF 	%O	 \\EF 	$O	\\GH 	$N	\\DE 	$N	 		 		 		 		 		 		 	sH   
D1
D
D(7
D4
E =
EDD%(D14D= E	Ec                     ddl }t        j                  d       | j                  t	        |j
                  d             y)z
        Exceptions saved in global module state get shared between
        individual module instances. This test checks whether or not
        a change in one interpreter's module gets reflected into the
        other ones.
        r   Nz1import binascii; binascii.Error.foobar = 'foobar'foobar)binasciir   rl  assertFalser  Error)r!   r  s     r   test_mutate_exceptionz(SubinterpreterTest.test_mutate_exception  s/     	  !TU:;r   $test requires _testmultiphase modulec                    t        j                         \  }}| j                  t         j                  |       | j                  t         j                  |       t	        j
                  d| d      }t        |       t        j                  |d      }t        j                  |      }| j                  |d       t        j                  |d      }| j                  ||       y)z
        bpo-44050: Extension module state should be shared between interpreters
        when it doesn't support sub-interpreters.
        a  
            import importlib.machinery
            import importlib.util
            import os

            fullname = '_test_module_state_shared'
            origin = importlib.util.find_spec('_testmultiphase').origin
            loader = importlib.machinery.ExtensionFileLoader(fullname, origin)
            spec = importlib.util.spec_from_loader(fullname, loader)
            module = importlib.util.module_from_spec(spec)
            attr_id = str(id(module.Error)).encode()

            os.write(z, attr_id)
            d   r   N)r  r.  r/  r)  r:   r;   r  r?  r   rl  r/   )r!   r*  r-  r  main_attr_idrq  subinterp_attr_ids          r   "test_module_state_shared_in_globalz5SubinterpreterTest.test_module_state_shared_in_global  s     wwy1!$!$ & S "  	Vwwq#&&v.a GGAsO'89r   )r%   r&   r'   r   re  r  r  rr  ru  r|  r  r   _testsinglephaser  r  _testmultiphaser  r   r   r   rf  rf    s
   XV,.BC> D> XV,.BCH DH*=D XV,.BCJK DJKX X__%-/VWXV,.BCP D XPd< X___,.TU: V:r   rf  c                   >    e Zd Zeeeee ed      ee	e
eegZd Zd Zy)BuiltinStaticTypesTestsNc                     | j                   D ]C  }| j                  |      5  t        j                  |      }| j	                  |d        d d d        E y # 1 sw Y   PxY wrG   )TYPESr  r   type_get_tp_basesry  )r!   typeobjbasess      r   test_tp_bases_is_setz,BuiltinStaticTypesTests.test_tp_bases_is_set  s]     zz 	.Gg& .!33G<  -. .	.. .   (AA	c                     | j                   D ]C  }| j                  |      5  t        j                  |      }| j	                  |d        d d d        E y # 1 sw Y   PxY wrG   )r  r  r   type_get_tp_mrory  )r!   r  r  s      r   test_tp_mro_is_setz*BuiltinStaticTypesTests.test_tp_mro_is_set  s]     zz 	,Gg& ,//8  d+, ,	,, ,r  )r%   r&   r'   rq   rg  r  r   r"  boolr  rT  Warningry  r  r  r  r   r   r   r  r    s:     	T
E.,r   r  c                   J    e Zd ZdZed        Zej                  d        Zd Z	y)TestStaticTypesFc                 T    | j                   rt        j                  d      d| _         y )Nz%these tests do not support re-runningT)_has_runr   SkipTest)rP  s    r   
setUpClasszTestStaticTypes.setUpClass  s$     <<##$KLLr   c              '   8   K   t        j                  | }| y wrG   )r   get_basic_static_type)r!   r   rP  s      r   basic_static_typez!TestStaticTypes.basic_static_type  s     --t4	s   c                 F   | j                         5 }| j                  |j                  t               | j	                  |j
                  t        f       | j                  t        |      t        t                     d d d        | j                  t              5 }| j                  |j                  t               | j	                  |j
                  t        f       | j                  t        |      t        t                     d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wrG   )r  rO  __base__rq   r/   	__bases__rg  )r!   rP  s     r   %test_pytype_ready_always_sets_tp_typez5TestStaticTypes.test_pytype_ready_always_sets_tp_type  s     ##% 	4MM#,,/S]]VI6MM$s)T&\2	4 ##F+ 	4sMM#,,/S]]VI6MM$s)T&\2	4 	4	4 	4	4 	4s   A*DA*DDD N)
r%   r&   r'   r  classmethodr  
contextlibcontextmanagerr  r  r   r   r   r  r    s8    H   4r   r  c                       e Zd Zej                   ej
                         d               Zej                   ej
                         d               Zej                   ej
                         d               Zd Z	y)TestThreadStatec                       fd} |        t        j                  |      }|j                          |j                          y )Nc                      g fd} t         j                  |        | x}}t        j                  d       j	                  j                  t        j                               dd       y )Nc                  L     j                  t        j                                y rG   )r  r  r  )identss   r   r  zCTestThreadState.test_thread_state.<locals>.target.<locals>.callback"  s    i1134r   rP   r   z/Couldn't find main thread correctly in the list)r   _test_thread_stater  r  r/   r  r  r  )r  r-  r   r  r!   s      @r   r  z1TestThreadState.test_thread_state.<locals>.target  sZ    F5 ((2AJJqMV\\)*=*=*?@!NPr   r  )r  r  rY  rZ  )r!   r  rl  s   `  r   test_thread_statez!TestThreadState.test_thread_state  s2    	P 	F+			r   c                 z     G d d      t        j                         fd}t        j                  |       y )Nc                       e Zd Zd Zy)8TestThreadState.test_thread_gilstate_in_clear.<locals>.Cc                 ,    t         j                          y rG   )r   gilstate_ensure_releaser    s    r   r   z@TestThreadState.test_thread_gilstate_in_clear.<locals>.C.__del__6  s    113r   N)r%   r&   r'   r   r   r   r   r   r  5  s    4r   r   c                               _         y rG   rZ  )r   	local_vars   r   r  z?TestThreadState.test_thread_gilstate_in_clear.<locals>.callback<  s    #IKr   )r  localr   r  )r!   r  r   r  s     @@r   test_thread_gilstate_in_clearz-TestThreadState.test_thread_gilstate_in_clear1  s0    	4 	4
 OO%		 	$$X.r   c                     t        j                  d      }t        ddd|      }| j                  d|j                         y )Nz
            import _testcapi

            def callback():
                print('callback called')

            _testcapi._test_thread_state(callback)
            z-Xtracemallocr9   s   callback called)r:   r;   r   r   rC   )r!   r?   rq  s      r    test_gilstate_ensure_no_deadlockz0TestThreadState.test_gilstate_ensure_no_deadlockA  s<         t]D$?(#''2r   c                 ,    t         j                          y rG   )r   test_current_tstate_matchesr    s    r   test_gilstate_matches_currentz-TestThreadState.test_gilstate_matches_currentP  s    --/r   N)
r%   r&   r'   r   reap_threadsrc  r  r  r  r  r   r   r   r  r    s    ""0002 3 #( ""0002/ 3 #/ ""00023 3 #30r   r  c                       e Zd Z e       j	                  d  ee      D                ej                  e	      d        Z
d Zy)Test_testcapic              #      K   | ]8  }|j                  d       r%|j                  d      s|t        t        |      f : yw)test__codeN)r>   endswithgetattrr   .0r  s     r   	<genexpr>zTest_testcapi.<genexpr>U  s=      Pw/g8N 79d34 Ps   >A r  c                 ,    t         j                          y rG   )r   test_widecharr    s    r   r  zTest_testcapi.test_widecharZ  s    !r   c                 `    | j                  t        j                  t        j                         y rG   )r/   r   
Py_Versionrj   
hexversionr    s    r   test_version_api_dataz#Test_testcapi.test_version_api_data^  s    --s~~>r   N)r%   r&   r'   localsupdatedirr   r	   rh  ry  r  r  r   r   r   r  r  T  sL    
HOO P #IP P
 %_$$.@A" B"?r   r  c                   R    e Zd Z e       j	                  d  ee      D               y)Test_testinternalcapic              #   b   K   | ]'  }|j                  d       r|t        t        |      f ) yw)r  N)r>   r  r  r  s     r   r
  zTest_testinternalcapi.<genexpr>c  s1      1w/ 7#4d;< 1s   -/N)r%   r&   r'   r  r  r  r  r   r   r   r  r  b  s#    
HOO 1 #$5 61 1r   r  r  c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	Test_ModuleStateAccessz%Test access to module start (PEP 573)c                 H   d}t         j                  j                  d      j                  }t         j                  j                  ||      }t         j                  j                  ||      }t         j                  j                  |      }|j                  |       || _	        y )N!_testmultiphase_meth_state_accessr  )
	importlibutil	find_specorigin	machineryExtensionFileLoaderspec_from_loadermodule_from_specexec_moduler*  )r!   fullnamer  loaderspecr*  s         r   setUpzTest_ModuleStateAccess.setUpp  sy    6))*;<CC$$886J~~..x@0066"r   c                      G d d| j                   j                        } |       }| j                  |j                         | j                          y)z#PyType_GetModule for defining_classc                       e Zd Zy)QTest_ModuleStateAccess.test_subclass_get_module.<locals>.StateAccessType_SubclassNr2  r   r   r   StateAccessType_Subclassr*  {  r3  r   r+  Nr*  StateAccessTyperO  get_defining_moduler!   r+  r  s      r   test_subclass_get_modulez/Test_ModuleStateAccess.test_subclass_get_moduley  s=    	t{{'B'B 	 ,-h224dkkBr   c                      G d d| j                   j                        } |       }| j                  |j                         | j                          y )Nc                        e Zd Z fdZ xZS )\Test_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclassc                      t         |          S rG   )r   r.  r   s    r   r.  zpTest_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclass.get_defining_module  s    w244r   )r%   r&   r'   r.  r   r   s   @r   r+  r3    s    5 5r   r+  r,  r/  s      r   #test_subclass_get_module_with_superz:Test_ModuleStateAccess.test_subclass_get_module_with_super  s=    	5t{{'B'B 	5 ,-h224dkkBr   c                    | j                   j                         }| j                   j                         }|j                  |j                  d}|j	                         D ]  \  }}| j                  |      5  | j                  |j                         |j                                | j                  |j                         d        |        | j                  |j                         |j                                | j                  |j                         d        |d       | j                  |j                         |j                                | j                  |j                         d        |dd       | j                  |j                         |j                                | j                  |j                         d       | j                  t              5   |d	       d
d
d
       | j                  t              5   |ddd       d
d
d
       d
d
d
        y
# 1 sw Y   =xY w# 1 sw Y   !xY w# 1 sw Y   xY w)zChecks methods defined with and without argument clinic

        This tests a no-arg method (get_count) and a method with
        both a positional and keyword argument.
        )clinicnoclinicr   rP   r   r   r  T)twice)thriceNrX   )
r*  r-  increment_count_clinicincrement_count_noclinicr  r  r/   	get_countr2   rs   )r!   r-  r   methodsr  increment_counts         r   test_state_accessz(Test_ModuleStateAccess.test_state_access  s    KK'')KK'') ..22

 &-]]_ 	-!D/d# -  >  2!  >  2"  >  2$/  >  2&&y1 .#1-. &&y1 -#Aq!,-'- -	-". .- -'- -s=   6E'H;
H#'H;H/H;#H,(H;/H84H;;I	c                     | j                   j                         }| j                  t              5  |j	                          d d d        y # 1 sw Y   y xY wrG   )r*  r-  r2   rs   getmodulebydef_bad_def)r!   r  s     r   test_get_module_bad_defz.Test_ModuleStateAccess.test_get_module_bad_def  sE     ;;..0y) 	.++-	. 	. 	.s   A

Ac                      G d dt         | j                  j                        }| j                   |       j	                         | j                         y )Nc                       e Zd Zy)FTest_ModuleStateAccess.test_get_module_static_in_mro.<locals>.SubclassNr2  r   r   r   SubclassrF    r3  r   rG  )r  r*  r-  rO  r.  )r!   rG  s     r   test_get_module_static_in_mroz4Test_ModuleStateAccess.test_get_module_static_in_mro  s7    	}dkk&A&A 	hj446Dr   N)
r%   r&   r'   r1   r'  r0  r5  r@  rC  rH  r   r   r   r  r  h  s'    /CC$-L.Er   r  c                   .    e Zd Zed        Zd Zd Zd Zy)TestInternalFrameApic                  *    t        j                         S rG   )rj   	_getframer   r   r   funczTestInternalFrameApi.func  s    }}r   c                     | j                         }t        j                  |      }| j                  || j                   j                         y rG   )rM  r  iframe_getcoderO  r  )r!   framer?   s      r   	test_codezTestInternalFrameApi.test_code  s5    		 //6dDII../r   c                     | j                         }t        j                  |      }| j                  |d       | j	                  |t        | j                   j                  j                               y )Nr   )rM  r  iframe_getlastir   rt  r  r  co_code)r!   rP  lastis      r   
test_lastizTestInternalFrameApi.test_lasti  sP    		!11%85!$s499#5#5#=#=>?r   c                     | j                         }t        j                  |      }| j                   j                  j                  }| j                  ||dz          y )NrX   )rM  r  iframe_getliner  co_firstlinenor/   )r!   rP  line	firstlines       r   	test_linezTestInternalFrameApi.test_line  sF    		 //6II&&55	y1}-r   N)r%   r&   r'   staticmethodrM  rQ  rV  r\  r   r   r   rJ  rJ    s$     0
@.r   rJ  r  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	Test_Pep523APIc                    g }t         }|t         z   }	 t        |      D ]#  }||k(  rt        j                  |        |        % 	 t        j                          |t         z  }| j                  t        |      t        |             t        ||d      D ]  \  }}	| j                  ||	        y # t        j                          w xY w)NT)strict)"SUFFICIENT_TO_DEOPT_AND_SPECIALIZEr   r  set_eval_frame_recordset_eval_frame_defaultr/   r  r  )
r!   rM  r  actual_callsrY  r  rn   expected_callsr  r\  s
             r   do_testzTest_Pep523API.do_test  s    2::	75\ :%;;LI
 446!CC^,c,.?@ #NL N 	/HfXv.	/ 446s   1B/ /Cc                 P     G d d      fd}ddg}| j                  ||       y )Nc                       e Zd Zd Zy)4Test_Pep523API.test_inlined_binary_subscr.<locals>.Cc                      y rG   r   )r!   others     r   ro   z@Test_Pep523API.test_inlined_binary_subscr.<locals>.C.__getitem__  rp   r   N)r%   r&   r'   ro   r   r   r   r   rj    s    r   r   c                               d    y Nr   r   )r   s   r   rM  z7Test_Pep523API.test_inlined_binary_subscr.<locals>.func  s    CGr   rM  ro   rg  )r!   rM  r  r   s      @r   test_inlined_binary_subscrz)Test_Pep523API.test_inlined_binary_subscr  s*    	 		'T5!r   c                 D    ddfd}g d}| j                  ||       y )Nc                      y rG   r   r  s    r   innerz/Test_Pep523API.test_inlined_call.<locals>.inner  r  r   c                  $                d       y rn  r   rs  s   r   rM  z.Test_Pep523API.test_inlined_call.<locals>.func  s    G"Ir   )rM  rs  rs  )r   ro  r!   rM  r  rs  s      @r   test_inlined_callz Test_Pep523API.test_inlined_call  s"    		 +T5!r   c                 B    d fd}ddg}| j                  ||       y )Nc                      y rG   r   r  s    r   rs  z;Test_Pep523API.test_inlined_call_function_ex.<locals>.inner  r  r   c                        dg  y rn  r   ru  s   r   rM  z:Test_Pep523API.test_inlined_call_function_ex.<locals>.func	  s    B4Lr   rM  rs  ro  rv  s      @r   test_inlined_call_function_exz,Test_Pep523API.test_inlined_call_function_ex  s%    		!T5!r   c                 B    d fd}g d}| j                  ||       y )Nc               3      K   d y wrn  r   r   r   r   r  z1Test_Pep523API.test_inlined_for_iter.<locals>.gen	       Hr  c                              D ]  }  y rG   r   )r   r  s    r   rM  z2Test_Pep523API.test_inlined_for_iter.<locals>.func		  s    U r   )rM  r  r  r  ro  )r!   rM  r  r  s      @r   test_inlined_for_iterz$Test_Pep523API.test_inlined_for_iter	  s"    		 .T5!r   c                 h     G d d       G d d      fd}g d}| j                  ||       y )Nc                       e Zd Zed        Zy)0Test_Pep523API.test_inlined_load_attr.<locals>.Cc                      yrn  r   r    s    r   r-  z2Test_Pep523API.test_inlined_load_attr.<locals>.C.a	  s    r   N)r%   r&   r'   propertyr-  r   r   r   r   r  	  s     r   r   c                       e Zd Zd Zy)0Test_Pep523API.test_inlined_load_attr.<locals>.Dc                      yrn  r   )r!   r  s     r   __getattribute__zATest_Pep523API.test_inlined_load_attr.<locals>.D.__getattribute__	  s    r   N)r%   r&   r'   r  r   r   r   Dr  	  s    r   r  c                  J             j                            j                    y rG   r  )r   r  s   r   rM  z3Test_Pep523API.test_inlined_load_attr.<locals>.func	  s    CEECEEr   )rM  r-  r  ro  )r!   rM  r  r   r  s      @@r   test_inlined_load_attrz%Test_Pep523API.test_inlined_load_attr	  s1    	 		 		 2T5!r   c                 N    d fdfd}g d}| j                  ||       y )Nc               3      K   d y wrn  r   r   r   r   rs  z/Test_Pep523API.test_inlined_send.<locals>.inner	  r~  r  c               3   0   K            E d {    y 7 wrG   r   ru  s   r   outerz/Test_Pep523API.test_inlined_send.<locals>.outer 	  s     ws   c                  &    t                        y rG   )r   )r  s   r   rM  z.Test_Pep523API.test_inlined_send.<locals>.func"	  s    Mr   )rM  r  r  rs  rs  r  rs  ro  )r!   rM  r  rs  r  s      @@r   test_inlined_sendz Test_Pep523API.test_inlined_send	  s%    			NT5!r   N)
r%   r&   r'   rg  rp  rw  r{  r  r  r  r   r   r   r_  r_    s%    / """"""r   r_  __main__)Cr  collectionsr   r   r  importlib.machineryr  importlib.utilr  r  rm  r  r  
subprocessrj   r:   r  r  r  r   r  r;  rr  r-   r   test.supportr   r   r   r	   r
   test.support.script_helperr   r   r   rt   ImportErrorr  r  _xxsubinterpretersr   ModuleNotFoundErrorr  r   r  r   r   r   r"   r$   TestCaser+   rj  r  rf  r  r  r  r  r  r   r  rJ  rb  r_  r%   mainr   r   r   <module>r     sQ    *     	     
          - & ) ( - d d.
 (M''4	  <=
: :z#x   z#z W.8,, W. W.tV4x(( V4rV:** V:r,h// ,B 4h''  4F80h'' 80v?H%% ?1H-- 1 D(*PQTEX.. TE RTEn.8,, .0 &) "K"X&& K"\ zHMMO OH    O    MsH   G5 	H H H 5H ?H HHHHH*)H*