
    <e\                        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Zd dlmZ d dlmZ d dlmZ d dlmZ e j        e j        k    Z eed          Zej                            d          rd	Znd
Z G d dej                  Z G d dej                  Z G d de          Z G d de          Z  G d de          Z! G d de          Z" G d de          Z#ej$        d             Z%d Z& G d d          Z' G d de'e          Z( G d d e          Z) G d! d"e          Z* G d# d$e          Z+ G d% d&e'e          Z, G d' d(e          Z- G d) d*e          Z. G d+ d,e          Z/e j0        e j1        ur G d- d.e          Z2 G d/ d0          Z3 G d1 d2e          Z4e5d3k    r ej6                     dS dS )4    N)mock)support)	os_helper)script_helper)warnings_helperspawnlopenbsd0   d   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )TestLowLevelInternalsc                    |                      t          t          j        d                     |                      t          t          j        d                     |                      t          t          j        d                      d S N     )assertIsstrtempfile_infer_return_typebytesselfs    )/usr/lib/python3.11/test/test_tempfile.pytest_infer_return_type_singlesz4TestLowLevelInternals.test_infer_return_type_singles&   se    c86r::;;;eX8==>>>c86t<<=====r   c                    |                      t          t          j        dd                     |                      t          t          j        dd                     |                     t                    5  t          j        dd           d d d            n# 1 swxY w Y   |                     t                    5  t          j        dd           d d d            d S # 1 swxY w Y   d S r   r   r   r   r   r   assertRaises	TypeErrorr   s    r    test_infer_return_type_multiplesz6TestLowLevelInternals.test_infer_return_type_multiples+   sK   c86r2>>???eX8cBBCCCy)) 	1 	1'C000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1y)) 	1 	1'R000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s$   7BB B>C!!C%(C%c                    |                      t          t          j        d d                     |                      t          t          j        dd                      |                      t          t          j        d d                      |                      t          t          j        dd                      |                      t          t          j        d d                     |                     t                    5  t          j        dd d           d d d            n# 1 swxY w Y   |                     t                    5  t          j        dd d           d d d            d S # 1 swxY w Y   d S r   r   r   s    r   )test_infer_return_type_multiples_and_nonez?TestLowLevelInternals.test_infer_return_type_multiples_and_none3   s   c86tR@@AAAc86r4@@AAAc86tTBBCCCeX8dCCDDDeX8sCCDDDy)) 	7 	7'D#666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7y)) 	7 	7'T2666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s$   D$$D(+D(	E--E14E1c                     |                      t          t          j        t	          j        d                               d S )N/)r   r   r   r   pathlibPathr   s    r   test_infer_return_type_pathlibz4TestLowLevelInternals.test_infer_return_type_pathlib>   s1    c86w|C7H7HIIJJJJJr   c           	          G d d          }|                      t          t          j         |d                               |                      t          t          j         |d                               |                      t          t          j        d |d                               |                      t          t          j        d |d                               |                      t          t          j        d  |d                               |                      t          t          j        d  |d                               |                     t                    5  t          j        d |d                     d d d            n# 1 swxY w Y   |                     t                    5  t          j        d |d                     d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Zd Zd ZdS )CTestLowLevelInternals.test_infer_return_type_pathlike.<locals>.Pathc                     || _         d S Npath)r   r-   s     r   __init__zLTestLowLevelInternals.test_infer_return_type_pathlike.<locals>.Path.__init__C   s     			r   c                     | j         S r+   r,   r   s    r   
__fspath__zNTestLowLevelInternals.test_infer_return_type_pathlike.<locals>.Path.__fspath__F   s
    y r   N)__name__
