
    9i                       S r SSKJrJrJrJr  SSKJr  SSKJ	r	J
r
JrJrJrJr  SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKr\" \S5      (       d  SSKrSSKrSSKrSSKrSSKr SSK r SSK#r#SSK$r%SSK&r&SSK'r' \RP                  (       a	  SSK)r)SSK*r*O	SSK+r)SSK*r*  SSK,r- SSK.r. SSK/r/ SSK0r0 SSK1r1/ SQr2 " S	 S
\35      r4 " S S\45      r5 " S S\Rl                  5      r7\Rp                  SS j5       r9SS jr:S r;S r<S r=SS jr>S r?Sr@SrASqBSqCSrDSrESqFS rGS rHS rI\R,                  R                  S5      (       a  SS jrKS rLS rMS rNO$\R                  rL\R                  rM\R                  rNS  rOS! rPS" rQ\R,                  R                  S5      (       a  SSKRrRSSKSrRS# rTOS$ rTS% rUSS& jrVS' rWS( rXS) rYS* rZS+r[S,r\\R                  \R                  4S- jr_\[4S. jr`S/ ra\a" 5       rbS0rcS1rd\R                  " \.S25      rf\R                  " \0S35      rg\R                  " \1S45      rh\R,                  R                  S55      ri\R                  S5:X  a  S6rkOS7rkS8R                  \k\R                  " 5       5      rk\R                  " 5       ro\Rp                  SS9 j5       rp\" \S:5      (       a  \Rp                  S; 5       rq\rS4S< jrsS= rtS> ruS? rvS@ rwSA rx " SB SC\y5      rzSSD jr{\Rp                  SE 5       r| " SF SG\y5      r}\RP                  (       a  SSK~r\GR                   GR                  rOSSKr\GR                  r " SH SI\5      r " SJ SK\y5      r " SL SM\y5      r\" \\GR                  SN9r\" \GR                  \GR                  SN9r\" \\GR                  SN9r\Rp                  SSO j5       r\Rp                  SP 5       rSQ rSR rSS rST r\Rp                  SU 5       rSV rSWrSXr\" \SY5      (       a  SZ\-   rS[r\S\-   rS] rS^ rS_rS`rSa rSb rSc rSdrSe\-  rSf\-  rSg\-  r\GRJ                  rSh r " Si Sj\y5      rSSk jrSl r " Sm Sn\y5      rSo rSp rSq rSSr jrSs rSt rSu rSv rSw rSx rSy rSSz jrS{ rS| rS} rS~ rS rS r\Rp                  S 5       r\Rp                  S 5       rS rS r " S S\%GR                  GR                  5      r " S S\y5      rSqS rS rSqS rS r\R,                  R                  S5      (       a  \Rp                  S 5       rO\Rp                  S 5       rS rg! \! a
    SSK"J r    GNf = f! \! a    Sr)Sr* GNf = f! \! a    Sr- GNf = f! \! a    Sr. GNf = f! \! a    Sr/ GNf = f! \! a    Sr0 GNf = f! \! a    Sr1 GN f = f)zwSupporting definitions for the Python regression tests.

Backported for python-future from Python 3.3 test/support.py.
    )absolute_importdivisionprint_functionunicode_literals)utils)strrangeopenintmaplistNskip)	sysconfig)JError
TestFailedResourceDeniedimport_moduleverboseuse_resources
max_memuserecord_original_stdoutget_original_stdoutunloadunlinkrmtreeforgetis_resource_enabledrequiresrequires_freebsd_versionrequires_linux_versionrequires_mac_verfind_unused_port	bind_portIPV6_ENABLED	is_jythonTESTFNHOSTSAVEDCWDtemp_cwdfindfilecreate_empty_filesortdictcheck_syntax_erroropen_urlresourcecheck_warningsCleanImportEnvironmentVarGuardTransientResourcecaptured_stdoutcaptured_stdincaptured_stderrtime_outsocket_peer_resetioerror_peer_resetrun_with_locale
temp_umasktransient_internetset_memlimit
bigmemtestbigaddrspacetestBasicTestRunnerrun_unittestrun_doctestthreading_setupthreading_cleanupreap_childrencpython_onlycheck_impl_detailget_attribute	swap_item	swap_attrrequires_IEEE_754TestHandlerMatchercan_symlinkskip_unless_symlinkskip_unless_xattrimport_fresh_modulerequires_zlibPIPE_MAX_SIZEfailfastanticipate_failurerun_with_tzrequires_gziprequires_bz2requires_lzmasuppress_crash_popupc                       \ rS rSrSrSrg)r   a   z*Base class for regression test exceptions. N__name__
__module____qualname____firstlineno____doc____static_attributes__r\       ]/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/future/backports/test/support.pyr   r   a   s    4rd   r   c                       \ rS rSrSrSrg)r   d   zTest failed.r\   Nr]   r\   rd   re   r   r   d   s    rd   r   c                       \ rS rSrSrSrg)r   g   zTest skipped because it requested a disallowed resource.

This is raised when a test calls requires() for a resource that
has not be enabled.  It is used to distinguish between expected
and unexpected skips.
r\   Nr]   r\   rd   re   r   r   g   s    rd   r   c              #      #    U (       a?  [         R                  " 5          [         R                  " SS[        5        Sv   SSS5        gSv   g! , (       d  f       g= f7f)zContext manager to suppress package and module deprecation
warnings when importing them.

If ignore is False, this context manager has no effect.ignorez.+ (module|package)N)warningscatch_warningsfilterwarningsDeprecationWarning)rk   s    re   _ignore_deprecated_importsrp   o   sD      $$&##H.C$68 '&
 	 '&s   A!A A