__module____qualname__r.   r0    r   r   r%   r)   B   s2        ! ! !! ! ! ! !r   r%   r#      /r   r   r   )r   r%   s     r   test_infer_return_type_pathlikez5TestLowLevelInternals.test_infer_return_type_pathlikeA   s5   	! 	! 	! 	! 	! 	! 	! 	! 	c86ttCyyAABBBeX8dDDEEEc86r4488DDEEEeX8dd3iiHHIIIeX8ttCyyIIJJJc86tTT"XXFFGGGy)) 	7 	7'DDII666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7y)) 	7 	7'TT"XX666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s$   0FF"F G,,G03G0N)r1   r2   r3   r   r   r!   r&   r6   r4   r   r   r   r   %   sb        > > >
1 1 1	7 	7 	7K K K7 7 7 7 7r   r   c                   Z    e Zd Z ej        d          Z ej        d          Zd Zd ZdS )BaseTestCasez^[a-z0-9_-]{8}$s   ^[a-z0-9_-]{8}$c                     |                      t          j                               t          j        dt
          dt                     d S )Nignoremktemp)categorymessagemodule)enterContextr   check_warningswarningsfilterwarningsRuntimeWarningr1   r   s    r   setUpzBaseTestCase.setUp\   sR    /8::;;;>(0	C 	C 	C 	C 	C 	Cr   c                 F   t           j                            |          \  }}|d t          |                   }|t          |          t          |          z
  d          }|`|                     t          |          t          |          t          u st          |t           j                  rt          nt          d           |F|                     t          |          t          |          t          u rt          nt          d           |F|                     t          |          t          |          t          u rt          nt          d           |||fdk    r)|                     t          |          t          d           | 
                    t           j                            |          t           j                            |          d|d|           | 
                    ||d|d|           | 
                    ||d|d|           |t          |          t          |          t          |          z
           }t          |t                    r| j        n| j        }	|                     |	                    |          d|d	|	j                   d S )
Nzunexpected return typeNNNzdefault return type must be strzfile z not in directory z does not begin with z does not end with zrandom characters z do not match )osr-   splitlenr   typer   
isinstancePathLiker   assertEqualabspath	str_checkb_check
assertTruematchpattern)
r   namedirpresufndirnbasenprensufchecks
             r   	nameCheckzBaseTestCase.nameChecka   s}   d++uis3xxi c%jjS)**+?MMT

99##z#r{'C'C# (   ?MM$t**T#YY#-=-=cc524 4 4?MM$t**T#YY#-=-=cc524 4 4c?000MM$t**c+LMMM 	..0D0D0D:>$$D	F 	F 	Fss=BUUCCH	J 	J 	Jss;@55##F	H 	H 	H c#hhs5zz#c((223",UC"8"8JdlE*** 55%--1	2 	2 	2 	2 	2r   N)	r1   r2   r3   recompilerO   rP   rD   r]   r4   r   r   r8   r8   W   sY        
-..Ibj,--GC C C
"2 "2 "2 "2 "2r   r8   c                       e Zd Zd ZdS )TestExportsc                     t           j        }ddddddddddddddd}g }|D ]'}|d         dk    r||vr|                    |           (|                     t	          |          dk    d|z             d S )N   )NamedTemporaryFileTemporaryFilemkstempmkdtempr;   TMP_MAXgettempprefixgettempprefixb
gettempdirgettempdirbtempdirtemplateSpooledTemporaryFileTemporaryDirectoryr   _zunexpected keys: %s)r   __dict__appendrQ   rI   )r   dictexpectedunexpkeys        r   test_exportszTestExports.test_exports   s      $% %&#$
 
"  	" 	"C1v}}H!4!4S!!!E

a-5	7 	7 	7 	7 	7r   N)r1   r2   r3   rx   r4   r   r   ra   ra      s#        7 7 7 7 7r   ra   c                   b     e Zd Z	  fdZd Zd Zd Z ej                    d             Z	 xZ
S )TestRandomNameSequencec                 x    t          j                    | _        t                                                       d S r+   )r   _RandomNameSequencersuperrD   r   	__class__s    r   rD   zTestRandomNameSequence.setUp   s(    -//r   c                 ^    t          | j                  }|                     |ddd           d S Nr   )nextr}   r]   )r   ss     r   test_get_eight_char_strz.TestRandomNameSequence.test_get_eight_char_str   s-    LLq"b"%%%%%r   c                     i }| j         }t          t                    D ]D}t          |          }|                     |ddd           |                     ||           d||<   Ed S )Nr   rc   )r}   range
TEST_FILESr   r]   assertNotIn)r   rt   r}   ir   s        r   	test_manyz TestRandomNameSequence.test_many   su     Fz"" 	 	AQANN1b"b)))Q%%%DGG		 	r   c                 >    d}| j         }|D ]}|dz  }|dk    r d S d S )Nr   rc      )r}   )r   r   r}   r   s       r   supports_iterz$TestRandomNameSequence.supports_iter   sG     F 	 	AFABww 	 	r   c                    t          j                    \  }}d }	 t          j                    }|svt          j        |           t          j        |t          | j                                      d                     t          j        |           t          j        d           t          | j                  }t          j	        |t          |                                        d          }|rt          j        |d           t          j        |           t          j        |           nE# |rt          j        |d           t          j        |           t          j        |           w xY w|                     ||           d S )Nasciir   )exitcode)rG   pipeforkclosewriter   r}   encode_exitreadrI   decoder   wait_processassertNotEqual)r   read_fdwrite_fdpidparent_valuechild_values         r   test_process_awarenessz-TestRandomNameSequence.test_process_awareness   sb    GII	'))C !!!4<<#6#6w#?#?@@@"""   <<L''3|+<+<==DDWMMK 6$S15555HWHX	  6$S15555HWHXK66666s   CD/ /AE1)r1   r2   r3   rD   r   r   r   r   requires_forkr   __classcell__r   s   @r   rz   rz      s        @    & & &
	 	 	   W7 7 7 7 7 7 7r   rz   c                       e Zd Z	 d Zd ZdS )TestCandidateTempdirListc                     t          j                    }|                     t          |          dk               |D ]}|                     |t
                     d S Nr   )r   _candidate_tempdir_listassertFalserI   assertIsInstancer   )r   candcs      r   test_nonempty_listz+TestCandidateTempdirList.test_nonempty_list   sb     /11Ta((( 	* 	*A!!!S))))	* 	*r   c                 
   t          j                    5 }dD ]:}t          j        |          }|s"t          j                            |          ||<   ;t          j                    }dD ]5}t          j        |          }|st          | 	                    ||           6	 t          j
                    }n## t          t          f$ r t          j        }Y nw xY w| 	                    ||           d d d            d S # 1 swxY w Y   d S )N)TMPDIRTEMPTMP)r   EnvironmentVarGuardrG   getenvr-   rN   r   r   
ValueErrorassertIngetcwdAttributeErrorOSErrorcurdir)r   envenvnamedirnamer   s        r   test_wanted_dirsz)TestCandidateTempdirList.test_wanted_dirs   sS    *,, 	)2 < <)G,, <#%7??7#;#;CL355D2 - -)G,,0j 0gt,,,,$)++"G, $ $ $)$ MM'4(((%	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s6   B	C8B21C82CC8CC88C<?C<N)r1   r2   r3   r   r   r4   r   r   r   r      s5        =* * *) ) ) ) )r   r   c                       e Zd Z	 d ZdS )TestGetDefaultTempdirc           	         t          j                    5 fd}t          j        t           d|          5  t          j                     |                     t          j                  g            d }t          j        t          d|          5  |                     t                    5  t          j                     d d d            n# 1 swxY w Y   |                     t          j                  g            d d d            n# 1 swxY w Y   t          j        t          d|          5  |                     t                    5  t          j                     d d d            n# 1 swxY w Y   |                     t          j                  g            d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nc                  
     gS r+   r4   )our_temp_directorys   r   our_candidate_listzKTestGetDefaultTempdir.test_no_files_left_behind.<locals>.our_candidate_list  s    *++r   r   c                      t                      r+   )r   )argskwargss     r   raise_OSErrorzFTestGetDefaultTempdir.test_no_files_left_behind.<locals>.raise_OSError  s    !))Or   openr   )
r   rp   r   	swap_attr_get_default_tempdirrM   rG   listdirr   FileNotFoundError)r   r   r   r   s      @r   test_no_files_left_behindz/TestGetDefaultTempdir.test_no_files_left_behind  s   (** 	I.@, , , , , "8-F#57 7 I I -///  ,>!?!?DDD$ $ $ &r6=AA I I**+<== 8 8 57778 8 8 8 8 8 8 8 8 8 8 8 8 8 8$$RZ0B%C%CRHHH	I I I I I I I I I I I I I I I &r7MBB I I**+<== 8 8 57778 8 8 8 8 8 8 8 8 8 8 8 8 8 8$$RZ0B%C%CRHHH	I I I I I I I I I I I I I I II I I I I I I I I I I I I I I	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	Is   !GAGD
+C	?D
CD
C+D
>G
DGDG0F*E+	F*+E//F*2E/3+F*G*F..G1F.2G5GG	GG		GG GN)r1   r2   r3   r   r4   r   r   r   r     s+        &I I I I Ir   r   c                       e Zd Z	 d Zd ZdS )TestGetCandidateNamesc                 l    t          j                    }|                     |t           j                   d S r+   )r   _get_candidate_namesr   r|   )r   objs     r   test_retvalz!TestGetCandidateNames.test_retval0  s/    +--c8#?@@@@@r   c                     t          j                    }t          j                    }|                     ||u            d S r+   )r   r   rQ   )r   abs      r   test_same_thingz%TestGetCandidateNames.test_same_thing5  s:    )++)++Qr   N)r1   r2   r3   r   r   r4   r   r   r   r   -  s8        :A A A
         r   r   c               #      K   t          j                    } 	 t          j        t           d|           5  d V  d d d            n# 1 swxY w Y   t	          j        |            d S # t	          j        |            w xY w)Nrm   )r   rg   r   r   r   rmtreerU   s    r   _inside_empty_temp_dirr   =  s      



CxC88 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 		s-   A$ AA$ AA$ 
AA$ $A:c                  @     t          j        t          d fd          S )Nr   c                  "    t                     S r+   )iternamess   r   <lambda>z'_mock_candidate_names.<locals>.<lambda>J  s    T%[[ r   )r   r   r   r   s   `r   _mock_candidate_namesr   G  s)    X300002 2 2r   c                   X    e Zd Z ej        ej        d          d             Zd Zd Z	dS )TestBadTempdirz$Emscripten cannot remove write bits.c                 (   t                      5  t          j        t          j                  j        x}}|t          j        t          j        z  t          j        z   z  }t          j	        t          j        |           	 t          j
        t          j        t          j                  r|                     d           |                     t                    5  |                                  d d d            n# 1 swxY w Y   |                     t          j        t          j                  g            t          j	        t          j        |           n$# t          j	        t          j        |           w xY w	 d d d            d S # 1 swxY w Y   d S )Nz!can't set the directory read-only)r   rG   statr   rm   st_modeS_IWUSRS_IWGRPS_IWOTHchmodaccessW_OKskipTestr   PermissionError	make_temprM   r   )r   oldmodemodes      r   test_read_only_directoryz'TestBadTempdir.test_read_only_directoryO  s    $%% 	4 	4WX%566>>GddlT\1DL@AADHX%t,,,49X-rw77 GMM"EFFF&&77 % %NN$$$% % % % % % % % % % % % % % %  H,<!=!=rBBB)73333)733333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4sO   A/F?AEC8,E8C<	<E?C<	 5E5 F!E66FFFc                    t                      5  t          j                            t          j        d          }t          j        t          d|          5  |                     t                    5  | 
                                 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nnonexistentrm   )r   rG   r-   joinr   rm   r   r   r   r   r   r   rm   s     r   test_nonexisting_directoryz)TestBadTempdir.test_nonexisting_directory`  sn   #%% 	% 	%gll8#3]CCG"8Y@@ % %&&'899 % %NN$$$% % % % % % % % % % % % % % %% % % % % % % % % % % % % % %	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%sZ   AC B(0BB(BB(BB(C (B,	,C /B,	0C  CCc                    t                      5  t          j                            t          j        d          }t          |d                                           t          j	        t          d|          5  | 
                    t          t          f          5  |                                  d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nfilewbrm   )r   rG   r-   r   r   rm   r   r   r   r   r   NotADirectoryErrorr   r   r   s     r   test_non_directoryz!TestBadTempdir.test_non_directoryg  s   #%% 	% 	%gll8#3V<<G$%%'''"8Y@@ % %&&(:<M'NOO % %NN$$$% % % % % % % % % % % % % % %% % % % % % % % % % % % % % %	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%sZ   A(C)7"CB:.C:B>>CB>CC)C	C)C	C))C-0C-N)
r1   r2   r3   unittestskipIfr   is_emscriptenr   r   r   r4   r   r   r   r   M  se        X_E 4 4 4% % %% % % % %r   r   c                      e Zd Z	  G d d          ZddZd Zd Zd Zd	 Ze	j
        d
             Z ej        ed           ej                    d                         Z ej        ed          d             Zd Zd Zd ZdS )TestMkstempInnerc                   X    e Zd Zej        Zej        Zej	        Z
ej        Zd Zd Zd ZdS )TestMkstempInner.mkstempedc                     |r| j         }n| j        }t          j        |||          }t          j        |||||          \  | _        | _        d S r+   )_bflags_tflagsr   r   _mkstemp_innerfdrT   )r   rU   rV   rW   binflagsoutput_types          r   r.   z#TestMkstempInner.mkstemped.__init__y  sS     )DLEE LE"5c3DDK#+#:3S%Q\#]#] TWdiiir   c                 :    t          j        | j        |           d S r+   )rG   r   r
  )r   r   s     r   r   z TestMkstempInner.mkstemped.write  s    HTWc"""""r   c                 n    |                      | j                   |                     | j                   d S r+   )_closer
  _unlinkrT   r   s    r   __del__z"TestMkstempInner.mkstemped.__del__  s0    KK   LL#####r   N)r1   r2   r3   r   _bin_openflagsr  _text_openflagsr  rG   r   r  unlinkr  r.   r   r  r4   r   r   	mkstempedr  s  sb        )*)	^ 	^ 	^	# 	# 	#	$ 	$ 	$ 	$ 	$r   r  Nrc   c                 0   t          j        |||          }|0|t          u rt          j                    }nt          j                    }|
 |            }|
 |            }|                     ||||          }|                     |j        |||           |S r+   )r   r   r   rk   rl   r  r]   rT   )r   rU   rV   rW   r  r  r   s          r   	do_createzTestMkstempInner.do_create  s    1#sC@@;c!!)++*,,;+--C;+--C~~c3S11ty#sC000r   c                    |                                                      d           |                      d                              d           |                      d                              d           |                      dd                              d           |                      dd                              d           d S )	N   blatr   rV   r   rW   rV   rW   aa.txt)r  r   r   s    r   
test_basiczTestMkstempInner.test_basic  s    w'''3%%g...3%%g...3C((..w7774V,,227;;;;;r   c                     t          j                    }|                     |d                              d           |                     |d                              d           |                     |d                              d           |                     |dd                              d           |                     |dd	                              d           |                     t
                    5  |                     d
d                              d           d d d            n# 1 swxY w Y   |                     t
                    5  |                     |d
                              d           d d d            n# 1 swxY w Y   |                     t
                    5  |                     |dd
                              d           d d d            d S # 1 swxY w Y   d S )Nr   rU   rW   r     arU   rV      brU   rV   rW      aa   .txtr   )r   rl   r  r   r   r   )r   dir_bs     r   test_basic_with_bytes_namesz,TestMkstempInner.test_basic_with_bytes_names  s    $&&5c**009995d++11':::5d++11':::5d55;;GDDD5e99??HHHy)) 	; 	;NNrsN++11':::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;y)) 	= 	=NNu"N--33G<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=y)) 	F 	FNNu#2N66<<WEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs6   +D99D= D=+FFF:,G33G7:G7c                     t          t          t                              }|D ]}|                     d          ||<   d S Nr  r  )listr   r   r  r   extantr   s      r   test_basic_manyz TestMkstempInner.test_basic_many  sI    eJ''(( 	1 	1A400F1II	1 	1r   c                    t          j                    }	 |                     |                              d           |                     t	          j        |                                        d           t          j                     t          j	        |           d S # t          j                     t          j	        |           w xY wNr   r  )
r   rg   r  r   r$   r%   r   
gc_collectrG   rmdirr   rU   s     r   test_choose_directoryz&TestMkstempInner.test_choose_directory  s      	NNsN##))'222NNw|C00N1177@@@   HSMMMMM    HSMMMMs   A$B" ")Cc                     |                                  }t          j        t          j        |j                  j                  }d}t          j        dk    r
|dz	  }|dz  }|                     ||           d S )N  win32   I   )	r  r   S_IMODErG   rT   r   sysplatformrM   )r   r   r   ru   users        r   test_file_modezTestMkstempInner.test_file_mode  st     ~~|BGDI..677<7"" q=Dz*Hx(((((r   zos.spawnl not availablec                    t           j        rd}nd}|                                 }|                     t	          j        |j                  d           d|j        z  }	 t          }n"# t          $ r t          j
        d         }Y nw xY wt          j                            t          j                            t          j                            |                    d          }t          j        dk    rdt          j        z  }d|z  }nt          j        }t	          j        t          j        t          j        ||||          }|                     |dk     d	| z             |                     |dk    d
|z             d S )NvqFz%dr   ztf_inherit_check.pyr9  z"%s"z$child process caught fatal signal %dz child process reports failure %d)r   verboser  rM   rG   get_inheritabler
  __file__	NameErrorr=  argvr-   r   r   rN   r>  
executabler   P_WAITr   )r   rB  r   r
  metester	decoratedretvals           r   test_noinheritzTestMkstempInner.test_noinherit  s`   
 ? 	AAA~~+DG44e<<<DG^	BB 	 	 	!BBB	 bgoobgoob.A.ABB35 5 <7""/If_FFI29cniBOO!:fWD	F 	F 	F!%G%NOOOOOs   A& &BBztext mode not availablec                 ,   |                      d          }|                    d           |                    d           t          j        |j        dt          j                   |                     t          j        |j        d          d           d S )Nr   )r  s   blats   extra
r   r  )r  r   rG   lseekr
  SEEK_SETrM   r   r   fs     r   test_textmodezTestMkstempInner.test_textmode  s}    
 NNqN!!		

q"+&&&r**G44444r   c                     t          j        t          j                    t          j                    dt           j        t
                    S r   )r   r	  rk   ri   r  r   r   s    r   r   zTestMkstempInner.make_temp   s:    &x':'<'<'/'='?'?')'/'>'*	, , 	,r   c                    t                      5  t          ddd          5  |                                 \  }}t          j        |           |                     |                    d                     |                                 \  }}t          j        |           |                     |                    d                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S Naaabbb)r   r   r   rG   r   rQ   endswith)r   fd1name1fd2name2s        r   !test_collision_with_existing_filez2TestMkstempInner.test_collision_with_existing_file  sW    $%% 	3 	3"5%77	3 	3>>++LS%HSMMMOOENN511222>>++LS%HSMMMOOENN511222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s5   C,B'CC,C	C,C	C,,C03C0c                    t                      5  t          ddd          5  t          j                    }|                     |                    d                     |                                 \  }}t          j        |           |                     |                    d                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S rX  )	r   r   r   rg   rQ   r[  r   rG   r   )r   rU   r
  rT   s       r   &test_collision_with_existing_directoryz7TestMkstempInner.test_collision_with_existing_directory  sE    $%% 	2 	2"5%77	2 	2"$$COOCLL//000))JRHRLLLOODMM%00111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s5   CBB<0C<C 	 CC 	CCC)NNNrc   )r1   r2   r3   r  r  r   r*  r0  r6  r   skip_unless_working_chmodr@  r   
skipUnless
has_spawnlr   requires_subprocessrO  has_textmoderU  r   r`  rb  r4   r   r   r  r  p  sR       4$ $ $ $ $ $ $ $(    < < <F F F"1 1 1   () ) )() X%>?? W ""#P #P #" @?#PJ X'@AA5 5 BA5, , ,3 3 3
2 
2 
2 
2 
2r   r  c                       e Zd Z	 d Zd ZdS )TestGetTempPrefixc                 J   t          j                    }|                     |t                     |                     t          |          d           t          j                    }|                     |t                     |                     t          |          d           d S r   )r   ri   r   r   assertGreaterrI   rj   r   )r   ppbs      r   test_sane_templatez$TestGetTempPrefix.test_sane_template$  s    "$$a%%%3q661%%%$&&b%(((3r77A&&&&&r   c                    t          j                    dz   }t          j        d          }	 t          j                            ||          }t          j        |t          j        t          j        z            }t          j	        |           t          j
        |           t          j        |           d S # t          j        |           w xY w)Nz
xxxxxx.xxxr   prefix)r   ri   rg   rG   r-   r   r   O_RDWRO_CREATr   r  r4  )r   rl  dr
  s       r   test_usable_templatez&TestGetTempPrefix.test_usable_template0  s     "$$|3B'''	Q""ABI
233BHRLLLIaLLLHQKKKKKBHQKKKKs   A4B7 7CN)r1   r2   r3   rn  ru  r4   r   r   ri  ri  !  s5        
' 
' 
'    r   ri  c                   (    e Zd Z	 d Zd Zd Zd ZdS )TestGetTempDirc                 P   t          j                    t          j                    fD ]~}|                     t          j                            |          p|t          j        k    d|z             |                     t          j                            |          d|z             d S )Nz%r is not an absolute pathz%r is not a directory)	r   rk   rl   rQ   rG   r-   isabsr   isdirr   rt  s     r   test_directory_existsz$TestGetTempDir.test_directory_existsD  s     %'')=)?)?@ 	9 	9AOOBGMM!,,>RY81<> > >OOBGMM!,,3a79 9 9 9	9 	9r   c                     t          j                    5 }|                    d           d d d            d S # 1 swxY w Y   d S )Nr  )r   rd   r   )r   r   s     r   test_directory_writablez&TestGetTempDir.test_directory_writableM  s     (** 	 dJJw	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   7;;c                 V   t          j                    }t          j                    }t          j                    }|                     ||u            |                     t          |          t          |                     |                     |t          j        |                     d S r+   )	r   rk   rl   rQ   r   rJ   rM   rG   fsdecode)r   r   r   r   s       r   r   zTestGetTempDir.test_same_thingV  s    !!!! ""QDGGT!WW---BKNN+++++r   c                    t          j        d          }t           j        d c}t           _        	 t          j                    5 }||d<   |                     t          j                    |           d d d            n# 1 swxY w Y   |t           _        t          j        |           d S # |t           _        t          j        |           w xY w)Nz-Tempr   )r   rg   rm   r   r   rM   rk   r4  )r   case_sensitive_tempdir_tempdirr   s       r   test_case_sensitivez"TestGetTempDir.test_case_sensitive`  s	    "*!1'!:!:%-%5t"("	4.00 PC 6H  !4!6!68NOOOP P P P P P P P P P P P P P P
  (HO233333  (HO23333s/   B( -A;/B( ;A??B( A?B( ("C
N)r1   r2   r3   r|  r~  r   r  r4   r   r   rw  rw  A  sS        9 9 9     , , ,4 4 4 4 4r   rw  c                   0    e Zd Z	 ddZd Zd Zd Zd ZdS )TestMkstempNc           	         t          j        |||          }|0|t          u rt          j                    }nt          j                    }|
 |            }|
 |            }t          j        |||          \  }}t          j                            |          \  }}t          j        	                    |          }	| 
                    |	|d|	d|d           	 |                     ||||           t          j        |           t          j        |           d S # t          j        |           t          j        |           w xY w)NrU   rq  suffixzDirectory 'z' incorrectly returned as '')r   r   r   rk   rl   rf   rG   r-   rH   rN   rM   r]   r   r  )
r   rU   rV   rW   r  r
  rT   rX   rY   adirs
             r   r  zTestMkstemp.do_creater  s7   1#sC@@;c!!)++*,,;+--C;+--C%#c#FFF