AAFc                     [        U5          [        R                  " U 5      sSSS5        $ ! [         a$  n[        R
                  " [        U5      5      eSnAff = f! , (       d  f       g= f)zImport and return the module to be tested, raising SkipTest if
it is not available.

If deprecated is True, any module or package deprecation messages
will be suppressed.N)rp   	importlibr   ImportErrorunittestSkipTestr   )name
deprecatedmsgs      re   r   r   ~   sW     
$J	/	.**40 
0	/  	.##CH--	. 
0	/s%   A-
AAAA
A,c                 0   U [         R                  ;  a  [        U 5        [         R                  U 	 [        [         R                  5       HI  nX :X  d  UR	                  U S-   5      (       d  M#  [         R                  U   X'   [         R                  U	 MK     g)zqHelper function to save and remove a module from sys.modules

Raise ImportError if the module can't be imported.
.N)sysmodules
__import__r   
startswith)rv   orig_modulesmodnames      re   _save_and_remove_moduler      sm     3;;4KK$?g00<<$'KK$8L!G$ %rd   c                     Sn [         R                  U    X'   S[         R                  U '   U$ ! [         a    Sn N#f = f)zzHelper function to save and block a module in sys.modules

Return True if the module was in sys.modules, False otherwise.
TFNr{   r|   KeyError)rv   r   saveds      re   _save_and_block_moduler      sJ    
 E [[. CKKL  s   . ==c                 6    U (       a  [         R                  $ S $ )zDecorator to mark a test that is known to be broken in some cases

Any use of this decorator should have a comment identifying the
associated tracker issue.
c                     U $ Nr\   )fs    re   <lambda>$anticipate_failure.<locals>.<lambda>   s    Qrd   )rt   expectedFailure)	conditions    re   rT   rT      s     '''rd   c                 d   [        U5         0 n/ n[        X5         U H  n[        Xd5        M     U H&  n[        Xt5      (       a  M  UR                  U5        M(     [        R
                  " U 5      nUR                  5        H  u  pU
[        R                  U	'   M     U H  n[        R                  U	 M     UsSSS5        $ ! [         a    Sn N_f = f! UR                  5        H  u  pU
[        R                  U	'   M     U H  n[        R                  U	 M     f = f! , (       d  f       g= f)a
  Import and return a module, deliberately bypassing sys.modules.
This function imports and returns a fresh copy of the named Python module
by removing the named module from sys.modules before doing the import.
Note that unlike reload, the original module is not affected by
this operation.

*fresh* is an iterable of additional module names that are also removed
from the sys.modules cache before doing the import.

*blocked* is an iterable of module names that are replaced with None
in the module cache during the import to ensure that attempts to import
them raise ImportError.

The named module and any modules named in the *fresh* and *blocked*
parameters are saved before starting the import and then reinserted into
sys.modules when the fresh import is complete.

Module and package deprecation messages are suppressed during this import
if *deprecated* is True.

This function will raise ImportError if the named module cannot be
imported.

If deprecated is True, any module or package deprecation messages
will be suppressed.
N)
rp   r   r   appendrr   r   rs   itemsr{   r|   )rv   freshblockedrw   r   names_to_remove
fresh_nameblocked_namefresh_module	orig_namemodulename_to_removes               re   rP   rP      s   : 
$J	/ 3	0#
'
A $ '-lII#**<8 !( %2248L &2%7%7%9!	)/I& &:"1KK/ #2) 
0	/  	 L	  &2%7%7%9!	)/I& &:"1KK/ #2% 
0	/sB   D!'C+C3AD!CCCCADD!!
D/c                 v     [        X5      nU$ ! [         a    [        R                  " SU < SU< 35      ef = f)z?Get an attribute, raising SkipTest if AttributeError is raised.zobject  has no attribute )getattrAttributeErrorrt   ru   )objrv   	attributes      re   rG   rG      sB    C&	   O3 MNNOs    )8   c                     U q g r   )_original_stdout)stdouts    re   r   r      s    rd   c                  <    [         =(       d    [        R                  $ r   )r   r{   r   r\   rd   re   r   r      s    )szz)rd   c                 H     [         R                  U 	 g ! [         a     g f = fr   r   )rv   s    re   r   r     s%    KK s    
!!winc                 j   U " U5        U(       a  UnO,[         R                  R                  U5      u  p4U=(       d    SnSnUS:  aP  [         R                  " U5      nU(       a	  U(       d	   g WU;   d  g [        R
                  " U5        US-  nUS:  a  MP  [        R                  " SU-   [        SS9  g )Nrz   gMbP?g      ?   z)tests may fail, delete still pending for    
stacklevel)	ospathsplitlistdirtimesleeprl   warnRuntimeWarning)funcpathnamewaitalldirnamerv   timeoutLs          re   _waitforr   	  s    XGGGMM(3MGnG m 

7#A A '+aiJJwqLG m 	AHL$	4rd   c                 8    [        [        R                  U 5        g r   )r   r   r   )filenames    re   _unlinkr   *  s    H%rd   c                 8    [        [        R                  U 5        g r   r   r   rmdir)r   s    re   _rmdirr   -  s    7#rd   c                 \   ^ U4S jm[        TU SS9  [        [        R                  U 5        g )Nc                 8  > [         R                  " U 5       H  n[         R                  R                  X5      n[         R                  R	                  U5      (       a#  [        TUSS9  [         R                  " U5        Mi  [         R                  " U5        M     g )NTr   )r   r   r   joinisdirr   r   r   )r   rv   fullname_rmtree_inners      re   r   _rmtree.<locals>._rmtree_inner1  s_    

4(77<<377==**]HdCHHX&IIh' )rd   Tr   r   )r   r   s    @re   _rmtreer   0  s$    	( 	d34 rd   c                      [        U 5        g ! [         a9  nUR                  [        R                  [        R                  4;  a  e  S nAg S nAff = fr   )r   OSErrorerrnoENOENTENOTDIR)r   errors     re   r   r   @  s@     ;;u||U]];; <s    
A/AAc                      [        U 5        g ! [         a)  nUR                  [        R                  :w  a  e  S nAg S nAff = fr   )r   r   r   r   )r   r   s     re   r   r   H  s6    w ;;%,,& '    
A<Ac                      [        U 5        g ! [         a)  nUR                  [        R                  :w  a  e  S nAg S nAff = fr   )r   r   r   r   )r   r   s     re   r   r   P  s6     ;;%,,& 'r   c            	         Sn Sn " S S[         R                  5      n[         R                  R                  nUR	                  5       nU(       d  [         R
                  " 5       eU" 5       n[         R                  R                  5       nUR                  UU [         R                  " U5      [         R                  " U5      [         R                  " U5      5      nU(       d  [         R
                  " 5       e[        UR                  U-  5      $ )Nr   c                       \ rS rSrS\R
                  R                  4S\R
                  R                  4S\R
                  R                  4/rSr	g)*_is_gui_available.<locals>.USEROBJECTFLAGSi`  fInherit	fReserveddwFlagsr\   N)
r^   r_   r`   ra   ctypeswintypesBOOLDWORD_fields_rc   r\   rd   re   USEROBJECTFLAGSr   `  s?    #V__%9%9:$foo&:&:;"FOO$9$9:<Hrd   r   )r   	Structurewindlluser32GetProcessWindowStationWinErrorr   r   GetUserObjectInformationWbyrefsizeofboolr   )	UOI_FLAGSWSF_VISIBLEr   dllhuofneededress           re   _is_gui_availabler   ]  s    		<f.. 	< mm""'')//##&&(++ALLMM#LL 	"
 //##CKK+-..rd   c                      g)NTr\   r\   rd   re   r   r   s  s    rd   c                 2    [         SL=(       a	    U [         ;   $ )zLTest whether a resource is enabled.  Known resources are set by
regrtest.py.N)r   resources    re   r   r   v  s     $B])BBrd   c                    U S:X  a%  [        5       (       d  [        R                  " S5      e[        R                  " S5      R
                  R                  S5      S:X  a  g[        U 5      (       d  Uc  SU -  n[        U5      eg)zRaise ResourceDenied if the specified resource is not available.

If the caller's module is __main__ then automatically return True.  The
possibility of False being returned occurs when regrtest.py is
executing.
guizCannot use the 'gui' resourcer   r^   __main__Nz"Use of the %r resource not enabled)	r   rt   ru   r{   	_getframe	f_globalsgetr   r   )r   rx   s     re   r   r   {  sx     5!2!4!4 ?@@ }}Q!!%%j1Z?x((;6ACS!! )rd   c                    ^ ^ UU 4S jnU$ )zDecorator raising SkipTest if the OS is `sysname` and the version is less
than `min_version`.

For example, @_requires_unix_version('FreeBSD', (7, 2)) raises SkipTest if
the FreeBSD version is less than 7.2.
c                 Z   >^  [         R                  " T 5      U UU4S j5       nTUl        U$ )Nc                    > [         R                  " 5       T:X  a  [         R                  " 5       R                  SS5      S   n [	        [        [        UR                  S5      5      5      nUT:  a@  SR                  [        [        T5      5      n[        R                  " T< SU< SU< 35      e T" U 0 UD6$ ! [         a     Nf = f)N-r   r   rz   z	 version  or higher required, not )platformsystemreleaser   tupler   r   r   r   rt   ru   
ValueError)argskwversion_txtversionmin_version_txtr   min_versionsysnames        re   wrapper:_requires_unix_version.<locals>.decorator.<locals>.wrapper  s     G+&..066sA>qA	G#C[->->s-C$DEG ,*-((3sK3H*I&//&FG G -
 $$$ " s   (B; ;
CC	functoolswrapsr  )r   r  r  r  s   ` re   	decorator)_requires_unix_version.<locals>.decorator  s-    			% 
	% *rd   r\   )r  r  r  s   `` re   _requires_unix_versionr    s    $ rd   c                      [        SU 5      $ )zDecorator raising SkipTest if the OS is FreeBSD and the FreeBSD version is
less than `min_version`.

For example, @requires_freebsd_version(7, 2) raises SkipTest if the FreeBSD
version is less than 7.2.
FreeBSDr  r  s    re   r   r     s     ")[99rd   c                      [        SU 5      $ )zDecorator raising SkipTest if the OS is Linux and the Linux version is
less than `min_version`.

For example, @requires_linux_version(2, 6, 32) raises SkipTest if the Linux
version is less than 2.6.32.
Linuxr  r  s    re   r    r      s     "';77rd   c                     ^  U 4S jnU$ )zDecorator raising SkipTest if the OS is Mac OS X and the OS X
version if less than min_version.

For example, @requires_mac_ver(10, 5) raises SkipTest if the OS X version
is lesser than 10.5.
c                 X   >^  [         R                  " T 5      U U4S j5       nTUl        U$ )Nc                  f  > [         R                  S:X  a  [        R                  " 5       S   n [        [	        [
        UR                  S5      5      5      nUT:  a=  SR                  [	        [        T5      5      n[        R                  " SU< SU< 35      e T" U 0 UD6$ ! [         a     Nf = f)Ndarwinr   rz   z	Mac OS X r   )r{   r  mac_verr  r   r   r   r   r   rt   ru   r  )r  r  r  r	  r
  r   r  s        re   r  4requires_mac_ver.<locals>.decorator.<locals>.wrapper  s    ||x'&..03	>#C[->->s-C$DEG ,*-((3sK3H*I&//.=> > -
 $$$ " s   (B# #
B0/B0r  )r   r  r  s   ` re   r  #requires_mac_ver.<locals>.decorator  s-    			% 
	% *rd   r\   )r  r  s   ` re   r!   r!     s    $ rd   z	127.0.0.1::1c                 j    [         R                   " X5      n[        U5      nUR                  5         AU$ )a3  Returns an unused port that should be suitable for binding.  This is
achieved by creating a temporary socket with the same family and type as
the 'sock' parameter (default is AF_INET, SOCK_STREAM), and binding it to
the specified host address (defaults to 0.0.0.0) with the port set to 0,
eliciting an unused ephemeral port from the OS.  The temporary socket is
then closed and deleted, and the ephemeral port is returned.

Either this method or bind_port() should be used for any tests where a
server socket needs to be bound to a particular port for the duration of
the test.  Which one to use depends on whether the calling code is creating
a python socket, or if an unused port needs to be provided in a constructor
or passed to an external program (i.e. the -accept argument to openssl's
s_server mode).  Always prefer bind_port() over find_unused_port() where
possible.  Hard coded ports should *NEVER* be used.  As soon as a server
socket is bound to a hard coded port, the ability to run multiple instances
of the test simultaneously on the same host is compromised, which makes the
test a ticking time bomb in a buildbot environment. On Unix buildbots, this
may simply manifest as a failed test, which can be recovered from without
intervention in most cases, but on Windows, the entire python process can
completely and utterly wedge, requiring someone to log in to the buildbot
and manually kill the affected process.

(This is easy to reproduce on Windows, unfortunately, and can be traced to
the SO_REUSEADDR socket option having different semantics on Windows versus
Unix/Linux.  On Unix, you can't have two AF_INET SOCK_STREAM sockets bind,
listen and then accept connections on identical host/ports.  An EADDRINUSE
socket.error will be raised at some point (depending on the platform and
the order bind and listen were called on each socket).

However, on Windows, if SO_REUSEADDR is set on the sockets, no EADDRINUSE
will ever be raised when attempting to bind two identical host/ports. When
accept() is called on each socket, the second caller's process will steal
the port from the first caller, leaving them both in an awkwardly wedged
state where they'll no longer respond to any signals or graceful kills, and
must be forcibly killed via OpenProcess()/TerminateProcess().

The solution on Windows is to use the SO_EXCLUSIVEADDRUSE socket option
instead of SO_REUSEADDR, which effectively affords the same semantics as
SO_REUSEADDR on Unix.  Given the propensity of Unix developers in the Open
Source world compared to Windows ones, this is a common mistake.  A quick
look over OpenSSL's 0.9.8g source shows that they use SO_REUSEADDR when
openssl.exe is called with the 's_server' option, for example. See
http://bugs.python.org/issue2550 for more info.  The following site also
has a very thorough description about the implications of both REUSEADDR
and EXCLUSIVEADDRUSE on Windows:
http://msdn2.microsoft.com/en-us/library/ms740621(VS.85).aspx)

XXX: although this approach is a vast improvement on previous attempts to
elicit unused ports, it rests heavily on the assumption that the ephemeral
port returned to us by the OS won't immediately be dished back out to some
other process when we close and delete our temporary socket but before our
calling code has a chance to bind the returned port.  We can deal with this
issue if/when we come across it.
)socketr#   close)familysocktypetempsockports       re   r"   r"     s/    p }}V.HXDNNKrd   c                    U R                   [        R                  :X  Ga  U R                  [        R                  :X  a  [        [        S5      (       a=  U R                  [        R                  [        R                  5      S:X  a  [        S5      e[        [        S5      (       a?   U R                  [        R                  [        R                  5      S:X  a  [        S5      e [        [        S5      (       a/  U R                  [        R                  [        R                  S5        U R                  US45        U R                  5       S   nU$ ! [        R                   a     Nf = f)a  Bind the socket to a free port and return the port number.  Relies on
ephemeral ports in order to ensure we are using an unbound port.  This is
important as many tests may be running simultaneously, especially in a
buildbot environment.  This method raises an exception if the sock.family
is AF_INET and sock.type is SOCK_STREAM, *and* the socket has SO_REUSEADDR
or SO_REUSEPORT set on it.  Tests should *never* set these socket options
for TCP/IP sockets.  The only case for setting these options is testing
multicasting via multiple UDP sockets.

Additionally, if the SO_EXCLUSIVEADDRUSE socket option is available (i.e.
on Windows), it will be set on the socket.  This will prevent anyone else
from bind()'ing to our host/port for the duration of the test.
SO_REUSEADDRr   zHtests should never set the SO_REUSEADDR socket option on TCP/IP sockets!SO_REUSEPORTzHtests should never set the SO_REUSEPORT socket option on TCP/IP sockets!SO_EXCLUSIVEADDRUSEr   )r&  r$  AF_INETtypeSOCK_STREAMhasattr
getsockopt
SOL_SOCKETr+  r   r,  r   
setsockoptr-  bindgetsockname)sockhostr)  s      re   r#   r#     s     {{fnn$f6H6H)H6>**v00&2E2EF!K  "D E E6>**??6#4#4f6I6IJaO$ &H I I P 6011OOF--v/I/I1MIItQia DK <<  	s   &=E E'&E'c                     [         R                  (       aa  Sn  [         R                   " [         R                  [         R                  5      n U R	                  S5         U (       a  U R                  5         ggg! [         R                  [         R                  4 a     Of = f U (       a  U R                  5         g! U (       a  U R                  5         f f = f)z+Check whether IPv6 is enabled on this host.N)r"  r   TF)r$  has_ipv6AF_INET6r0  r5  r%  r   gaierror)r7  s    re   _is_ipv6_enabledr=  >  s    	==&2D2DEDIIj! 

  foo. 		

 

 s$   AA8 8$BB; BB; ;Ci @ i  zrequires zlibzrequires bz2zrequires lzmajavaz$testz@testz{0}_{1}_tmpc              #   V  #    [         R                  " 5       nSnUc  U n [         R                  " U 5        Sn [         R                  " U5         [         R                  " 5       v   [         R                  " U5        U(       a  [        U 5        gg! [         a(    U(       d  e [        R
                  " SU -   [        SS9   Nf = f! [         a(    U(       d  e [        R
                  " SU-   [        SS9   Nf = f! [         R                  " U5        U(       a  [        U 5        f f = f7f)a  
Context manager that temporarily changes the CWD.

An existing path may be provided as *path*, in which case this
function makes no changes to the file system.

Otherwise, the new CWD is created in the current directory and it's
named *name*. If *quiet* is False (default) and it's not possible to
create or change the CWD, an error is raised.  If it's True, only a
warning is raised and the original CWD is used.
FNTz*tests may fail, unable to create temp CWD    r   z,tests may fail, unable to change the CWD to )	r   getcwdmkdirr   rl   r   r   chdirr   )rv   quietr   	saved_diris_temporarys        re   r)   r)     s      		IL|	8HHTNL4
iik
4L !  	8MMFM(Q8	8  4DtK$	44 	4L sW   D)B C C; '*D)/C D)CD)/C85D)7C88D);+D&&D)umaskc              #      #    [         R                  " U 5      n Sv   [         R                  " U5        g! [         R                  " U5        f = f7f)z8Context manager that temporarily sets the process umask.N)r   rG  )rG  oldmasks     re   r:   r:     s4      ((5/	HHWBHHWs   A5 AAAc                    [         R                  R                  U 5      (       a  U $ Ub  [         R                  R                  X 5      n [        R                  n[         R                  R                  U5      /U-   nU HJ  n[         R                  R                  X@5      n[         R                  R                  U5      (       d  MH  Us  $    U $ )zTry to find a file on sys.path and the working directory.  If it is not
found the argument passed to the function is returned (this does not
necessarily signal failure; could still be the legitimate path).)r   r   isabsr   r{   r   exists)fileheresubdirr   dnfns         re   r*   r*   &  s     
ww}}Tww||F)88DGGOOD!"T)DWW\\"#77>>"by  Krd   c                     [         R                  " U [         R                  [         R                  -  [         R                  -  5      n[         R
                  " U5        g)z>Create an empty file. If the file already exists, truncate it.N)r   r
   O_WRONLYO_CREATO_TRUNCr%  )r   fds     re   r+   r+   5  s3    	2;;3bjj@	ABHHRLrd   c                     [        U R                  5       5      nU Vs/ s H  nSU-  PM
     nnSR                  U5      nSU-  $ s  snf )z%Like repr(dict), but in sorted order.z%r: %rz, z{%s})sortedr   r   )dictr   pair	reprpairs
withcommass        re   r,   r,   :  sH    4::< E-23UTDUI39%JJ 4s   Ac                      [        [        S5      n  U R                  5       U R                  5         [	        [        5        $ ! U R                  5         [	        [        5        f = f)zT
Create an invalid file descriptor by opening and closing a file and return
its fd.
wb)r
   r&   filenor%  r   rM  s    re   make_bad_fdra  A  sB    
 D{{}

v 	

vs   A !A"c                 >    U R                  [        [        USS5        g )Nz<test string>exec)assertRaisesSyntaxErrorcompile)testcase	statements     re   r-   r-   M  s    +w	)63rd   c                 D  ^^^ SSK JnJn  TR                  SS 5      mUR	                  U 5      S   R                  S5      S   n[        R                  R                  [        R                  R                  [        5      SU5      nUUU4S jn[        R                  R                  U5      (       a  U" U5      nUb  U$ [        U5        [        S	5        [        S
U -  [        5       S9  UR!                  U SS9n [#        US5       n	UR%                  5       n
U
(       a*  U	R'                  U
5        UR%                  5       n
U
(       a  M*  S S S 5        UR)                  5         U" U5      nUb  U$ [+        SU-  5      e! , (       d  f       N9= f! UR)                  5         f = f)Nr   )requestparsecheckr   /datac                    > [        U /TQ70 TD6nTc  U$ T" U5      (       a  UR                  S5        U$ UR                  5         g Nr   )r
   seekr%  )rQ  r   r  rl  r  s     re   check_valid_file*open_urlresource.<locals>.check_valid_file[  sC    !d!b!=H1XXFF1IH		rd   urlfetchz	fetching %s ...r`     )r   r^  zinvalid resource %r)future.backports.urllibrj  rk  popurlparser   r   r   r   r   __file__rL  r   r   printr   urlopenr
   readwriter%  r   )urlr  r  urllib_requesturllib_parser   rQ  rs  r   outsrl  s    ``        @re   r.   r.   Q  sO   @ FF7D!E$$S)!,2237;H	bggooh/	BB 
ww~~bR =Hr
 Z	

#*=*?@sB/A"d^sA		!FFH !  	
	A}
*R/
00 ^ 	
	s%   ;F A E<	F <
F
F Fc                   :    \ rS rSrSrS rS r\S 5       rS r	Sr
g)	WarningsRecorderi~  znConvenience wrapper for the warnings list returned on
entry to the warnings.catch_warnings() context manager.
c                     Xl         SU l        g rq  	_warnings_last)selfwarnings_lists     re   __init__WarningsRecorder.__init__  s    &
rd   c                     [        U R                  5      U R                  :  a  [        U R                  S   U5      $ U[        R
                  R                  ;   a  g [        U < SU< 35      e)Nrn  r   )lenr  r  r   rl   WarningMessage_WARNING_DETAILSr   )r  attrs     re   __getattr__WarningsRecorder.__getattr__  sT    t~~+4>>"-t44X,,===tDEErd   c                 4    U R                   U R                  S  $ r   r  r  s    re   rl   WarningsRecorder.warnings  s    ~~djjk**rd   c                 8    [        U R                  5      U l        g r   )r  r  r  r  s    re   resetWarningsRecorder.reset  s    (
rd   )r  r  N)r^   r_   r`   ra   rb   r  r  propertyrl   r  rc   r\   rd   re   r  r  ~  s+    F + +)rd   r  c              #     #    [         R                  " S5      nUR                  R                  S5      nU(       aQ  [        R
                  (       a  UR                  5         O+[        [        U5      5       H  nUR                  5         M     [        R                  " SS9 n[         R                  S   R                  S5        [        U5      v   SSS5        [        W5      n/ nU  H  u  pSn
USS  Hu  nUR                   n["        R$                  " U['        U5      ["        R(                  5      (       d  ME  [+        UR,                  U	5      (       d  Mb  Sn
UR/                  U5        Mw     U
(       a  M  U(       a  M  UR1                  XR2                  45        M     U(       a  [5        S	US
   -  5      eU(       a  [5        SUS
   -  5      eg! , (       d  f       GN= f7f)zCatch the warnings, then check if all the expected
warnings have been raised and re-raise unexpected warnings.
If 'quiet' is True, only re-raise the unexpected warnings.
r   __warningregistry__T)recordrl   alwaysNFzunhandled warning %sr   z)filter (%r, %s) did not catch any warning)r{   r   r   r   r   PY3clearr	   r  rx  rl   rm   r|   simplefilterr  r   messagerematchr   I
issubclass	__class__remover   r^   AssertionError)filtersrD  frameregistryiwreraisemissingrx   catseenwarnings               re   _filterwarningsr    sp     MM!E""#89H99NN 3x=) *		 	 	- 	J,,X6q!! 
. 1gGGAiiGc'lBDD117,,c22q!  tEENNC./  3gaj@AAH$QZ( ) 	) / 
.	-s8   BG! 0GA$G!8G!G!5G!>AG!
GG!c                  d    UR                  S5      nU (       d  S[        44n Uc  Sn[        X5      $ )at  Context manager to silence warnings.

Accept 2-tuples as positional arguments:
    ("message regexp", WarningCategory)

Optional argument:
 - if 'quiet' is True, it does not fail if a filter catches nothing
    (default True without argument,
     default False if some filters are defined)

Without argument, it defaults to:
    check_warnings(("", Warning), quiet=True)
rD   T)r   Warningr  )r  kwargsrD  s      re   r/   r/     s6     JJwE="=E7**rd   c                   *    \ rS rSrSrS rS rS rSrg)r0   i  a  Context manager to force import to return a new module reference.

This is useful for testing module-level behaviours, such as
the emission of a DeprecationWarning on import.

Use like this:

    with CleanImport("foo"):
        importlib.import_module("foo") # new reference
c                 &   [         R                  R                  5       U l        U Hh  nU[         R                  ;   d  M  [         R                  U   nUR                  U:w  a  [         R                  UR                  	 [         R                  U	 Mj     g r   )r{   r|   copyoriginal_modulesr^   )r  module_namesmodule_namer   s       re   r  CleanImport.__init__  se     # 0 0 2'Kckk)[1
 ??k1FOO4KK, (rd   c                     U $ r   r\   r  s    re   	__enter__CleanImport.__enter__      rd   c                 V    [         R                  R                  U R                  5        g r   )r{   r|   updater  r  
ignore_excs     re   __exit__CleanImport.__exit__  s    4001rd   )r  N	r^   r_   r`   ra   rb   r  r  r  rc   r\   rd   re   r0   r0     s    	-2rd   r0   c                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)r1   i  z[Class to help protect the environment variable properly.  Can be used as
a context manager.c                 <    [         R                  U l        0 U l        g r   )r   environ_environ_changedr  s    re   r  EnvironmentVarGuard.__init__  s    

rd   c                      U R                   U   $ r   )r  r  envvars     re   __getitem__EnvironmentVarGuard.__getitem__
  s    }}V$$rd   c                     XR                   ;  a(  U R                  R                  U5      U R                   U'   X R                  U'   g r   r  r  r   r  r  values      re   __setitem__EnvironmentVarGuard.__setitem__  s5    &$(MM$5$5f$=DMM&! %frd   c                     XR                   ;  a(  U R                  R                  U5      U R                   U'   XR                  ;   a  U R                  U	 g g r   r  r  s     re   __delitem__EnvironmentVarGuard.__delitem__  sD    &$(MM$5$5f$=DMM&!]]"f% #rd   c                 6    U R                   R                  5       $ r   )r  keysr  s    re   r  EnvironmentVarGuard.keys  s    }}!!##rd   c                 ,    [        U R                  5      $ r   )iterr  r  s    re   __iter__EnvironmentVarGuard.__iter__  s    DMM""rd   c                 ,    [        U R                  5      $ r   )r  r  r  s    re   __len__EnvironmentVarGuard.__len__   s    4==!!rd   c                     X U'   g r   r\   r  s      re   setEnvironmentVarGuard.set#  s	    Vrd   c                     X	 g r   r\   r  s     re   unsetEnvironmentVarGuard.unset&  s    Lrd   c                     U $ r   r\   r  s    re   r  EnvironmentVarGuard.__enter__)  r  rd   c                     U R                   R                  5        H6  u  p#Uc   X R                  ;   a  U R                  U	 M&  M(  X0R                  U'   M8     U R                  [        l        g r   )r  r   r  r   r  )r  r  kvs       re   r  EnvironmentVarGuard.__exit__,  sV    mm))+FQy%a( & $%a  , ]]
rd   )r  r  N)r^   r_   r`   ra   rb   r  r  r  r  r  r  r  r  r  r  r  rc   r\   rd   re   r1   r1     s>    %&&$#"#rd   r1   c                   *    \ rS rSrSrS rS rS rSrg)DirsOnSysPathi6  ar  Context manager to temporarily add directories to sys.path.

This makes a copy of sys.path, appends any directories given
as positional arguments, then reverts sys.path to the copied
settings when the context ends.

Note that *all* sys.path modifications in the body of the
context manager, including replacement of the object,
will be reverted at the end of the block.
c                     [         R                  S S  U l        [         R                  U l        [         R                  R	                  U5        g r   )r{   r   original_valueoriginal_objectextend)r  pathss     re   r  DirsOnSysPath.__init__B  s.    !hhqk"xxrd   c                     U $ r   r\   r  s    re   r  DirsOnSysPath.__enter__G  r  rd   c                 h    U R                   [        l        U R                  [        R                  S S & g r   )r  r{   r   r  r  s     re   r  DirsOnSysPath.__exit__J  s"    ''))rd   )r  r  Nr  r\   rd   re   r  r  6  s    	
*rd   r  c                   .    \ rS rSrSrS rS rSS jrSrg)	r2   iO  zRaise ResourceDenied if an exception is raised while the context manager
is in effect that matches the specified exception and attributes.c                     Xl         X l        g r   )excattrs)r  r  r  s      re   r  TransientResource.__init__T  s    
rd   c                     U $ r   r\   r  s    re   r  TransientResource.__enter__X  r  rd   Nc                     Ubm  [        U R                  U5      (       aQ  U R                  R                  5        H(  u  pE[	        X$5      (       d    g[        X$5      U:w  d  M(    g   [        S5      egg)zIf type_ is a subclass of self.exc and value has attributes matching
self.attrs, raise ResourceDenied.  Otherwise let the exception
propagate (if any).Nz%an optional resource is not available)r  r  r  r   r1  r   r   )r  type_r  	tracebackr  
attr_values         re   r  TransientResource.__exit__[  sh     DHHe!<!<$(JJ$4$4$6 u++5':5	 %7 %%LMM "=rd   )r  r  )NNNr  r\   rd   re   r2   r2   O  s    INrd   r2   )r   c           	   #     ^^^#    / SQn/ SQn[        SU -  5      mUm/ mT(       dJ  U VVs/ s H  u  pV[        [        XV5      PM     snnmU VVs/ s H  u  pV[        [        XV5      PM     snnmUUU4S jn[        R                  " 5       n Ub  [        R
                  " U5        Sv    [        R
                  " U5        gs  snnf s  snnf ! [         ax  n	 U	R                  n
[        U
5      S:  a  [        U
S   [        5      (       a  U
S   n	O.[        U
5      S:  a  [        U
S   [        5      (       a  U
S   n	OOMi  U" U	5        e Sn	A	ff = f! [        R
                  " U5        f = f7f)	zReturn a context manager that raises ResourceDenied when various issues
with the Internet connection manifest themselves as exceptions.))ECONNREFUSEDo   )
ECONNRESETh   )EHOSTUNREACHq   )ENETUNREACHe   )	ETIMEDOUTn   ))	EAI_AGAIN)EAI_FAIL)
EAI_NONAME)
EAI_NODATA)
WSANO_DATAi*  zResource %r is not availablec                 <  > [        U SS 5      n[        U [        R                  5      (       d+  [        U [        R                  5      (       a  UT;   d  UT;   aD  [
        (       d/  [        R                  R                  TR                  S   S-   5        TnXl
        Ueg )Nr   r   
)r   
isinstancer$  r   r<  r   r{   stderrr~  r  	__cause__)errnr  captured_errnosdenied
gai_errnoss      re   filter_error(transient_internet.<locals>.filter_error  s{    C$'sFNN++V__--!z/ 7

  Q$!67 CMI !rd   Nr   r   r   )
r   r   r   r$  getdefaulttimeoutsetdefaulttimeoutIOErrorr  r  r$  )resource_namer   errnosdefault_errnosdefault_gai_errnosrv   numr,  old_timeoutr'  ar)  r*  r+  s              @@@re   r;   r;   p  s]    N :]JKFOJ.<>.<{ #5$4.<> *<=);+4 fd0);=
 **,K.$$W-( 	  -U>=*   A1v{z!A$88d Q1AaD'!:!:d  	S& 	  -sM   'E0C	E0C
-!E0C -#E0
EA3EEE E--E0c              #      #    SSK n[        [        U 5      n[        [        XR	                  5       5         [        [        U 5      v   [        [        X5        g! [        [        X5        f = f7f)zReturn a context manager used by captured_stdout/stdin/stderr
that temporarily replaces the sys stream *stream_name* with a StringIO.r   N)ior   r{   setattrStringIO)stream_namer9  orig_stdouts      re   captured_outputr>    sL      #{+KCkkm,/c;''[.[.s   3A.A A.A++A.c                      [        S5      $ )z{Capture the output of sys.stdout:

with captured_stdout() as s:
    print("hello")
self.assertEqual(s.getvalue(), "hello")
r   r>  r\   rd   re   r3   r3     s     8$$rd   c                      [        S5      $ )Nr%  r@  r\   rd   re   r5   r5     s    8$$rd   c                      [        S5      $ )Nstdinr@  r\   rd   re   r4   r4     s    7##rd   c                      [         R                  " 5         [        (       a  [        R                  " S5        [         R                  " 5         [         R                  " 5         g)a  Force as many objects as possible to be collected.

In non-CPython implementations of Python, this is needed because timely
deallocation is not guaranteed by the garbage collector.  (Even in CPython
this can be the case in case of reference cycles.)  This means that __del__
methods may be called later than expected and weakrefs may remain alive for
longer than expected.  This function tries its best to force all garbage
objects to disappear.
皙?N)gccollectr%   r   r   r\   rd   re   
gc_collectrH    s/     JJLy

3JJLJJLrd   c               #      #    [         R                  " 5       n [         R                  " 5          S v   U (       a  [         R                  " 5         g g ! U (       a  [         R                  " 5         f f = f7fr   )rF  	isenableddisableenable)have_gcs    re   
disable_gcrN    sC     llnGJJLIIK 7IIK s   +A2A A2A//A2c                      SSK n U R                  " S5      =(       d    SnSnUR                  5        H  nUR                  S5      (       d  M  UnM     US:g  =(       a    US:g  $ )z,Find if Python was built with optimizations.r   N	PY_CFLAGSr  z-Oz-O0)r   get_config_varr   r~   )r   cflags	final_optopts       re   python_is_optimizedrU    s[     %%k28bFI||~>>$I  ?1yE11rd   nP0ngettotalrefcount2P0Pr(  c                 J    [         R                  " [        U -   [        -   5      $ r   )structcalcsize_header_alignfmts    re   calcobjsizerb    s    ??7S=6122rd   c                 J    [         R                  " [        U -   [        -   5      $ r   )r\  r]  _vheaderr_  r`  s    re   calcvobjsizere    s    ??8c>F233rd   i @  i   c                 X   [         R                  " U5      n[        U5      [        :X  a  UR                  [        -  (       d4  [        U5      [        :w  a4  [        U5      R                  [
        -  (       a  U[        R                  -  nS[        U5      X24-  nU R                  X2U5        g )Nz&wrong size for %s: got %d, expected %d)	r{   	getsizeofr/  	__flags___TPFLAGS_HEAPTYPE_TPFLAGS_HAVE_GC	_testcapiSIZEOF_PYGC_HEADassertEqual)testosizeresultrx   s        re   check_sizeofrr  	  sz    ]]1F	aDq{{->>
q'T/Q 1 14D D	***
2Aw%&CV3'rd   c                    ^ ^ U U4S jnU$ )Nc                 ^   >^  UU U4S jnT R                   Ul         T R                  Ul        U$ )Nc                  \  >  SS K n[        UT5      nUR                  U5      nT H  n UR                  X55          O     T" U 0 UD6U(       a  U(       a  UR                  WU5        $ $ $ !    MJ  = f! [         a    e   S =p$ ND= f! U(       a  U(       a  UR                  WU5        f f f = frq  )localer   	setlocaler   )	r  kwdsrv  categoryorig_localeloccatstrr   localess	         re   inner1run_with_locale.<locals>.decorator.<locals>.inner  s    "662$..x8 #C((7 #<T*T*k$$X{; *6 " ,'++ k$$X{; *6s"   !A3 A+B +A03B$B+r^   rb   )r   r~  r|  r}  s   ` re   r  "run_with_locale.<locals>.decorator  s%    	<2 rd   r\   )r|  r}  r  s   `` re   r9   r9     s    : rd   c                    ^  U 4S jnU$ )Nc                 \   >^  U U4S jnT R                   Ul         T R                  Ul        U$ )Nc                    >  [         R                  nS[
        R                  ;   a  [
        R                  S   nOS nT[
        R                  S'   U" 5          T" U 0 UD6Uc  [
        R                  S	 OU[
        R                  S'   [         R                  " 5         $ ! [         a    [        R                  " S5      ef = f! Uc  [
        R                  S	 OU[
        R                  S'   [         R                  " 5         f = f)Nztzset requiredTZ)r   tzsetr   rt   ru   r   r  )r  rx  r  orig_tzr   tzs       re   r~  -run_with_tz.<locals>.decorator.<locals>.inner=  s    :

 rzz!**T*!BJJtGT*T*?

4('.BJJt$

# " :''(899: ?

4('.BJJt$

s   B C !B>?D r  )r   r~  r  s   ` re   r  run_with_tz.<locals>.decorator<  s%    	, rd   r\   )r  r  s   ` re   rU   rU   ;  s    4 rd   i      r   r   c                    S[         [        S[        -  S.n[        R                  " SU [        R                  [        R
                  -  5      nUc  [        SU < 35      e[        [        UR                  S5      5      XR                  S5      R                  5          -  5      nUqU[        :  a  [        nU[        S-
  :  a  [        SU < S35      eUqg )	Nr  )r  mgtz(\d+(\.\d+)?) (K|M|G|T)b?$zInvalid memory limit r   r@  zMemory limit z too low to be useful)_1M_1Gr  r  
IGNORECASEVERBOSEr  r   floatgrouplowerreal_max_memuseMAX_Py_ssize_t_2Gr   )limitsizesr  memlimits       re   r<   r<   e  s     #X	E 	.+	-Aye=>>5$uWWQZ-=-=-?'@@AHO. !#'5JKKJrd   c                   *    \ rS rSrSrS rS rS rSrg)_MemoryWatchdogiz  zXAn object which periodically watches the process' memory consumption
and prints it out.
c                 `    SR                  [        R                  " 5       S9U l        SU l        g )Nz/proc/{pid}/statm)pidF)formatr   getpidprocfilestartedr  s    re   r  _MemoryWatchdog.__init__  s$    +22ryy{2Crd   c                     [        U R                  S5      n[        S5      n[        R                  " [        R                  U/U[        R                  S9U l        UR!                  5         SU l        g ! [         aR  n[        R                  " SR                  U5      [        5        [        R                  R                  5          S nAg S nAff = f)Nrz"/proc not available for stats: {0}zmemory_watchdog.py)rC  r%  T)r
   r  r   rl   r   r  r   r{   r%  flushr*   
subprocessPopen
executableDEVNULLmem_watchdogr%  r  )r  r   ewatchdog_scripts       re   start_MemoryWatchdog.start  s    	T]]C(A ##78&,,cnno-N34Z=O=OQ		  	MM>EEaH(*JJ		s   A4 4
C>ACCc                     U R                   (       a5  U R                  R                  5         U R                  R                  5         g g r   )r  r  	terminatewaitr  s    re   stop_MemoryWatchdog.stop  s2    <<'')""$ rd   )r  r  r  N)	r^   r_   r`   ra   rb   r  r  r  rc   r\   rd   re   r  r  z  s    %rd   r  c                    ^ ^^ UUU 4S jnU$ )a)  Decorator for bigmem tests.

'minsize' is the minimum useful size for the test (in arbitrary,
test-interpreted units.) 'memuse' is the number of 'bytes per size' for
the test, or a good estimate of it.

if 'dry_run' is False, it means the test doesn't support dummy runs
when -M is not specified.
c                 8   >^ ^ UU U4S jmTTl         TTl        T$ )Nc                   > TR                   nTR                  n[        (       d  SnOUn[        (       d  T(       d*  [        X2-  :  a  [        R                  " SX-  S-  -  5      e[        (       aM  [
        (       aB  [        5         [        SR                  X-  S-  S95        [        5       nUR                  5         OS n T" X5      U(       a  UR                  5         $ $ ! U(       a  UR                  5         f f = f)Ni  'not enough memory: %.1fG minimum needed   @z* ... expected peak memory use: {peak:.1f}G)peak)rp  memuser  rt   ru   r   r{  r  r  r  r  )r  rp  r  maxsizewatchdogdry_runr   r  s        re   r  .bigmemtest.<locals>.decorator.<locals>.wrapper  s    <<D^^F"? #g&66''=}	245 5 77Bv4=I#>v?A*, $'MMO 8MMO s   C! !C;)rp  r  )r   r  r  r  rp  s   `@re   r  bigmemtest.<locals>.decorator  s    	$: rd   r\   )rp  r  r  r  s   ``` re   r=   r=     s     B rd   c                    ^  U 4S jnU$ )z0Decorator for tests that fill the address space.c                    > [         [        :  aJ  [        S:  a   [         S:  a  [        R                  " S5      e[        R                  " S[        S-  -  5      eT" U 5      $ )Nl    l        z-not enough memory: try a 32-bit build insteadr  r  )r   r  rt   ru   )r  r   s    re   r  !bigaddrspacetest.<locals>.wrapper  sb    &*zU/B''CE E ''=%356 6 T7Nrd   r\   )r   r  s   ` re   r>   r>     s    
 Nrd   c                       \ rS rSrS rSrg)r?   i  c                 @    [         R                  " 5       nU" U5        U$ r   )rt   
TestResult)r  rn  rq  s      re   runBasicTestRunner.run  s    $$&Vrd   r\   N)r^   r_   r`   ra   r  rc   r\   rd   re   r?   r?     s    rd   r?   c                     U $ r   r\   )r   s    re   _idr    s    Jrd   c                     U S:X  a%  [        5       (       d  [        R                  " S5      $ [        U 5      (       a  [        $ [        R                  " SR                  U 5      5      $ )Nr   zresource 'gui' is not availablezresource {0!r} is not enabled)r   rt   r   r   r  r  r   s    re   requires_resourcer    sN    5!2!4!4}}>??8$$
}}<CCHMNNrd   c                      [        SS9" U 5      $ )z1
Decorator for tests only applicable on CPython.
T)cpython)impl_detailrn  s    re   rE   rE     s     t$T**rd   c                    [        S0 UD6(       a  [        $ U cR  [        U5      u  p#U(       a  Sn OSn [        UR	                  5       5      nU R                  SR                  U5      5      n [        R                  " U 5      $ )Nz*implementation detail not available on {0}z%implementation detail specific to {0}z or r\   )	rF   r  _parse_guardsrX  r  r  r   rt   r   )rx   guards
guardnamesdefaults       re   r  r    sh    "6"

{+F3
>C9CJOO-.
jjZ01==rd   c                     U (       d  SS0S4$ [        U R                  5       5      S   n[        U R                  5       5      U/[        U 5      -  :X  d   eX(       + 4$ )Nr  TFr   )r   valuesr  )r  is_trues     re   r  r    sY    D!5))6==?#A&G WIF$;;;;K  rd   c                      [        U 5      u  pU R                  [        R                  " 5       R	                  5       U5      $ )a  This function returns True or False depending on the host platform.
Examples:
   if check_impl_detail():               # only on CPython (default)
   if check_impl_detail(jython=True):    # only on Jython
   if check_impl_detail(cpython=False):  # everywhere except on CPython
)r  r   r  python_implementationr  )r  r  s     re   rF   rF     s3     $F+OF::h446<<>HHrd   c                 t   ^  [        [        S5      (       d  T $ [        R                  " T 5      U 4S j5       nU$ )zEDecorator to temporarily turn off tracing for the duration of a test.gettracec                     > [         R                  " 5       n [         R                  " S 5        T" U 0 UD6[         R                  " U5        $ ! [         R                  " U5        f = fr   )r{   r  settrace)r  r  original_tracer   s      re   r  no_tracing.<locals>.wrapper  sE     \\^N-T"T,V,^,^,s   A A$)r1  r{   r  r  )r   r  s   ` re   
no_tracingr    s7    3
##			- 
	- rd   c                 *    [        [        U 5      5      $ )zDecorator for tests which involve reference counting.

To start, the decorator does not run the test if is not run by CPython.
After that, any trace function is unset during the test to prevent
unexpected refcounts caused by the trace function.

)r  rE   r  s    re   refcount_testr     s     l4())rd   c                     / nU R                    H`  n[        U[        R                  5      (       a  [	        X15        UR                  U5        M@  U" U5      (       d  MO  UR                  U5        Mb     X l         g)z>Recursively filter test cases in a suite based on a predicate.N)_testsr$  rt   	TestSuite_filter_suiter   )suiteprednewtestsrn  s       re   r  r  +  sX    HdH..//$%OOD!Dzz%  Lrd   c                    [         (       a)  [        R                  " [        R                  S[
        S9nO
[        5       nUR                  U 5      nUR                  5       (       d  [        UR                  5      S:X  a$  UR                  (       d  UR                  S   S   nOO[        UR                  5      S:X  a$  UR                  (       d  UR                  S   S   nOSn[         (       d  US-  n[        U5      eg)z2Run tests from a unittest.TestSuite-derived class.r   )	verbosityrS   r   r   zmultiple errors occurredz!; run in verbose mode for detailsN)r   rt   TextTestRunnerr{   r   rS   r?   r  wasSuccessfulr  errorsfailuresr   )r  runnerrq  r'  s       re   
_run_suiter  7  s    w((q2:< !"ZZF!!v}}"6??--"1%C!Q&v}}//!$Q'C,C7C#FFCo "rd   c                     [         R                  [         R                  4n[         R                  " 5       nU  H  n[        U[        5      (       aW  U[
        R                  ;   a8  UR                  [         R                  " [
        R                  U   5      5        Md  [        S5      e[        X15      (       a  UR                  U5        M  UR                  [         R                  " U5      5        M     S n[        X$5        [        U5        g)z1Run tests from unittest.TestCase-derived classes.z)str arguments must be keys in sys.modulesc                     [         c  gU R                  5       R                  S5       H%  n[        R                  " U[         5      (       d  M%    g   g)NTrz   F)match_testsidr   fnmatchfnmatchcase)rn  rv   s     re   	case_predrun_unittest.<locals>.case_predY  s?    GGIOOC(D""455 ) rd   N)rt   r  TestCaser$  r   r{   r|   addTestfindTestCasesr  	makeSuiter  r  )classesvalid_typesr  clsr  s        re   r@   r@   K  s    %%x'8'89K Ec3ckk!h44S[[5EFG !LMM))MM#MM(,,S12  %#urd   c                     SSK nUc  [        nOSnUR                  XUS9u  pEU(       a  [        SXE4-  5      e[        (       a  [	        SU R
                  U4-  5        XE4$ )zRun doctest on the given module.  Return (#failures, #tests).

If optional argument verbosity is not specified (or is None), pass
support's belief about verbosity on to doctest.  Else doctest's
usual behavior is used (it searches sys.argv for -v).
r   N)r   optionflagsz%d of %d doctests failedz,doctest (%s) ... %d tests with zero failures)doctestr   testmodr   r{  r^   )r   r  r  r  r   r  s         re   rA   rA   r  si     		??6+?NDA3qf<==w<"# 	$4Krd   c                  @    [         R                  R                  5       4$ r   )r{   r|   r  r\   rd   re   modules_setupr	    s    ;;rd   c                    [         R                  R                  5        VVs/ s H   u  pUR                  S5      (       d  M  X4PM"     nnn[	        [        [         R                  5      5       H!  n[         R                  R                  5         M#     [         R                  R                  U5        [         R                  R                  U 5        g s  snnf )Nz
encodings.)r{   r|   r   r~   r	   r  rx  r  )
oldmodulesr  r  	encodingsr  s        re   modules_cleanupr    s     %(KK$5$5$7 0$7DALL. !$7I 0
 3s{{#$ % KKy! KKz"0s   CCc                  F    [         (       a  [         R                  " 5       4$ g)N)r   )_thread_countr\   rd   re   rB   rB     s    w~~  rd   c                     [         (       d  g Sn[        U5       H5  n[         R                  " 5       nX0:X  a    g [        R                  " S5        M7     g )N
   rE  )r  r	   r  r   r   )
nb_threads
_MAX_COUNTcountr(  s       re   rC   rC     s=    7Jz"NN?

3	 #rd   c                 `   ^  [         (       d  T $ [        R                  " T 5      U 4S j5       nU$ )zUse this function when threads are being used.  This will
ensure that the threads are cleaned up even when the test fails.
If threading is unavailable this function does nothing.
c                  N   > [        5       n T" U 6 [        U6   $ ! [        U6   f = fr   )rB   rC   )r  keyr   s     re   r  reap_threads.<locals>.decorator  s)    	$;s#s#s    
$)r  r  r  )r   r  s   ` re   reap_threadsr    s2    
 7__T$ $ rd   c                      [        [        S5      (       a5  Sn   [        R                  " U [        R                  5      u  pUS:X  a  g M2  g!    g= f)zUse this function at the end of test_main() whenever sub-processes
are started.  This will help ensure that no extra children (zombies)
stick around to hog resources and create problems when looking
for refleaks.
waitpidrn  r   N)r1  r   r  WNOHANG)any_processr  statuss      re   rD   rD     sW     r9 jjbjjA!8 	  s   -A Ac              #      #    [        X5      (       a)  [        X5      n[        XU5         Sv   [        XU5        g[        XU5         Sv   [        X5        g! [        XU5        f = f! [        X5        f = f7f)aM  Temporary swap out an attribute with a new object.

Usage:
    with swap_attr(obj, "attr", 5):
        ...

    This will set obj.attr to 5 for the duration of the with: block,
    restoring the old value at the end of the block. If `attr` doesn't
    exist on `obj`, it will be created and then deleted at the end of the
    block.
N)r1  r   r:  delattr)r   r  new_valreal_vals       re   rI   rI     sj      s3%7#	)Cx(7#	C Cx( Cs3   (A:A A:	A* A:A''A:*A77A:c              #   p   #    X;   a  X   nX U'    Sv   X0U'   gX U'    Sv   X	 g! X0U'   f = f! X	 f = f7f)aK  Temporary swap out an item with a new object.

Usage:
    with swap_item(obj, "item", 5):
        ...

    This will set obj["item"] to 5 for the duration of the with: block,
    restoring the old value at the end of the block. If `item` doesn't
    exist on `obj`, it will be created and then deleted at the end of the
    block.
Nr\   )r   itemr"  r#  s       re   rH   rH     sO      {9D		! ID			 !I 	s$   6& 	6/ 6,636c                 R    [         R                  " SSU 5      R                  5       n U $ )zStrip the stderr of a Python process from potential debug output
emitted by the interpreter.

This will typically be run on the result of the communicate() method
of a subprocess.Popen object.
s   \[\d+ refs\]\r?\n?rd   )r  substrip)r%  s    re   strip_python_stderrr)     s%     VV*C8>>@FMrd   c                  ,    [         R                  " 5       $ )zjReturn a list of command-line arguments reproducing the current
settings in sys.flags and sys.warnoptions.)r  _args_from_interpreter_flagsr\   rd   re   args_from_interpreter_flagsr,  *  s     2244rd   c                   ,    \ rS rSrS rS rS rS rSrg)rK   i3  c                 d    [         R                  R                  R                  U S5        Xl        g rq  )logginghandlersBufferingHandlerr  matcher)r  r2  s     re   r  TestHandler.__init__4  s%     	))224;rd   c                     g)NFr\   r  s    re   shouldFlushTestHandler.shouldFlush=  s    rd   c                 p    U R                  U5        U R                  R                  UR                  5        g r   )r  bufferr   __dict__)r  r  s     re   emitTestHandler.emit@  s$    F6??+rd   c                 ~    SnU R                    H*  nU R                  R                  " U40 UD6(       d  M'  Sn  U$    U$ )zG
Look for a saved dict whose keys/values match the supplied arguments.
FT)r8  r2  matches)r  r  rq  ds       re   r=  TestHandler.matchesD  sE     A||##A000	  rd   )r2  N)	r^   r_   r`   ra   r  r5  r:  r=  rc   r\   rd   re   rK   rK   3  s    ,	rd   rK   c                   $    \ rS rSrSrS rS rSrg)rL   iO  )rx   r  c                 ~    SnU H4  nX$   nUR                  U5      nU R                  XFU5      (       a  M1  Sn  U$    U$ )a  
Try to match a single dict with the supplied arguments.

Keys whose values are strings and which are in self._partial_matches
will be checked for partial (i.e. substring) matches. You can extend
this scheme to (for example) do regular expression matching, etc.
TF)r   match_value)r  r>  r  rq  r  r  dvs          re   r=  Matcher.matchesS  sN     A	AqB##A1--  rd   c                     [        U5      [        U5      :w  a  SnU$ [        U5      [        Ld  XR                  ;  a  X2:H  nU$ UR                  U5      S:  nU$ )zD
Try to match a single stored value (dv) with a supplied value (v).
Fr   )r/  r   _partial_matchesfind)r  r  rC  r  rq  s        re   rB  Matcher.match_valued  s_     7d2hF
 	 "XS A-B-B$BgF  WWQZ1_Frd   r\   N)r^   r_   r`   ra   rF  r=  rB  rc   r\   rd   re   rL   rL   O  s    )"
rd   rL   c                      [         b  [         $ [        S-   n  [        R                  " [        U 5        Sn[        R                  " U 5        Uq U$ ! [
        [        [        4 a    Sn Uq U$ f = f)NrM   TF)_can_symlinkr&   r   symlinkr  r   NotImplementedErrorr   )symlink_pathcans     re   rM   rM   r  sr    M)L 


6<( 			,LJ (.9  LJs   A A,+A,c                 d    [        5       nSnU(       a  U $ [        R                  " U5      " U 5      $ )z8Skip decorator for tests that require functional symlinkz*Requires functional symlink implementation)rM   rt   r   rn  okrx   s      re   rN   rN     s)    	B
6C438==-d33rd   c                     [         b  [         $ [        [        S5      (       d  Sn U q U $ [        R                  " 5       u  p [        [        S5       n [        R                  " USS5        [        R                  " UR                  5       SS5        [        R                  " 5       n[        R                  " SU5      nUS L =(       d    [        UR                  S5      5      S:  n S S S 5        [!        [        5        [!        U5        W q U $ ! [         a    Sn  N4f = f! , (       d  f       N>= f! [!        [        5        [!        U5        f = f)	NsetxattrFr^  s	   user.testrd   z2.6.(\d{1,2})r   '   )
_can_xattrr1  r   tempfilemkstempr
   r&   rS  r_  r  r  r  r  r   r  r   r   )rN  tmp_fptmp_namefpkernel_versionr  s         re   	can_xattrr\    s   2z""& JJ% $++-	fd#r
  KKc:KK		\3?%-%5%5%7N.AAt)<s1771:"'<C $ 6N8JJ   C  $# 6N8sC   D. DBD%D. DDDD
D+'D. .E
c                 d    [        5       nSnU(       a  U $ [        R                  " U5      " U 5      $ )zDSkip decorator for tests that require functional extended attributesz(no non-broken extended attribute support)r\  rt   r   rP  s      re   rO   rO     s)    	B
4C438==-d33rd   c               #      #    SSK n U R                  R                  nSnUR                  U5      nUR                  X2-  5         Sv   UR                  U5        g! UR                  U5        f = f7f)z;Disable Windows Error Reporting dialogs using SetErrorMode.r   Nr   )r   r   kernel32SetErrorMode)r   k32SEM_NOGPFAULTERRORBOXold_error_modes       re   rY   rY     se      	mm$$ $))*?@?@	-^,C^,s   AA0A A0A--A0c               #      #    S v   g 7fr   r\   r\   rd   re   rY   rY     s     s   c                    ^^^^ [        TT5        Sm TR                  T   mSmUUUU4S jnU R	                  U5        [        TTU5        g! [        [        4 a    [        TTS5      m NGf = f)zOverride 'object_to_patch'.'attr_name' with 'new_value'.

Also, add a cleanup procedure to 'test_instance' to restore
'object_to_patch' value for 'attr_name'.
The 'attr_name' should be a valid attribute for 'object_to_patch'.

FTNc                  H   > T (       a  [        TTT5        g [        TT5        g r   )r:  r!  )attr_is_local	attr_nameobject_to_patch	old_values   re   cleanuppatch.<locals>.cleanup  s    OY	:OY/rd   )r   r9  r   r   
addCleanupr:  )test_instanceri  rh  	new_valuerk  rg  rj  s    ``  @@re   patchrp    s~     OY' M#,,Y7	 0 0 W% OY	2 H% >OY=	>s   A A-,A-)T)F)r\   r\   Fr   )tempcwdFN)g      >@r\   rq  )rb   
__future__r   r   r   r   futurer   future.builtinsr   r	   r
   r   r   r   
contextlibr   r  rF  r$  r{   r   r  shutilrl   rt   r1  	unittest2rr   r  r  r   r   rs   	distutilsr  logging.handlersr/  r\  rV  r  r  	threadingthreadmultiprocessing.processmultiprocessingzlibgzipbz2lzma__all__	Exceptionr   r   ru   r   contextmanagerrp   r   r   r   rT   rP   rG   r   r   r   r  rS   r  r   r   r   r   r~   r   r   r   r   r   r   r   r   ctypes.wintypesr   r   r   r  r   r    r!   r'   HOSTv6r.  r0  r"   r#   r=  r$   rR   SOCK_MAX_SIZE
skipUnlessrQ   rW   rX   r%   rv   r&   r  r  rA  r(   r)   r:   rz  r*   r+   r,   ra  r-   r.   objectr  r  r/   r0   collections.abccollectionsabcMutableMappingmybaseUserDict	DictMixinr1   r  r2   r0  r  r6   r   r  r7   r8   r;   r>  r3   r5   r4   rH  rN  rU  r^  r_  rd  rb  re  rj  ri  rr  r9   rU   r  r  r  _4Gr  r  r<   r  r=   r>   r?   r  r  rE   r  r  rF   r  r  r  r  r@   rA   r	  r  rB   rC   r  rD   rI   rH   r)  r,  r0  r1  rK   rL   rJ  rM   rN   rU  r\  rO   rY   rp  r\   rd   re   <module>r     s  
: :  < <    	  
 	    x     	  $    yy!!++",5I 5 X&&   
.%1h 

  * <<5!!4B&$
! iiGXXFmmG <<5!!/,C
"$6:8: 	 #NNV5G5G <|  #J  ! $ % ##D/:""37##D/:LL##F+	 77fFF 
		fbiik	2z 99;$ $N 2w  ! 

3*1Z)v ).))X + +.2& 2@ 	99__++FF2#& 2#j*F *2N N8 WEOO<%fll%:J:JK &we6F6FG  A. A.H 	/ 	/%%$   	2 	
3"##WnGFS=34   (HF 
Sj#g#g*%f %<+Z$f O+!I *
(N6#F	"(  4  45'""33 8f D 4 
64 <<5!!- -   3<  $##$  GI
  O
  D
  D
  
C
  Ds   4U 	U- #U- -U> 2V 7V <V+ V: U*)U*-
U;:U;>V
	V
VVV('V(+V76V7:WW