Td++uws##tt=ATT444H	J 	J 	J	NN4c3///HRLLLIdOOOOO HRLLLIdOOOOs   D *Ec                    |                                   |                      d           |                      d           |                      dd           |                      dd           |                      d	           d S )
Nr   r  r   r  r  r  r  .r   r  r   s    r   r   zTestMkstemp.test_basic  s    333C(((4V,,,3r   c                     t          j                    }|                     |d           |                     |d           |                     |d           |                     |dd           |                     |dd           |                     d	
           |                     t                    5  |                     ddd           d d d            n# 1 swxY w Y   |                     t                    5  |                     d	dd           d d d            n# 1 swxY w Y   |                     t                    5  |                     d	dd           d d d            d S # 1 swxY w Y   d S )Nr   r"  r#  r$  r%  r&  r'  r(     .r   r  r  r  )r   rl   r  r   r   r{  s     r   r*  z'TestMkstemp.test_basic_with_bytes_names  s*     ""1#&&&1$'''1$'''1$D1111%W5554   y)) 	< 	<NNs7N;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<y)) 	< 	<NNt7N;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<y)) 	< 	<NNtFN;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s6   9CC"%C"D((D,/D,E33E7:E7c                    t          j                    }	 |                     |           |                     t          j        |                     t          j        |           d S # t          j        |           w xY wNr   )r   rg   r  r$   r%   rG   r4  r5  s     r   r6  z!TestMkstemp.test_choose_directory  sj      	NNsN###NNw|C00N111HSMMMMMBHSMMMMs   >A) )A?c                    t           j        }|                     t           j        t          t	          d           f           	 t          j                    \  }}t          j        |           t          j        |           |                     |t                     t          j	                    t           _        |                     t           j        t                     |                     t          j                    t                     |                     t          j	                    t                     t          j                    \  }}t          j        |           t          j        |           |                     |t                     t          j        d          \  }}t          j        |           t          j        |           |                     |t                     t          j        d          \  }}t          j        |           t          j        |           |                     |t                     t          j        t          j                              \  }}t          j        |           t          j        |           |                     |t                     |t           _        d S # |t           _        w xY w)Nr  r  z
test-temp-rp  r   )r   rm   r   r   rJ   rf   rG   r   r  rl   r   rk   )r   orig_tempdirr
  r-   s       r   .test_for_tempdir_is_bytes_issue40701_api_wartsz:TestMkstemp.test_for_tempdir_is_bytes_issue40701_api_warts  s   'h.d4jj0ABBB	,'))HBHRLLLIdOOO!!$,,,'355H!!("2E:::!!("5"7"7===!!("6"8"8%@@@'))HBHRLLLIdOOO!!$...'v666HBHRLLLIdOOO!!$,,,'|<<<HBHRLLLIdOOO!!$,,,'H,?,A,ABBBHBHRLLLIdOOO!!$,,,+H|H++++s   I.J> >KrF   )r1   r2   r3   r  r   r*  r6  r  r4   r   r   r  r  o  sg           .     < < <$  , , , , ,r   r  c                   h    e Zd Z	 d ZddZd Zd Zd Zd Ze	j
        d             Zd	 Zd
 Zd ZdS )TestMkdtempc                 (    t          j                    S r+   )r   rg   r   s    r   r   zTestMkdtemp.make_temp  s    !!!r   Nc                 Z   t          j        |||          }|0|t          u rt          j                    }nt          j                    }|
 |            }|
 |            }t          j        |||          }	 |                     ||||           |S #  t          j        |            xY w)Nr  )	r   r   r   rk   rl   rg   r]   rG   r4  )r   rU   rV   rW   r  rT   s         r   r  zTestMkdtemp.do_create  s    1#sC@@;c!!)++*,,;+--C;+--CCC@@@	NN4c3///K	HTNNNs   9B B*c                    t          j        |                                            t          j        |                     d                     t          j        |                     d                     t          j        |                     dd                     t          j        |                     dd                     d S Nr   r  r   r  r  r  r  )rG   r4  r  r   s    r   r   zTestMkdtemp.test_basic  s    
!!"""
C(()))
C(()))
CS11222
Df5566666r   c                    t          j                    }t          j        |                     |                     t          j        |                     |d                     t          j        |                     |d                     t          j        |                     |dd                     t          j        |                     |dd                     |                     t                    5  t          j        |                     |d	d                     d d d            n# 1 swxY w Y   |                     t                    5  t          j        |                     |dd
                     d d d            n# 1 swxY w Y   |                     t                    5  t          j        |                     ddd                     d d d            d S # 1 swxY w Y   d S )Nr   r#  r$  r%  r"  r&  r'  r(  r  r  r   )r   rl   rG   r4  r  r   r   r{  s     r   r*  z'TestMkdtemp.test_basic_with_bytes_names  s    ""
A&&'''
A400111
A400111
A4T::;;;
A5g>>???y)) 	C 	CHT^^t^AABBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cy)) 	C 	CHT^^u&^AABBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cy)) 	E 	EHT^^7^CCDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es6   <+D33D7:D7+FFF4+G,,G03G0c                 J   t          t          t                              }	 |D ]}|                     d          ||<   	 |D ]+}t	          |t
                    rt          j        |           ,d S # |D ]+}t	          |t
                    rt          j        |           ,w xY wr,  )r-  r   r   r  rK   r   rG   r4  r.  s      r   r0  zTestMkdtemp.test_basic_many  s    eJ''((	  5 5 NNtN44q		5     a%%  HQKKK   V    a%%  HQKKK s   A2 20B"c                 L   t          j                    }	 t          j        |                     |                     t          j        |                     t          j        |                               t          j        |           d S # t          j        |           w xY wr  )r   rg   rG   r4  r  r$   r%   r5  s     r   r6  z!TestMkdtemp.test_choose_directory	  s~      	HT^^^,,---HT^^S(9(9^::;;;HSMMMMMBHSMMMMs   A"B B#c                 N   |                                  }	 t          j        t          j        |          j                  }|dz  }d}t
          j        dk    r
|dz	  }|dz  }|                     ||           t          j        |           d S # t          j        |           w xY w)Ni  i  r9  r:  r;  )	r  r   r<  rG   r   r=  r>  rM   r4  )r   rU   r   ru   r?  s        r   	test_modezTestMkdtemp.test_mode  s     nn	< 455DEMDH|w&&  1}:.T8,,,HSMMMMMBHSMMMMs   A"B B$c                    t                      5  t          ddd          5  t          j        d          }|                                 |                     |j                            d                     t          j                    }|                     |                    d                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrY  rZ  F)delete)	r   r   r   rd   r   rQ   rT   r[  rg   )r   r   rU   s      r   r`  z-TestMkdtemp.test_collision_with_existing_file$  sI    $%% 	1 	1"5%77	1 	1.e<<<DJJLLLOODI..u55666"$$COOCLL//000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s5   CBB?3C?C	CC	CCCc                    t                      5  t          ddd          5  t          j                    }|                     |                    d                     t          j                    }|                     |                    d                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S rX  )r   r   r   rg   rQ   r[  )r   dir1dir2s      r   rb  z2TestMkdtemp.test_collision_with_existing_directory/  s3    $%% 	2 	2"5%77	2 	2#%%DOODMM%00111#%%DOODMM%00111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s5   B<A7B$B<$B(	(B<+B(	,B<<C C c                    t           j        }|                     t           j        t          t	          d           f           	 t          j                    }t          j        |           |                     |t                     t          j                    t           _        |                     t           j        t                     |                     t          j
                    t                     |                     t          j                    t                     t          j                    }t          j        |           |                     |t                     t          j        d          }t          j        |           |                     |t                     t          j        d          }t          j        |           |                     |t                     t          j        t          j
                              }t          j        |           |                     |t                     |t           _        d S # |t           _        w xY w)Nz-dirr  ztest-mkdtemp-rp  r   )r   rm   r   r   rJ   rg   rG   r4  rl   r   rk   )r   r  r-   s      r   r  z:TestMkdtemp.test_for_tempdir_is_bytes_issue40701_api_warts9  s   'h.d4jj0ABBB	,#%%DHTNNN!!$,,,'355H!!("2E:::!!("5"7"7===!!("6"8"8%@@@#%%DHTNNN!!$...#6222DHTNNN!!$,,,#?;;;DHTNNN!!$,,,#(;(=(=>>>DHTNNN!!$,,,+H|H++++s   G;I IrF   )r1   r2   r3   r   r  r   r*  r0  r6  r   rc  r  r`  rb  r  r4   r   r   r  r    s        " " "   (7 7 7E E E	  	  	    (  )("	1 	1 	12 2 2, , , , ,r   r  c                   X     e Zd Z	  fdZ fdZ G d d          Zd	dZd Zd Z xZ	S )

TestMktempc                 x    t          j                    | _        t                                                       d S r+   )r   rg   rU   r~   rD   r   s    r   rD   zTestMktemp.setUpY  s(    #%%r   c                     | j         r t          j        | j                    d | _         t                                                       d S r+   )rU   rG   r4  r~   tearDownr   s    r   r  zTestMktemp.tearDown]  sB    8 	HTXDHr   c                   6    e Zd Zej        Zej        Zd Z	d Z
dS )TestMktemp.mktempedc                     t          j        |||          | _        t          j        t          j        | j        | j        d                     d S )Nr  r8  )r   r;   rT   rG   r   r   r  )r   rU   rV   rW   s       r   r.   zTestMktemp.mktemped.__init__g  sD     CCHHHDI HRWTYe<<=====r   c                 :    |                      | j                   d S r+   )r  rT   r   s    r   r  zTestMktemp.mktemped.__del__m  s    LL#####r   N)r1   r2   r3   rG   r  r  r   r  r  r.   r  r4   r   r   mktempedr  c  sA        ))	> 	> 	>	$ 	$ 	$ 	$ 	$r   r  r   c                     |                      | j        ||          }|                     |j        | j        ||           |S r+   )r  rU   r]   rT   )r   rV   rW   r   s       r   r  zTestMktemp.do_createp  s:    }}TXsC00ty$(C555r   c                     |                                   |                      d           |                      d           |                      dd           |                      dd           d S r  r  r   s    r   r   zTestMktemp.test_basicv  l    333C(((4V,,,,,r   c                     t          t          t                              }|D ]}|                     d          ||<   ~t	          j                     d S r,  )r-  r   r   r  r   r3  r.  s      r   r   zTestMktemp.test_many~  sW    eJ''(( 	1 	1A400F1IIr   )r   r   )
r1   r2   r3   rD   r  r  r  r   r   r   r   s   @r   r  r  T  s                $ $ $ $ $ $ $ $   - - -      r   r  c                   Z    e Zd Z	 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S )TestNamedTemporaryFileNr   Tc                     |t          j                    }t          j        ||||          }|                     |j        |||           |S )N)rU   rq  r  r  )r   rk   rd   r]   rT   )r   rU   rV   rW   r  r   s         r   r  z TestNamedTemporaryFile.do_create  sV    ;%''C*s3s28: : : 	ty#sC000r   c                     |                                   |                      d           |                      d           |                      dd           |                      dd           d S r  r  r   s    r   r   z!TestNamedTemporaryFile.test_basic  r  r   c                    |                                  }t          j        |          }|j        }|j        }~ |d           ~ |d           ~t	          j        d          r|                      |                       d S d S )N   foos   barT)cpython)r  weakrefrefr   r   check_impl_detailassertIsNone)r   rT  wrr   write2s        r   test_method_lookupz)TestNamedTemporaryFile.test_method_lookup  s     NN[^^fv$T222 	$bbdd#####	$ 	$r   c                     g dfd}t           |                      D ]!\  }}|                     ||                    "|                     |t                    dz
             d S )N)s   spam
s   eggs
s   beans
c                      t          j        d          } |                     d                                         |                     d           | S )Nw+br   r   r   )r   rd   r   r   seek)rT  liness    r   	make_filez3TestNamedTemporaryFile.test_iter.<locals>.make_file  sF    +777AGGCHHUOO$$$FF1IIIHr   rc   )	enumeraterM   rI   )r   r  r   lr  s       @r   	test_iterz TestNamedTemporaryFile.test_iter  s     322	 	 	 	 	
 iikk** 	* 	*DAqQa))))CJJN+++++r   c                     t          j                    }|                     t          j                            |j                  d|j        z             d S )Nz$NamedTemporaryFile %s does not exist)r   rd   rQ   rG   r-   existsrT   rS  s     r   test_creates_namedz)TestNamedTemporaryFile.test_creates_named  sQ    '))qv..>G	I 	I 	I 	I 	Ir   c                    t          j                    }	 t          j        |          5 }|                    d           d d d            n# 1 swxY w Y   |                     t          j        |          g            |                     t
          j        	                    |j
                  d|j
        z             t          j        |           d S # t          j        |           w xY w)Nr   r  z(NamedTemporaryFile %s exists after close)r   rg   rd   r   rM   rG   r   r   r-   r  rT   r4  r   rU   rT  s      r   test_del_on_closez(TestNamedTemporaryFile.test_del_on_close  s     	,555 !   ! ! ! ! ! ! ! ! ! ! ! ! ! ! !RZ__b111RW^^AF33BQVKM M M HSMMMMMBHSMMMMs/   C A C AC AA+C C+c                    t          j                    }d }	 t          j        |d          }|j        }|                    d           |                                 |                     t          j        	                    |j                  d|j        z             |t          j
        |           t          j        |           d S # |t          j
        |           t          j        |           w xY w)NF)rU   r  r  z)NamedTemporaryFile %s missing after close)r   rg   rd   rT   r   r   rQ   rG   r-   r  r  r4  )r   rU   tmprT  s       r   test_dis_del_on_closez,TestNamedTemporaryFile.test_dis_del_on_close  s      
	+EBBBA&CGGGGGIIIOOBGNN1622CafLN N N 	#HSMMMMM 	#HSMMMMs   BC	 	,C5c                     t          j                    }|                    d           |                                 |                                 |                                 d S N   abc
)r   rd   r   r   rS  s     r   test_multiple_closez*TestNamedTemporaryFile.test_multiple_close  sM    '))															r   c                 z   t          j                    5 |                     t          j                            j                             d d d            n# 1 swxY w Y   |                     t          j                            j                             fd}|                     t          |           d S )Nc                  @     5  	 d d d            d S # 1 swxY w Y   d S r+   r4   rT  s   r   
use_closedz?TestNamedTemporaryFile.test_context_manager.<locals>.use_closed  p                          )
r   rd   rQ   rG   r-   r  rT   r   r   r   r   r  rT  s     @r   test_context_managerz+TestNamedTemporaryFile.test_context_manager  s    (** 	4aOOBGNN1622333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4//000	 	 	 	 	 	*j11111s   8AA Ac                    t          j                    }|                     t          j        |           |                     t                    5  t          j        d|           d d d            n# 1 swxY w Y   |                     t                    5  t          j        d|           d d d            n# 1 swxY w Y   | 	                    t          j        |          g            d S Nr  )r   rU      )r   rg   
addCleanupr   r   r   r   rd   r   rM   rG   r   r5  s     r   test_bad_modez$TestNamedTemporaryFile.test_bad_mode  sI     	(#...z** 	< 	<'Ts;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<y)) 	9 	9'QC8888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9C"-----$   A11A58A5B99B= B=c                 N   t          j                    }|                     t          j        |           |                     t                    5  t          j        dd|           d d d            n# 1 swxY w Y   |                     t          j
        |          g            d S Nwzbad-encoding)encodingrU   )r   rg   r  r   r   r   LookupErrorrd   rM   rG   r   r5  s     r   test_bad_encodingz(TestNamedTemporaryFile.test_bad_encoding  s      	(#...{++ 	O 	O'n#NNNN	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	OC"-----   A22A69A6c                    t          j                    }|                     t          j        |           t          j        d          5 }t          j        dt          j                              5 }t                      |_	        | 
                    t                    5  t          j        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y    |            j                                         |                     t          j        |          g            d S )Nztempfile._TemporaryFileWrapperzio.openr   )r   rg   r  r   r   r   patch	mock_openKeyboardInterruptside_effectr   rd   r   assert_calledrM   rG   r   )r   rU   mock_ntfr  s       r   test_unexpected_errorz,TestNamedTemporaryFile.test_unexpected_error  s     	(#...Z899 	5XZ	4>#3#344	58A#4#6#6H ""#455 5 5+44445 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5
 		'')))C"-----sZ   'C-/.CB?3C?CCCC
C-C	C-C	C--C14C1)Nr   r   T)r1   r2   r3   r  r   r  r  r  r  r  r  r  r  r  r  r4   r   r   r  r    s        $   - - -$ $ $ , , ,I I I
 
 
     2 2 2. . .. . .	. 	. 	. 	. 	.r   r  c                      e Zd Z	 ddZd Zd Zd Zd Zd	 Z e	j
        ej        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 Zd Zd Z e	j
        ej        d
          d             Zd ZdS )TestSpooledTemporaryFiler   Nr   c                 `    |t          j                    }t          j        ||||          }|S )N)max_sizerU   rq  r  )r   rk   ro   )r   r  rU   rV   rW   r   s         r   r  z"TestSpooledTemporaryFile.do_create  s5    ;%''C,hCPS\_```r   c                     |                                  }|                     |j                   |                      ddd          }|                     |j                   d S )Nr   r   r  )r  rV   rW   )r  r   _rolledrS  s     r   r   z#TestSpooledTemporaryFile.test_basic   sZ    NN###NNCSfN==#####r   c                 j    |                      |                                 t          j                   d S r+   )r   r  ioIOBaser   s    r   test_is_iobasez'TestSpooledTemporaryFile.test_is_iobase'  s*    dnn..	:::::r   c                     h d}t          t          t          j                            }||z
  }|                     |d           d S )N>   r   r  tellr   flushread1r   closeddetacherrorsfilenoisatty__exit____iter____next__r  newlinesreadablereadintoreadlineseekabletruncatewritable	__enter__	readinto1	readlines
writelineszMSpooledTemporaryFile missing attributes from IOBase/BufferedIOBase/TextIOBase)setrU   r   ro   r   )r   iobase_attrsspooledtempfile_attrsmissing_attrss       r   test_iobase_interfacez.TestSpooledTemporaryFile.test_iobase_interface+  sa    	
 	
 	
 !$C(E$F$F G G$'<<[	
 	
 	
 	
 	
r   c                 b   t          j                    }	 t          j        d|          }|                     |j                   |                    d           |                     |j                   |j        }|                                 | 	                    t          j        |          g            t          |t                    s6|                     t          j                            |          d|z             t          j        |           d S # t          j        |           w xY w)N
   )r  rU   s   blat blat blat blat blat z*SpooledTemporaryFile %s exists after close)r   rg   ro   r   r  r   rQ   rT   r   rM   rG   r   rK   intr-   r  r4  )r   rU   rT  filenames       r   r  z*TestSpooledTemporaryFile.test_del_on_close?  s     	-rsCCCAQY'''GGL!!!OOAI&&&vHGGIIIRZ__b111h,, M  !9!9@8KM M M HSMMMMMBHSMMMMs   C-D D.c                     |                      d          }|                    d           |                     |j        d            |                     t
                    5  |                                 d d d            d S # 1 swxY w Y   d S )Nr  r  r  )r  r   rM   rT   assertWarnsResourceWarningr  rS  s     r   test_del_unrolled_filez/TestSpooledTemporaryFile.test_del_unrolled_fileP  s     NNBN''	&&&o.. 	 	IIKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   !BB
Bz&Emscripten cannot fstat renamed files.c                    |                      d          }|                    d           |j        }|                     t          j                            |                     |                     t                    5  |	                                 d d d            n# 1 swxY w Y   | 
                    t          j                            |          d|z             d S )Nr  r#  r  z9Rolled SpooledTemporaryFile (name=%s) exists after delete)r  r   rT   rQ   rG   r-   r  r$  r%  r  r   )r   rT  rT   s      r   test_del_rolled_filez-TestSpooledTemporaryFile.test_del_rolled_fileY  s     NNAN&&	vt,,---o.. 	 	IIKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	GNN4  G$N	
 	
 	
 	
 	
s   ?B  B$'B$c                    |                      d          }|                     |j                   t          d          D ]-}|                    dd           |                    d           .|                     |j                   d S )N   r#     r      xxxxxxxxxxxxxxxxxxxx)r  r   r  r   r  r   )r   rT  r   s      r   test_rewrite_smallz+TestSpooledTemporaryFile.test_rewrite_smallk  s    NNBN''###q 	 	AFF1aLLLGGI#####r   c                    |                      d          }|                     |j                   |                    d           |                     |j                   |                    d           |                     |j                   |                    d           |                     |j                   d S )Nr*  r#  r,  
   xxxxxxxxxx   x)r  r   r  r   rQ   rS  s     r   test_write_sequentialz.TestSpooledTemporaryFile.test_write_sequentialt  s     NNBN''###		###		###		"""""r   c                    |                                  }|                    d           |                    d          }|                     |d           |                                }|                     |d           d S )N)r0     y   zr   s   xyz)r  r  r  rM   r   )r   rT  posbufs       r   test_writelinesz(TestSpooledTemporaryFile.test_writelines  sr    NN	'(((ffQiia   ffhhf%%%%%r   c                     |                      d          }|                    d           |                     |j                   |                    d           |                     |j                   d S )N#   r#  )r,  r/  s   xxxxxr0  )r  r  r   r  r   rQ   rS  s     r   test_writelines_sequentialz3TestSpooledTemporaryFile.test_writelines_sequential  si     NNBN''	5666###		"""""r   c                 P   |                      d          }|                     |j                   |                    dd          }|                     |d           |                     |j                   |                    d           |                     |j                   d S )Nr*  r#  r   r   r0  )r  r   r  r  rM   r   rQ   )r   rT  r5  s      r   test_sparsez$TestSpooledTemporaryFile.test_sparse  s     NNBN''###ffS!nnc"""###		"""""r   c                     |                      d          }|                     |j                   |                     |                                dk               |                     |j                   d S )Nr*  r#  r   )r  r   r  rQ   r	  rS  s     r   test_filenoz$TestSpooledTemporaryFile.test_fileno  sc    NNBN''###

Q'''	"""""r   c                    t          j                    }|                    d           |                     |j                   |                                 |                                 |                                 d S r  )r   ro   r   r   r  r   rS  s     r   #test_multiple_close_before_rolloverz<TestSpooledTemporaryFile.test_multiple_close_before_rollover  sc    )++	###														r   c                    t          j        d          }|                    d           |                     |j                   |                                 |                                 |                                 d S )Nrc   r#  r  )r   ro   r   rQ   r  r   rS  s     r   "test_multiple_close_after_rolloverz;TestSpooledTemporaryFile.test_multiple_close_after_rollover  sf    )1555		"""														r   c                     |                      d          }|j        }|j        }|j        } |d            |d            |dd           |                      |d          d           d S )Nr*  r#  s#   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas#   bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbr   F   sF   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)r  r   r   r  rM   )r   rT  r   r   r  s        r   test_bound_methodsz+TestSpooledTemporaryFile.test_bound_methods  s     NNBN''vviiQ


b#455555r   c                 n   t          j        d          }|                    d           |                     |j                   |                     |j        d           |                     |j                   | 	                    t                    5  |j         d d d            n# 1 swxY w Y   | 	                    t                    5  |j         d d d            n# 1 swxY w Y   | 	                    t                    5  |j         d d d            n# 1 swxY w Y   |                    d           |                     |j                   |                     |j        d           |                     |j                   | 	                    t                    5  |j         d d d            n# 1 swxY w Y   | 	                    t                    5  |j         d d d            n# 1 swxY w Y   | 	                    t                    5  |j         d d d            d S # 1 swxY w Y   d S )Nr  r#  r/  r  r0  zrb+)r   ro   r   r   r  rM   r   r  rT   r   r   r  r  r  rQ   assertIsNotNonerS  s     r   test_propertiesz(TestSpooledTemporaryFile.test_properties  sm   )2666		###'''!&!!!~.. 	 	JJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	~.. 	 	JJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	~.. 	 	HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
	"""'''QV$$$~.. 	 	JJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	~.. 	 	JJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	~.. 	 	HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sl   B((B,/B,C!!C%(C%DD!D#F77F;>F;G00G47G4H**H.1H.c                 l   t          j        ddd          }|                    d           |                    d           |                     |                                d           |                    d           |                    d           |                     |                                d           |                     |j                   |                     |j        d           | 	                    |j
                   |                     |j        t          j                   |                     |j        d           |                     |j        d	           |                    d
           |                    d           |                     |                                d           |                    d           |                    d           |                     |                                d           |                     |j                   |                     |j        d           |                     |j
                   |                     |j        t          j                   |                     |j        d           |                     |j        d	           d S )Nw+r  utf-8)r   r  r  zabc
r   zdef
zabc
def
strictzxyzzy
zabc
def
xyzzy
zfoobar
zabc
def
xyzzy
foobar
)r   ro   r   r  rM   r   r   r  r   r  rT   r  rG   linesepr  r  rQ   rG  rS  s     r   test_text_modez'TestSpooledTemporaryFile.test_text_mode  s@    )tb3:< < <		q			7+++		q			<000###&&&!&!!!RZ000W---8,,,			q			#6777		q			#BCCC	"""&&&QV$$$RZ000W---8,,,,,r   c                 &   t          j        ddddd          }|                    d           |                    d           |                     |                                d           |                     |j                   |                     |j        d           | 	                    |j
                   |                     |j                   |                     |j        d           |                     |j        d           |                    d	           |                    d
           |                    d           |                     |                                d           |                     |j                   |                     |j        d           |                     |j
                   |                     |j                   |                     |j        d           |                     |j        d           d S )NrJ  r  r   rK  r:   )r   r  newliner  r  u   Λ
r   u   ΜΜΜΜΜΜΜΜΜΜ
u(   ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝuB   Λ
ΜΜΜΜΜΜΜΜΜΜ
ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ)r   ro   r   r  rM   r   r   r  r   r  rT   rG  r  r  r  rQ   rS  s     r   test_text_newline_and_encodingz7TestSpooledTemporaryFile.test_text_newline_and_encoding  s   )tb24w19; ; ; 	
	q			<000###&&&!&!!!QZ(((W---8,,,	&'''		q			I	K 	K 	K	"""&&&QV$$$QZ(((W---8,,,,,r   c                 >   t          j        d          5 |                     j                   |                     j                   d d d            n# 1 swxY w Y   |                     j                   fd}|                     t          |           d S )Nrc   r#  c                  @     5  	 d d d            d S # 1 swxY w Y   d S r+   r4   r  s   r   r  zQTestSpooledTemporaryFile.test_context_manager_before_rollover.<locals>.use_closed  r  r  )r   ro   r   r  r  rQ   r   r   r  s     @r   $test_context_manager_before_rolloverz=TestSpooledTemporaryFile.test_context_manager_before_rollover  s    *A666 	'!QY'''QX&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	!!!	 	 	 	 	 	*j11111s   5AAAc                    t          j        d          5 |                     j                                       d                                            |                     j                   |                     j                   d d d            n# 1 swxY w Y   |                     j                   fd}|                     t          |           d S )Nrc   r#  r  c                  @     5  	 d d d            d S # 1 swxY w Y   d S r+   r4   r  s   r   r  zQTestSpooledTemporaryFile.test_context_manager_during_rollover.<locals>.use_closed*  r  r  )
r   ro   r   r  r   r  rQ   r  r   r   r  s     @r   $test_context_manager_during_rolloverz=TestSpooledTemporaryFile.test_context_manager_during_rollover!  s   *A666 	'!QY'''GGHGGIIIOOAI&&&QX&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	!!!	 	 	 	 	 	*j11111s   A8BB"Bc                    t          j        d                              d                                            |                     j                   5  |                     j                   d d d            n# 1 swxY w Y   |                     j                   fd}|                     t          |           d S )Nrc   r#  r  c                  @     5  	 d d d            d S # 1 swxY w Y   d S r+   r4   r  s   r   r  zPTestSpooledTemporaryFile.test_context_manager_after_rollover.<locals>.use_closed8  r  r  )
r   ro   r   r  rQ   r  r   r  r   r   r  s     @r   #test_context_manager_after_rolloverz<TestSpooledTemporaryFile.test_context_manager_after_rollover/  s   )1555						""" 	' 	'QX&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'!!!	 	 	 	 	 	*j11111s   BB
Bc                 v   t          j        d          }|                    d           |                    d           |                                 |                     |j                   |                     |j        	                                d           t          j        d          }|                    d           |                    d           |                     |j                   |                     |j        	                                d           t          j        d          }|                    d           |                    d           | 
                    |j                   |                     t          j        |                                          j        d           d S )	Nr  r#  s   abcdefg
r   r      s   abcdr   )r   ro   r   r  r  r   r  rM   _filegetvaluerQ   rG   fstatr	  st_sizerS  s     r   !test_truncate_with_size_parameterz:TestSpooledTemporaryFile.test_truncate_with_size_parameter=  sf   
 )2666		q				

###))++S111)2666		

1###))++W555)2666		

2	"""!((**--5r:::::r   c                 p    |                      t          j        t                   t          j                   d S r+   )r   r   ro   r   typesGenericAliasr   s    r   test_class_getitemz+TestSpooledTemporaryFile.test_class_getitemU  s4    h;EB(	* 	* 	* 	* 	*r   )r   Nr   r   )r1   r2   r3   r  r   r  r  r  r&  r   r   r   r  r(  r-  r1  r7  r:  r<  r>  r@  rB  rE  rH  rN  rQ  rT  rW  rZ  ra  re  r4   r   r   r  r    s       &   $ $ $; ; ;
 
 
(  "   X_G 
 
 
$ $ $
# 
# 
#& & &# # #	# 	# 	## # #    6 6 6  0- - -@- - -4	2 	2 	22 2 22 2 2 X_G ; ; ;** * * * *r   r  c                   :    e Zd Z	 d Zd Zd Zd Zd Zd Zd Z	dS )	TestTemporaryFilec                 ,    t          j                     d S r+   )r   re   r   s    r   r   zTestTemporaryFile.test_basic^  s     "$$$$$r   c                    t          j                    }t          j        |          }|                    d           	 t	          j        |           d S #  |                                 t	          j        |            xY wr2  )r   rg   re   r   rG   r4  r   r  s      r   test_has_no_namez"TestTemporaryFile.test_has_no_namec  sq    "$$C&3///AGGG			s   A +B c                     t          j                    }|                    d           |                                 |                                 |                                 d S r  )r   re   r   r   rS  s     r   r  z%TestTemporaryFile.test_multiple_closes  sM    &((AGGHGGIIIGGIIIGGIIIIIr   c                 z      fd} |dd            |dd            |ddd            |d	dd
           d S )Nc                     t          j        |i |5 }|                    |            |                    d                               | |                                           d d d            d S # 1 swxY w Y   d S r   )r   re   r   r  rM   r   )inputr   r   fileobjr   s       r   	roundtripz;TestTemporaryFile.test_mode_and_encoding.<locals>.roundtrip~  s    +T<V<< <MM%(((LLOOO$$UGLLNN;;;< < < < < < < < < < < < < < < < < <s   AA33A7:A7s   1234r  zabdc
rJ  u   Λzutf-16)r  zfoo
r   )rP  r4   )r   rp  s   ` r   test_mode_and_encodingz(TestTemporaryFile.test_mode_and_encoding|  sv    < < < < < Igu%%%Ih%%%Ihx8888Iir222222r   c                    t          j                    }|                     t          j        |           |                     t                    5  t          j        d|           d d d            n# 1 swxY w Y   |                     t                    5  t          j        d|           d d d            n# 1 swxY w Y   | 	                    t          j        |          g            d S r  )r   rg   r  r   r   r   r   re   r   rM   rG   r   r5  s     r   r  zTestTemporaryFile.test_bad_mode  sI   "$$COOI,c222"":.. ; ;&Dc::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;""9-- 8 8&A377778 8 8 8 8 8 8 8 8 8 8 8 8 8 8RZ__b11111r  c                 N   t          j                    }|                     t          j        |           |                     t                    5  t          j        dd|           d d d            n# 1 swxY w Y   |                     t          j
        |          g            d S r  )r   rg   r  r   r   r   r  re   rM   rG   r   r5  s     r   r  z#TestTemporaryFile.test_bad_encoding  s    "$$COOI,c222"";// N N&s^MMMMN N N N N N N N N N N N N N NRZ__b11111r  c           
         t          j                    }|                     t          j        |           t          j        dd          5  t          j        d          5 }t          j        d          5 }t          j        d          5 }t                      |_        | 	                    t                    5  t          j
        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                                 |                     t          j        |          g            d S )Nztempfile._O_TMPFILE_WORKSFz	os.unlinkzos.openzos.closer   )r   rg   r  r   r   r   r  r  r  r   re   r  rM   rG   r   )r   rU   mock_unlinkr  
mock_closes        r   r  z'TestTemporaryFile.test_unexpected_error  s~   "$$COOI,c2227?? 4 4K((4,7I&&4*3J''4 ,6*;*=*='&&'899 4 4*s33334 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 $$&&&RZ__b11111s   	D4D3D.C/	6CC/	CC/	C C/	#D/C33D6C37D:DD

DD
DD4D!	!D4$D!	%D44D8;D8N)
r1   r2   r3   r   rj  r  rq  r  r  r  r4   r   r   rg  rg  [  s        #	% 	% 	%
	 	 	 	 	 		3 	3 	3	2 	2 	2	2 	2 	2	2 	2 	2 	2 	2r   rg  c                        e Zd Zd Zd Zd ZdS )NulledModulesc                 T    d |D             | _         d | j         D             | _        d S )Nc                     g | ]	}|j         
S r4   )rr   ).0mods     r   
<listcomp>z*NulledModules.__init__.<locals>.<listcomp>  s    555cS\555r   c                 6    g | ]}|                                 S r4   )copy)r{  r  s     r   r}  z*NulledModules.__init__.<locals>.<listcomp>  s     999999r   )refscontents)r   moduless     r   r.   zNulledModules.__init__  s2    55W555	99ty999r   c                 .    | j         D ]}|D ]}d ||<   d S r+   )r  )r   rt  rw   s      r   r  zNulledModules.__enter__  s<     	 	A  #	 	r   c                     t          | j        | j                  D ].\  }}|                                 |                    |           /d S r+   )zipr  r  clearupdate)r   exc_infort  r   s       r   r  zNulledModules.__exit__  sK    	4=11 	 	DAqGGIIIHHQKKKK	 	r   N)r1   r2   r3   r.   r  r  r4   r   r   rx  rx    sA        : : :  
    r   rx  c                      e Zd Z	 	 	 ddZddZd Zd Zd	 Zej	        d
             Z
ej        d             Zej        d             Zd Zd Zd Zd Zd Zd Zd Z ej         eed          d          d             ZdS )TestTemporaryDirectoryNr   rc   Fc                     |t          j                    }t          j        ||||          }|                     |j        |||           |                     |j        |||           |S )N)rU   rq  r  ignore_cleanup_errors)r   rk   rp   r]   rT   
do_create2)	r   rU   rV   rW   recursedirsfilesr  r  s	            r   r  z TestTemporaryDirectory.do_create  sq    ;%''C)C"79 9 9 	sxc3///'4777
r   c                    |rdt          |          D ]T}t          j                            |d|z            }t          j        |           |                     ||dz
  ||           Ut          |          D ]`}t          t          j                            |d|z            d          5 }|                    d           d d d            n# 1 swxY w Y   ad S )Nzdir%drc   z
test%d.txtr   s   Hello world!)r   rG   r-   r   mkdirr  r   r   )r   r-   r  r  r  r   rT   rT  s           r   r  z!TestTemporaryDirectory.do_create2  s    	>4[[ > >w||D'A+66gaiu====u 	) 	)Abgll4)9::DAA )Q((() ) ) ) ) ) ) ) ) ) ) ) ) ) )	) 	)s   )CC	C	c                 @   t          j                    5 }	 d d d            n# 1 swxY w Y   |                     t                    5 }t          j        |           d d d            n# 1 swxY w Y   |                     |j        j        t          j                   d S r  )r   rp   r   r   rM   	exceptionerrnoENOENT)r   r   cms      r   test_mkdtemp_failurez+TestTemporaryDirectory.test_mkdtemp_failure  s    (** 	k	 	 	 	 	 	 	 	 	 	 	 	 	 	 	011 	9R'K8888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9+U\:::::s   "&&A))A-0A-c                    t          j                    }	 |                     |          }|                     t          j                            |j                  d|j        z             |                                 | 	                    t          j                            |j                  d|j        z             t	          j
        |           d S # t	          j
        |           w xY w)Nr   z$TemporaryDirectory %s does not exist*TemporaryDirectory %s exists after cleanup)r   rg   r  rQ   rG   r-   r  rT   cleanupr   r4  )r   rU   rt  s      r   test_explicit_cleanupz,TestTemporaryDirectory.test_explicit_cleanup  s      	3''AOOBGNN1622BQVKM M MIIKKKRW^^AF33DqvMO O O HSMMMMMBHSMMMMs   B*C C+c           
         	 t          j                    5 }|                     |d          }t          j        |j                  }|                     |                                d|d           t          |dz  d          5 }|	                    d           |
                                 d d d            n# 1 swxY w Y   |                     t          t          |                    d                              t          t           j                            d	                    d
|           |                     |                                t           j                            d	          d|d           |
                                 |                     |                                d|d           d d d            d S # 1 swxY w Y   d S )NTrU   r  TemporaryDirectory  does not exist
a_file.txtw+tHello world!
*win1Unexpected number of files in TemporaryDirectory  existence state unexpectedz exists after cleanup)r   rp   r  r$   r%   rT   rQ   r  r   r   r  rM   rI   r-  globr   r=  r>  
startswithr   r   working_dirtemp_dir	temp_path	open_files        r   "test_explict_cleanup_ignore_errorsz9TestTemporaryDirectory.test_explict_cleanup_ignore_errors  s{   K(** 	Jk~~t & = =HX]33IOOI,,..N)NNNP P Pi,.66 #) 0111  """# # # # # # # # # # # # # # # SinnS&9&9!:!:;; !8!8!?!?@@A3<A AB B B   ""''..NiNNNP P P   ""HiHHHJ J J%	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js7   A0G*B;/G;B?	?GB?	C>GGGc                 r   |                                  }|                      d          }t          j        |j        t          j                            |j        d                     |                                 |                     t          j                            |j                  d|j        z             | 	                    t          j                            |j                  d           | 
                    t          j        |j                  dgd           |                                 d S )Nr   )r  foor  z-Directory pointed to by a symlink was deletedz	test0.txtz>Contents of the directory pointed to by a symlink were deleted)r  rG   symlinkrT   r-   r   r  r   r  rQ   rM   r   )r   d1d2s      r   (test_cleanup_with_symlink_to_a_directoryz?TestTemporaryDirectory.test_cleanup_with_symlink_to_a_directory   s    ^^^^A^&& 	
27BGLL%88999 	

00EO	Q 	Q 	Qrw//G	I 	I 	IBG,,{m(	) 	) 	) 	

r   c                 0   t          j                    }	 |                     |          }|j        }~|                     t
          j                            |          d|z             t          j        |           d S # t          j        |           w xY w)Nr   *TemporaryDirectory %s exists after __del__)	r   rg   r  rT   r   rG   r-   r  r4  r   rU   rt  rT   s       r   test_del_on_collectionz-TestTemporaryDirectory.test_del_on_collection  s       	3''A6DRW^^D11DtKM M M HSMMMMMBHSMMMMs   AA? ?Bc           
         	 t          j                    5 }|                     |d          }t          j        |j                  }|                     |                                d|d           t          |dz  d          5 }|	                    d           ~d d d            n# 1 swxY w Y   | 
                    t          t          |                    d                              t          t          j                            d	                    d
|           | 
                    |                                t          j                            d	          d|d           d d d            d S # 1 swxY w Y   d S )NTr  r  r  r  r  r  r  r  r  r  )r   rp   r  r$   r%   rT   rQ   r  r   r   rM   rI   r-  r  r   r=  r>  r  r  s        r   $test_del_on_collection_ignore_errorsz;TestTemporaryDirectory.test_del_on_collection_ignore_errors"  s    N(** 	Pk~~t & = =HX]33IOOI,,..N)NNNP P Pi,.66 ) 0111               SinnS&9&9!:!:;; !8!8!?!?@@A3<A AB B B   ""''..NiNNNP P P	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Ps7   A0E;B(E;(B,	,E;/B,	0B>E;;E?E?c                    |                                  5 }dD ]}d                    ||          }t          j        d|          \  }}}|                                                                }|                     t          j        	                    |          d|z             |                    dd          }| 
                    d|           |                     d	|           	 d d d            d S # 1 swxY w Y   d S )
N)builtinsrG   shutilr=  r   rA   a  if True:
                    import builtins
                    import os
                    import shutil
                    import sys
                    import tempfile
                    import warnings

                    tmp = tempfile.TemporaryDirectory(dir={dir!r})
                    sys.stdout.buffer.write(tmp.name.encode())

                    tmp2 = os.path.join(tmp.name, 'test_dir')
                    os.mkdir(tmp2)
                    with open(os.path.join(tmp2, "test0.txt"), "w") as f:
                        f.write("Hello world!")

                    {mod}.tmp = tmp

                    warnings.filterwarnings("always", category=ResourceWarning)
                    )rU   r|  -cr  rK  backslashreplace
Exception 'ResourceWarning: Implicitly cleaning upr  formatr   assert_python_okr   stripr   rG   r-   r  r   r   )r   rU   r|  codercouterrtmp_names           r   test_del_on_shutdownz+TestTemporaryDirectory.test_del_on_shutdown7  sb   ^^ 	NR N N& 3C00' (  -=dDIIC::<<--//  !9!9H8SU U Ujj*<==  s333GMMMM7N	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	Ns   CC77C;>C;c           
      T   	 t          j                    5 }d                    |          }t          j        d|          \  }}}t          j        |                                                                          }| 	                    t          t          |                    d                              t          t          j                            d                    d|           | 	                    |                                t          j                            d          d|d           |                    d	d
          }|                     d|           |                     d|           |                     d|           d d d            d S # 1 swxY w Y   d S )Na  if True:
                import pathlib
                import sys
                import tempfile
                import warnings

                temp_dir = tempfile.TemporaryDirectory(
                    dir={working_dir!r}, ignore_cleanup_errors=True)
                sys.stdout.buffer.write(temp_dir.name.encode())

                temp_dir_2 = pathlib.Path(temp_dir.name) / "test_dir"
                temp_dir_2.mkdir()
                with open(temp_dir_2 / "test0.txt", "w") as test_file:
                    test_file.write("Hello world!")
                open_file = open(temp_dir_2 / "open_file.txt", "w")
                open_file.write("Hello world!")

                warnings.filterwarnings("always", category=ResourceWarning)
                )r  r  r  r  r  r  r  rK  r  	ExceptionErrorr  )r   rp   r  r   r  r$   r%   r   r  rM   rI   r-  r  r   r=  r>  r  r  r   r   )r   r  r  __r  r  r  s          r   "test_del_on_shutdown_ignore_errorsz9TestTemporaryDirectory.test_del_on_shutdown_ignore_errorsW  s   M(** !	Jk$ F{F33% & )9$EELBSSZZ\\%7%7%9%9::ISinnS&9&9!:!:;; !8!8!?!?@@A3<A AB B B   ""''..NiNNNP P P **W&899C[#...Wc***MMCSIIIC!	J !	J !	J !	J !	J !	J !	J !	J !	J !	J !	J !	J !	J !	J !	J !	J !	J !	Js   E;FF!$F!c                    |                                  5 }d                    |          }t          j        d|          \  }}}|                                                                }|                     t          j        	                    |          d|z             |                    dd          }| 
                    d|           |                     d|           d d d            d S # 1 swxY w Y   d S )	Na  if True:
                import sys
                import tempfile
                import warnings

                def generator():
                    with tempfile.TemporaryDirectory(dir={dir!r}) as tmp:
                        yield tmp
                g = generator()
                sys.stdout.buffer.write(next(g).encode())

                warnings.filterwarnings("always", category=ResourceWarning)
                r   r  r  rK  r  r  r  r  )r   rU   r  r  r  r  r  s          r   test_exit_on_shutdownz,TestTemporaryDirectory.test_exit_on_shutdown|  sD   ^^ 	J FsFOO  )9$EELBSzz||))++HRW^^H55DxOQ Q Q**W&899C\3///MMCSIII)	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js   CC00C47C4c                    |                                  5 }|                      |d          }|j        }t          j        dt          fd          5  t          j        dt                     ~t          j                     d d d            n# 1 swxY w Y   | 	                    t          j                            |          d|z             d d d            d S # 1 swxY w Y   d S )	N   )rU   r  
ImplicitlyF)quietalways)r<   r  )r  rT   r   r@   r%  rA   rB   r   r3  r   rG   r-   r  r  s       r   test_warnings_on_cleanupz/TestTemporaryDirectory.test_warnings_on_cleanup  s~   ^^ 	M322A6D !/1@1B6;= = = % % '?KKKK"$$$% % % % % % % % % % % % % % % RW^^D11DtKM M M	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	Ms5   <C0BCB	CB	9CC"Cc                     |                                  }|                                 |                                 |                                 d S r+   )r  r  r{  s     r   r  z*TestTemporaryDirectory.test_multiple_close  s<    NN									r   c                 `   |                                  }|5 }|                     t          j                            |                     |                     ||j                   d d d            n# 1 swxY w Y   |                     t          j                            |                     d S r+   )r  rQ   rG   r-   r  rM   rT   r   )r   rt  rT   s      r   r  z+TestTemporaryDirectory.test_context_manager  s    NN 	+$OOBGNN400111T16***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	--.....s   AA11A58A5c                    t          d          D ]0}|dz  }|                     t          |d                    5  |                     ddd          }|5  t	          j        |j        d	          D ]S\  }}}|D ]5}t	          j        t          j        	                    ||          |           6t	          j        ||           T|
                                 d d d            n# 1 swxY w Y   |                     t          j                            |j                             d d d            n# 1 swxY w Y   2d S )
N   r:  03or  r  r  r  r  r  Ftopdown)r   subTestr  r  rG   walkrT   r   r-   r   r  r   r  )r   r   rt  rootr  r  rT   s          r   
test_modesz!TestTemporaryDirectory.test_modes  s   !HH 	9 	9DQJD6$#6#677 	9 	9NN11AN>>    -/WQVU-K-K-K - -)dE$) E EDHRW\\$%=%=tDDDDt,,,,IIKKK                                !7!7888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9	9 	9s6   D5BC'D5'C++D5.C+/:D55D9	<D9	chflagszrequires os.lchflagsc           	         t           j        t           j        z  }|                     ddd          }|5  t	          j        |j        d          D ]S\  }}}|D ]5}t	          j        t          j        	                    ||          |           6t	          j        ||           T|
                                 d d d            n# 1 swxY w Y   |                     t          j                            |j                             d S )Nr  r  r  Fr  )r   UF_IMMUTABLEUF_NOUNLINKr  rG   r  rT   r  r-   r   r  r   r  )r   r  rt  r  r  r  rT   s          r   
test_flagsz!TestTemporaryDirectory.test_flags  s/   !D$44NN11AN66 	 	%'WQVU%C%C%C ( (!dE! @ @DJrw||D$77????
4''''IIKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	//00000s   BCCC)Nr   r   rc   rc   rc   F)rc   rc   rc   )r1   r2   r3   r  r  r  r  r  r   skip_unless_symlinkr  r   cpython_onlyr  r  r  r  r  r  r  r  r  r   rd  hasattrrG   r  r4   r   r   r  r    s       $KL(-	 	 	 		) 	) 	) 	); ; ;  J J J0 "  #"( 
 
 
 P P P(N N N@#J #J #JJJ J J0M M M   / / /9 9 9 XY//1GHH
1 
1 IH
1 
1 
1r   r  __main__)7r   r  r  rG   r$   r=  r^   rA   
contextlibr   rc  r  r   r   testr   test.supportr   r   r   r  r  rg  r  re  r>  r  r   TestCaser   r8   ra   rz   r   r   r   contextmanagerr   r   r   r  ri  rw  r  r  r  r  r  rd   re   rg  rx  r  r1   mainr4   r   r   <module>r     s     				 				  



 				                      " " " " " " & & & & & & ( ( ( ( ( ( (H,CCWR""
 <9%% JJJ.7 .7 .7 .7 .7H- .7 .7 .7d,2 ,2 ,2 ,2 ,28$ ,2 ,2 ,2^7 7 7 7 7, 7 7 7<;7 ;7 ;7 ;7 ;7\ ;7 ;7 ;7~") ") ") ") ")| ") ") ")TI I I I IL I I I@         L          2 2 2 %  %  %  %  %  %  %  %Fn2 n2 n2 n2 n2~| n2 n2 n2b       @+4 +4 +4 +4 +4\ +4 +4 +4\[, [, [, [, [,, [, [, [,|D, D, D, D, D,., D, D, D,N0 0 0 0 0 0 0 0|. . . . .\ . . .FB* B* B* B* B*| B* B* B*H
 h&<<<I2 I2 I2 I2 I2L I2 I2 I2Z        T1 T1 T1 T1 T1\ T1 T1 T1n zHMOOOOO r   