Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_tempfile.cpython-39.opt-1.pyc

a

��gD��@s.ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddl
Z
ddlmZddlmZejejkZeed�Zej�d�r�dZndZGd	d
�d
e
j�ZGdd�de
j�ZGd
d�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"ej#dd��Z$dd�Z%Gdd�d�Z&Gdd�de&e�Z'Gdd �d e�Z(Gd!d"�d"e�Z)Gd#d$�d$e�Z*Gd%d&�d&e&e�Z+Gd'd(�d(e�Z,Gd)d*�d*e�Z-Gd+d,�d,e�Z.ej/ej0u�r�Gd-d.�d.e�Z1Gd/d0�d0�Z2Gd1d2�d2e�Z3e4d3k�r*e
�5�dS)4�N)�mock)�support)�
script_helper�spawnlZopenbsd�0�dc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestLowLevelInternalscCs:|�tt�d��|�tt�d��|�tt�d��dS�N��)�assertIs�str�tempfile�_infer_return_type�bytes��self�r�./usr/local/lib/python3.9/test/test_tempfile.py�test_infer_return_type_singles%sz4TestLowLevelInternals.test_infer_return_type_singlescCs�|�tt�dd��|�tt�dd��|�t��t�dd�Wd�n1sT0Y|�t��t�dd�Wd�n1s�0YdSr	�rr
rrr�assertRaises�	TypeErrorrrrr� test_infer_return_type_multiples*s*z6TestLowLevelInternals.test_infer_return_type_multiplescCs�|�tt�dd��|�tt�dd��|�tt�dd��|�tt�dd��|�tt�dd��|�t��t�ddd�Wd�n1s�0Y|�t��t�ddd�Wd�n1s�0YdSr	rrrrr�)test_infer_return_type_multiples_and_none2s,z?TestLowLevelInternals.test_infer_return_type_multiples_and_nonecCs|�tt�t�d���dS)N�/)rr
rr�pathlib�Pathrrrr�test_infer_return_type_pathlib=sz4TestLowLevelInternals.test_infer_return_type_pathlibcCsGdd�d�}|�tt�|d���|�tt�|d���|�tt�d|d���|�tt�d|d���|�tt�d|d���|�tt�d|d���|�t�� t�d|d��Wd�n1s�0Y|�t�� t�d|d��Wd�n1�s0YdS)Nc@seZdZdd�Zdd�ZdS)zCTestLowLevelInternals.test_infer_return_type_pathlike.<locals>.PathcSs
||_dS�N��path)rr!rrr�__init__BszLTestLowLevelInternals.test_infer_return_type_pathlike.<locals>.Path.__init__cSs|jSrr rrrr�
__fspath__EszNTestLowLevelInternals.test_infer_return_type_pathlike.<locals>.Path.__fspath__N)�__name__�
__module__�__qualname__r"r#rrrrrAsrr�/r
rr)rrrrr�test_infer_return_type_pathlike@s.z5TestLowLevelInternals.test_infer_return_type_pathlikeN)r$r%r&rrrrr(rrrrr$s
rc@s8eZdZe�d�Ze�d�Zdd�Zdd�Zdd�Z	d	S)
�BaseTestCasez^[a-z0-9_-]{8}$s^[a-z0-9_-]{8}$cCs*t��|_|j��tjdtdtd�dS)N�ignore�mktemp)�category�message�module)r�check_warnings�_warnings_manager�	__enter__�warnings�filterwarnings�RuntimeWarningr$rrrr�setUp[s


�zBaseTestCase.setUpcCs|j�ddd�dSr)r0�__exit__rrrr�tearDownaszBaseTestCase.tearDownc
Cs�tj�|�\}}|dt|��}|t|�t|�d�}|durn|�t|�t|�tusbt|tj�rftnt	d�|dur�|�t|�t|�tur�tnt	d�|dur�|�t|�t|�tur�tnt	d�|||fdkr�|�t|�td�|�
tj�|�tj�|�d||f�|�
||d||f�|�
||d||f�|t|�t|�t|��}t|t��rb|jn|j
}	|�|	�|�d||	jf�dS)Nzunexpected return type)NNNzdefault return type must be strzfile %r not in directory %rzfile %r does not begin with %rzfile %r does not end with %rz$random characters %r do not match %r)�osr!�split�lenr�typer
�
isinstance�PathLiker�assertEqual�abspath�	str_check�b_check�
assertTrue�match�pattern)
r�name�dir�pre�suf�ndir�nbaseZnpreZnsuf�checkrrr�	nameCheckdsN
�
����
�
�
���zBaseTestCase.nameCheckN)
r$r%r&�re�compiler@rAr5r7rLrrrrr)Vs


r)c@seZdZdd�ZdS)�TestExportscCsptj}ddddddddddddddd�}g}|D]"}|ddkr0||vr0|�|�q0|�t|�dkd|�dS)N�)�NamedTemporaryFile�
TemporaryFile�mkstemp�mkdtempr+�TMP_MAX�
gettempprefix�gettempprefixb�
gettempdir�gettempdirb�tempdir�template�SpooledTemporaryFile�TemporaryDirectoryr�_zunexpected keys: %s)r�__dict__�appendrBr:)r�dict�expectedZunexp�keyrrr�test_exports�s.��zTestExports.test_exportsN)r$r%r&rdrrrrrO�srOcsReZdZdZ�fdd�Zdd�Zdd�Zdd	�Ze�	e
ed
�d�dd
��Z�Z
S)�TestRandomNameSequencez6Test the internal iterator object _RandomNameSequence.cst��|_t���dSr)r�_RandomNameSequence�r�superr5r��	__class__rrr5�s
zTestRandomNameSequence.setUpcCst|j�}|�|ddd�dS�Nr
)�nextrgrL)r�srrr�test_get_six_char_str�s
z,TestRandomNameSequence.test_get_six_char_strcCsHi}|j}tt�D]0}t|�}|�|ddd�|�||�d||<qdS)Nr
rP)rg�range�
TEST_FILESrlrL�assertNotIn)rrarg�irmrrr�	test_many�sz TestRandomNameSequence.test_manycCs,d}|j}|D]}|d7}|dkrq(qdS)NrrP�)rg)rrrrgrmrrr�
supports_iter�sz$TestRandomNameSequence.supports_iter�forkz!os.fork is required for this testc
Cs�t��\}}d}z�t��}|sTt�|�t�|t|j��d��t�|�t�d�t|j�}t�	|t
|���d�}W|r�tj
|dd�t�|�t�|�n(|r�tj
|dd�t�|�t�|�0|�||�dS)N�asciir)�exitcode)r8�piperv�close�writerlrg�encode�_exit�readr:�decoderZwait_process�assertNotEqual)rZread_fdZwrite_fd�pidZparent_valueZchild_valuerrr�test_process_awareness�s(




�
z-TestRandomNameSequence.test_process_awareness)r$r%r&�__doc__r5rnrsru�unittest�
skipUnless�hasattrr8r��
__classcell__rrrirre�s
�rec@s eZdZdZdd�Zdd�ZdS)�TestCandidateTempdirListz3Test the internal function _candidate_tempdir_list.cCs4t��}|�t|�dk�|D]}|�|t�qdS�Nr)r�_candidate_tempdir_list�assertFalser:�assertIsInstancer
)r�cand�crrr�test_nonempty_list�sz+TestCandidateTempdirList.test_nonempty_listc
Cs�t����}dD]"}t�|�}|stj�|�||<qt��}dD]"}t�|�}|sTt�|�	||�q>zt�
�}Wnttfy�tj
}Yn0|�	||�Wd�n1s�0YdS)N)�TMPDIR�TEMP�TMP)r�EnvironmentVarGuardr8�getenvr!r?rr��
ValueError�assertIn�getcwd�AttributeError�OSError�curdir)r�env�envname�dirnamer�rrr�test_wanted_dirs�s


z)TestCandidateTempdirList.test_wanted_dirsN)r$r%r&r�r�r�rrrrr��s	r�c@seZdZdZdd�ZdS)�TestGetDefaultTempdirzTest _get_default_tempdir().cs�t����f��fdd�}t�td|���(t��|�t���g�dd��t�td���T|�	t
��t��Wd�n1s�0Y|�t���g�Wd�n1s�0Y��fdd�}t�td|��V�|�	t
��t��Wd�n1�s0Y|�t���g�Wd�n1�s80YWd�n1�sX0YWd�n1�sx0YdS)	Ncs�gSrrr)�our_temp_directoryrr�our_candidate_listszKTestGetDefaultTempdir.test_no_files_left_behind.<locals>.our_candidate_listr�c_s
t��dSr)r�)�args�kwargsrrr�
raise_OSError!szFTestGetDefaultTempdir.test_no_files_left_behind.<locals>.raise_OSError�opencs�|i|��}�|_|Sr)r{)r�r��fp)�	orig_openr�rr�
bad_writer*szCTestGetDefaultTempdir.test_no_files_left_behind.<locals>.bad_writer)rr]r�	swap_attr�_get_default_tempdirr>r8�listdir�ior�FileNotFoundError)rr�r�r)r�r�r�r�test_no_files_left_behinds"�&0(z/TestGetDefaultTempdir.test_no_files_left_behindN)r$r%r&r�r�rrrrr�sr�c@s eZdZdZdd�Zdd�ZdS)�TestGetCandidateNamesz0Test the internal function _get_candidate_names.cCst��}|�|tj�dSr)r�_get_candidate_namesr�rf)r�objrrr�test_retval9sz!TestGetCandidateNames.test_retvalcCs"t��}t��}|�||u�dSr)rr�rB)r�a�brrr�test_same_thing>sz%TestGetCandidateNames.test_same_thingN)r$r%r&r�r�r�rrrrr�6sr�c	cs\t��}zBt�td|��dVWd�n1s40YWt�|�nt�|�0dS)NrZ)rrTrr��rmtree�rFrrr�_inside_empty_temp_dirFs
&r�cst�td�fdd��S)Nr�cst��Sr)�iterr��namesrr�<lambda>Srz'_mock_candidate_names.<locals>.<lambda>)rr�rr�rr�r�_mock_candidate_namesPs
�r�c@s$eZdZdd�Zdd�Zdd�ZdS)�TestBadTempdircCs�t���t�tj�j}}|tjtjBtjBM}t�	tj|�zrt�
tjtj�r\|�d�|�
t��|��Wd�n1s�0Y|�t�tj�g�Wt�	tj|�nt�	tj|�0Wd�n1s�0YdS)Nz!can't set the directory read-only)r�r8�statrrZ�st_mode�S_IWUSR�S_IWGRP�S_IWOTH�chmod�access�W_OK�skipTestr�PermissionError�	make_tempr>r�)rZoldmode�moderrr�test_read_only_directoryXs
&z'TestBadTempdir.test_read_only_directoryc
Cs�t���tj�tjd�}t�td|��B|�t	��|�
�Wd�n1sP0YWd�n1sn0YWd�n1s�0YdS)N�nonexistentrZ)r�r8r!�joinrrZrr�rr�r��rrZrrr�test_nonexisting_directoryfs
z)TestBadTempdir.test_nonexisting_directoryc
Cs�t���tj�tjd�}t|d���t�	td|��F|�
ttf��|�
�Wd�n1sb0YWd�n1s�0YWd�n1s�0YdS)N�file�wbrZ)r�r8r!r�rrZr�rzrr�r�NotADirectoryErrorr�r�r�rrr�test_non_directorymsz!TestBadTempdir.test_non_directoryN)r$r%r&r�r�r�rrrrr�Vsr�c@s�eZdZdZGdd�d�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
e�e
d�dd��Ze�ed�dd��Zdd�Zdd�Zdd�ZdS)�TestMkstempInnerz*Test the internal function _mkstemp_inner.c@s<eZdZejZejZej	Z
ejZdd�Z
dd�Zdd�ZdS)zTestMkstempInner.mkstempedcCs>|r|j}n|j}t�|||�}t�|||||�\|_|_dSr)�_bflags�_tflagsrr�_mkstemp_inner�fdrE)rrFrGrH�bin�flags�output_typerrrr"sz#TestMkstempInner.mkstemped.__init__cCst�|j|�dSr)r8r{r�)rr
rrrr{�sz TestMkstempInner.mkstemped.writecCs|�|j�|�|j�dSr)�_closer��_unlinkrErrrr�__del__�sz"TestMkstempInner.mkstemped.__del__N)r$r%r&r�_bin_openflagsr��_text_openflagsr�r8rzr��unlinkr�r"r{r�rrrr�	mkstempedysr�NrPcCsrt�|||�}|dur0|tur(t��}nt��}|dur>|�}|durL|�}|�||||�}|�|j|||�|Sr)rrr
rXrYr�rLrE)rrFrGrHr�r�r�rrr�	do_create�s
zTestMkstempInner.do_createcCs^|���d�|jdd��d�|jdd��d�|jddd��d�|jddd��d�dS)	N�blatr��rGr��rH�rGrH�aa�.txt)r�r{rrrr�
test_basic�s
zTestMkstempInner.test_basiccCs2t��}|j|dd��d�|j|dd��d�|j|dd��d�|j|ddd��d�|j|dd	d��d�|�t��$|jd
dd��d�Wd�n1s�0Y|�t��$|j|d
d��d�Wd�n1s�0Y|�t��&|j|dd
d��d�Wd�n1�s$0YdS)Nr�rFrHr��a�rFrG�b�rFrGrH�aa�.txtr
)rrYr�r{rr)rZdir_brrr�test_basic_with_bytes_names�s22z,TestMkstempInner.test_basic_with_bytes_namescCs*ttt��}|D]}|jdd�||<qdS�Nr�r�)�listrorpr��rZextantrrrrr�test_basic_many�sz TestMkstempInner.test_basic_manyc	Csbt��}z@|j|d��d�|jt�|�d��d�Wt��t�	|�nt��t�	|�0dS�Nr�r�)
rrTr�r{rrr�
gc_collectr8�rmdir�rrFrrr�test_choose_directory�s�z&TestMkstempInner.test_choose_directorycCsJ|��}t�t�|j�j�}d}tjdkr:|d?}|d}|�||�dS)N��win32��I)	r�r��S_IMODEr8rEr��sys�platformr>)rr�r�rb�userrrr�test_file_mode�s
zTestMkstempInner.test_file_modezos.spawnl not availablecCs�tjrd}nd}|��}|�t�|j�d�d|j}zt}WntyZt	j
d}Yn0tj�tj�
tj�|��d�}t	jdkr�dt	j}d|}nt	j}t�tjt	j||||�}|�|dkd	|�|�|dkd
|�dS)N�v�qFz%drztf_inherit_check.pyr�z"%s"z$child process caught fatal signal %dz child process reports failure %d)r�verboser�r>r8�get_inheritabler��__file__�	NameErrorr�argvr!r�r�r?r�
executabler�P_WAITr�)rrr�r��meZtesterZ	decoratedZretvalrrr�test_noinherit�s,
�



�zTestMkstempInner.test_noinheritztext mode not availablecCsL|jdd�}|�d�|�d�t�|jdtj�|�t�|jd�d�dS)Nr)r�sblatsextra
rtr�)r�r{r8�lseekr��SEEK_SETr>r~�r�frrr�
test_textmode�s


zTestMkstempInner.test_textmodecCst�t��t��dtjt�Srk)rr�rXrVr�r
rrrrr�s
�zTestMkstempInner.make_tempc	Cs�t���tddd��\|��\}}t�|�|�|�d��|��\}}t�|�|�|�d��Wd�n1sv0YWd�n1s�0YdS�N�aaa�bbb)r�r�r�r8rzrB�endswith)r�fd1Zname1�fd2Zname2rrr�!test_collision_with_existing_files
�

z2TestMkstempInner.test_collision_with_existing_filec	Cs�t��ztddd��Nt��}|�|�d��|��\}}t�|�|�|�d��Wd�n1sh0YWd�n1s�0YdSr)	r�r�rrTrBrr�r8rz)rrFr�rErrr�&test_collision_with_existing_directorys
�
z7TestMkstempInner.test_collision_with_existing_directory)NNNrP)r$r%r&r�r�r�r�r�r�r�rr�r��
has_spawnlr�has_textmoderr�rrrrrrr�vs



%



r�c@s eZdZdZdd�Zdd�ZdS)�TestGetTempPrefixzTest gettempprefix().cCsLt��}|�|t�|�t|�d�t��}|�|t�|�t|�d�dSr�)rrVr�r
Z
assertGreaterr:rWr)r�pZpbrrr�test_sane_template(sz$TestGetTempPrefix.test_sane_templatec	Csnt��d}tjdd�}zDtj�||�}t�|tjtjB�}t�	|�t�
|�Wt�|�nt�|�0dS)Nz
xxxxxx.xxxr
)�prefix)rrVrTr8r!r�r��O_RDWR�O_CREATrzr�r�)rr �dr�rrr�test_usable_template4s
z&TestGetTempPrefix.test_usable_templateN)r$r%r&r�r!r&rrrrr%src@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�TestGetTempDirzTest gettempdir().cCsTt��t��fD]>}|�tj�|�p,|tjkd|�|�tj�|�d|�qdS)Nz%r is not an absolute pathz%r is not a directory)	rrXrYrBr8r!�isabsr��isdir�rr%rrr�test_directory_existsHs��z$TestGetTempDir.test_directory_existscCs6t���}|�d�Wd�n1s(0YdS)Nr�)rrQr{)rr�rrr�test_directory_writableQs
z&TestGetTempDir.test_directory_writablecCsPt��}t��}t��}|�||u�|�t|�t|��|�|t�|��dSr)	rrXrYrBr�r;r>r8�fsdecode)rr�r�r�rrrr�ZszTestGetTempDir.test_same_thingc	Cs�t�d�}tjd}t_zTt���(}||d<|�t��|�Wd�n1sP0YW|t_t�|�n|t_t�|�0dS)Nz-Tempr�)rrTrZrr�r>rXr�)rZcase_sensitive_tempdirZ_tempdirr�rrr�test_case_sensitiveds

0�z"TestGetTempDir.test_case_sensitiveN)r$r%r&r�r+r,r�r.rrrrr'Es
		
r'c@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)�TestMkstempzTest mkstemp().Nc
	Cs�t�|||�}|dur0|tur(t��}nt��}|dur>|�}|durL|�}tj|||d�\}}tj�|�\}}tj�	|�}	|�
|	|d|	|f�z(|�||||�Wt�|�t�
|�nt�|�t�
|�0dS)N�rFr"�suffixz+Directory '%s' incorrectly returned as '%s')rrr
rXrYrSr8r!r9r?r>rLrzr�)
rrFrGrHr�r�rErIrJZadirrrrr�vs*

�
�
zTestMkstemp.do_createcCsL|��|jdd�|jdd�|jddd�|jddd�|jdd	�dS)
Nr�r�r�r�r�r�r��.r��r�rrrrr��szTestMkstemp.test_basiccCst��}|j|dd�|j|dd�|j|dd�|j|ddd�|j|ddd�|jd	d
�|�t�� |jdddd�Wd�n1s�0Y|�t�� |jd	ddd�Wd�n1s�0Y|�t�� |jd	dd
d�Wd�n1�s0YdS)Nrr�r�r�r�r�r�r��.r�r2r�r�)rrYr�rrr*rrrr��s..z'TestMkstemp.test_basic_with_bytes_namesc	CsFt��}z,|j|d�|jt�|�d�Wt�|�nt�|�0dS�Nr�)rrTr�rrr8r�r�rrrr��s
z!TestMkstemp.test_choose_directory)NNN)r$r%r&r�r�r�r�r�rrrrr/ss

	r/c@steZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
e�e
jdkd�dd��Zdd�Zdd�ZdS)�TestMkdtempzTest mkdtemp().cCst��Sr)rrTrrrrr��szTestMkdtemp.make_tempNcCs�t�|||�}|dur0|tur(t��}nt��}|dur>|�}|durL|�}tj|||d�}z|�||||�|WSt�|��Yn0dS�Nr0)	rrr
rXrYrTrLr8r�)rrFrGrHr�rErrrr��s 

zTestMkdtemp.do_createcCs^t�|���t�|jdd��t�|jdd��t�|jddd��t�|jddd��dS�Nr�r�r�r�r�r�r�)r8r�r�rrrrr��s
zTestMkdtemp.test_basiccCs4t��}t�|j|d��t�|j|dd��t�|j|dd��t�|j|ddd��t�|j|ddd��|�t��&t�|j|d	dd��Wd�n1s�0Y|�t��&t�|j|dd
d��Wd�n1s�0Y|�t��&t�|jdddd��Wd�n1�s&0YdS)Nr�r�r�r�r�r�r�r�r�r�r
)rrYr8r�r�rrr*rrrr��s44z'TestMkdtemp.test_basic_with_bytes_namesc
Csnttt��}z<|D]}|jdd�||<qW|D]}t|t�r.t�|�q.n |D]}t|t�rNt�|�qN0dSr�)r�rorpr�r<r
r8r�r�rrrr��s
�
zTestMkdtemp.test_basic_manyc	CsRt��}z8t�|j|d��t�|jt�|�d��Wt�|�nt�|�0dSr5)rrTr8r�r�rrr�rrrr��s
z!TestMkdtemp.test_choose_directoryc	Csl|��}zRt�t�|�j�}|dM}d}tjdkrB|d?}|d}|�||�Wt�|�nt�|�0dS)Ni�i�r�r�r�)	r�r�rr8r�rrr>r�)rrFr�rbrrrr�	test_mode�s
zTestMkdtemp.test_mode�ntzOnly on Windows.c	Cs�|��}z$tjd|gdd���}Wt�|�nt�|�0|��}t�}d}|����D]V}d}|�	|�rz|�
|���}n|r�|dd���r�|��}|rX|�|�
d�d�qX|�d��|�dS)	Nz
icacls.exeZoem��encodingFrP�:rz
BUILTIN\Users)r��
subprocess�check_output�casefoldr8r��set�strip�
splitlines�
startswith�removeprefix�isspace�add�	partitionrq)rrF�outZusersZ
found_user�lineZaclrrr�test_mode_win32s 
zTestMkdtemp.test_mode_win32c	Cs�t��ztddd��Ntjdd�}|��|�|j�d��t��}|�|�d��Wd�n1sh0YWd�n1s�0YdS)NrrF)�delete)	r�r�rrQrzrBrErrT)rr�rFrrrr#s
�z-TestMkdtemp.test_collision_with_existing_filec	Cs�t��ltddd��@t��}|�|�d��t��}|�|�d��Wd�n1sZ0YWd�n1sx0YdSr)r�r�rrTrBr)r�dir1Zdir2rrrr.s
�z2TestMkdtemp.test_collision_with_existing_directory)NNN)r$r%r&r�r�r�r�r�r�r�r9r�r�r8rErKrrrrrrr6�s
	
r6csTeZdZdZ�fdd�Z�fdd�ZGdd�d�Zdd	d
�Zdd�Zd
d�Z	�Z
S)�
TestMktempzTest mktemp().cst��|_t���dSr)rrTrFrhr5rrirrr5>s
zTestMktemp.setUpcs&|jrt�|j�d|_t���dSr)rFr8r�rhr7rrirrr7BszTestMktemp.tearDownc@s(eZdZejZejZdd�Z	dd�Z
dS)zTestMktemp.mktempedcCs.tj|||d�|_t�t�|j|jd��dS)Nr0r�)rr+rEr8rzr�r�)rrFrGrHrrrr"LszTestMktemp.mktemped.__init__cCs|�|j�dSr)r�rErrrrr�RszTestMktemp.mktemped.__del__N)r$r%r&r8r�r�rr�r�r"r�rrrr�mktempedHsrOr
cCs(|�|j||�}|�|j|j||�|Sr)rOrFrLrE)rrGrHr�rrrr�UszTestMktemp.do_createcCs@|��|jdd�|jdd�|jddd�|jddd�dSr8r3rrrrr�[s
zTestMktemp.test_basiccCs4ttt��}|D]}|jdd�||<q~t��dSr�)r�rorpr�rr�r�rrrrscs
zTestMktemp.test_many)r
r
)r$r%r&r�r5r7rOr�r�rsr�rrrirrN9s
rNc@sjeZdZdZddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestNamedTemporaryFilezTest NamedTemporaryFile().Nr
TcCs8|durt��}tj||||d�}|�|j|||�|S)N)rFr"r1rL)rrXrQrLrE)rrFrGrHrLr�rrrr�zs
�z TestNamedTemporaryFile.do_createcCs@|��|jdd�|jdd�|jddd�|jddd�dSr8r3rrrrr��s
z!TestNamedTemporaryFile.test_basiccCsP|��}t�|�}|j}|j}~|d�~|d�~tjdd�rL|�|��dS)NsfoosbarT)Zcpython)r��weakref�refr{rZcheck_impl_detail�assertIsNone)rr�wrr{Zwrite2rrr�test_method_lookup�s
z)TestNamedTemporaryFile.test_method_lookupcsPgd���fdd�}t|��D]\}}|�|�|�q|�|t��d�dS)N)sspam
seggs
sbeans
cs*tjdd�}|�d����|�d�|S)N�w+b�r�rr)rrQr{r��seek�r��linesrr�	make_file�s
z3TestNamedTemporaryFile.test_iter.<locals>.make_filerP)�	enumerater>r:)rr\rr�lrrZr�	test_iter�s
z TestNamedTemporaryFile.test_itercCs(t��}|�tj�|j�d|j�dS)Nz$NamedTemporaryFile %s does not exist)rrQrBr8r!�existsrErrrr�test_creates_named�s�z)TestNamedTemporaryFile.test_creates_namedc	Cszt��}z`tj|d��}|�d�Wd�n1s60Y|�tj�|j�d|j�Wt�	|�nt�	|�0dS)Nr�r�z(NamedTemporaryFile %s exists after close)
rrTrQr{r�r8r!r`rEr��rrFrrrr�test_del_on_close�s(�z(TestNamedTemporaryFile.test_del_on_closec	Cs�t��}d}zbtj|dd�}|j}|�d�|��|�tj�	|j�d|j�W|durdt�
|�t�|�n|dur�t�
|�t�|�0dS)NF)rFrLr�z)NamedTemporaryFile %s missing after close)rrTrQrEr{rzrBr8r!r`r�r�)rrF�tmprrrr�test_dis_del_on_close�s 
�
�
z,TestNamedTemporaryFile.test_dis_del_on_closecCs.t��}|�d�|��|��|��dS�N�abc
)rrQr{rzrrrr�test_multiple_close�s

z*TestNamedTemporaryFile.test_multiple_closecslt���$�|�tj��j��Wd�n1s20Y|�tj��j���fdd�}|�t	|�dS)Ncs(��Wd�n1s0YdSrrrrYrr�
use_closed�sz?TestNamedTemporaryFile.test_context_manager.<locals>.use_closed)
rrQrBr8r!r`rEr�rr��rrirrYr�test_context_manager�s

2z+TestNamedTemporaryFile.test_context_managerc	s�g�tj���fdd�}tjd|d��\tjdtd��.|�ttj�|�t	��d�Wd�n1sj0YWd�n1s�0YdS)Ncs��|��|�dSr�r`�r���closedZos_closerrrz�s
z5TestNamedTemporaryFile.test_no_leak_fd.<locals>.close�os.close�Zside_effect�io.openrP)
r8rzr�patchr�rrrQr>r:�rrzrrnr�test_no_leak_fd�sz&TestNamedTemporaryFile.test_no_leak_fdcCs�t��}|�tj|�|�t��tjd|d�Wd�n1sD0Y|�t��tjd|d�Wd�n1s|0Y|�	t
�|�g�dS)NrT)r�rF�)rrTZ
addCleanuprr�rr�rQrr>r8r�r�rrr�
test_bad_mode�s,,z$TestNamedTemporaryFile.test_bad_mode)Nr
r
T)r$r%r&r�r�r�rUr_rarcrerhrkrurwrrrrrPws




rPc@s�eZdZdZd-dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZdS).�TestSpooledTemporaryFilezTest SpooledTemporaryFile().rNr
cCs&|durt��}tj||||d�}|S)N)�max_sizerFr"r1)rrXr\)rryrFrGrHr�rrrr��sz"TestSpooledTemporaryFile.do_createcCs4|��}|�|j�|jdddd�}|�|j�dS)Nrr�r�)ryrGrH)r�r��_rolledrrrrr��sz#TestSpooledTemporaryFile.test_basicc	Cs�t��}zntjd|d�}|�|j�|�d�|�|j�|j}|��|�t	|t
�o`tj�
|�d|�Wt�|�nt�|�0dS)N�
)ryrFsblat blat blat blat blat z*SpooledTemporaryFile %s exists after close)rrTr\r�rzr{rBrErzr<r
r8r!r`r�)rrFr�filenamerrrrcs
�z*TestSpooledTemporaryFile.test_del_on_closecCsL|jdd�}|�|j�td�D]}|�dd�|�d�q |�|j�dS)N��ry�r�xxxxxxxxxxxxxxxxxxxx)r�r�rzrorXr{)rrrrrrr�test_rewrite_smallsz+TestSpooledTemporaryFile.test_rewrite_smallcCs^|jdd�}|�|j�|�d�|�|j�|�d�|�|j�|�d�|�|j�dS)Nr}r~r��
xxxxxxxxxx�x)r�r�rzr{rBrrrr�test_write_sequentials


z.TestSpooledTemporaryFile.test_write_sequentialcCs@|��}|�d�|�d�}|�|d�|��}|�|d�dS)N)r��y�zrsxyz)r��
writelinesrXr>r~)rr�pos�bufrrr�test_writelines*s

z(TestSpooledTemporaryFile.test_writelinescCs<|jdd�}|�d�|�|j�|�d�|�|j�dS)N�#r~)r�r�sxxxxxr�)r�r�r�rzr{rBrrrr�test_writelines_sequential3s


z3TestSpooledTemporaryFile.test_writelines_sequentialcCsV|jdd�}|�|j�|�dd�}|�|d�|�|j�|�d�|�|j�dS)Nr}r~rrr�)r�r�rzrXr>r{rB)rrr�rrr�test_sparse<s
z$TestSpooledTemporaryFile.test_sparsecCs:|jdd�}|�|j�|�|��dk�|�|j�dS)Nr}r~r)r�r�rzrB�filenorrrr�test_filenoGsz$TestSpooledTemporaryFile.test_filenocCs:t��}|�d�|�|j�|��|��|��dSrf)rr\r{r�rzrzrrrr�#test_multiple_close_before_rolloverNs
z<TestSpooledTemporaryFile.test_multiple_close_before_rollovercCs>tjdd�}|�d�|�|j�|��|��|��dS)NrPr~rg)rr\r{rBrzrzrrrr�"test_multiple_close_after_rolloverWs
z;TestSpooledTemporaryFile.test_multiple_close_after_rollovercCsL|jdd�}|j}|j}|j}|d�|d�|dd�|�|d�d�dS)Nr}r~s#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas#bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbr�FsFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)r�r~r{rXr>)rrr~r{rXrrr�test_bound_methods`s
z+TestSpooledTemporaryFile.test_bound_methodscCs�tjdd�}|�d�|�|j�|�|jd�|�|j�|�	t
��|jWd�n1sb0Y|�	t
��|jWd�n1s�0Y|�	t
��|j
Wd�n1s�0Y|�d�|�|j�|�|jd�|�|j�|�	t
��|jWd�n1�s$0Y|�	t
��|jWd�n1�sV0Y|�	t
��|j
Wd�n1�s�0YdS)Nr{r~r�rVr�zrb+)rr\r{r�rzr>r�rSrErr��newlinesr<�errorsrB�assertIsNotNonerrrr�test_propertiesns*
$$$
&&z(TestSpooledTemporaryFile.test_propertiescCsHtjdddd�}|�d�|�d�|�|��d�|�d�|�d�|�|��d�|�|j�|�|jd�|�	|j
�|�|jtj
�|�|jd�|�|jd	�|�d
�|�d�|�|��d�|�d�|�d�|�|��d
�|�|j�|�|jd�|�|j
�|�|jtj
�|�|jd�|�|jd	�dS)N�w+r{�utf-8)r�ryr<zabc
rzdef
zabc
def
�strictzxyzzy
zabc
def
xyzzy
zfoobar
zabc
def
xyzzy
foobar
)rr\r{rXr>r~r�rzr�rSrEr�r8�linesepr<r�rBr�rrrr�test_text_mode�s6�







z'TestSpooledTemporaryFile.test_text_modecCstjdddddd�}|�d�|�d�|�|��d�|�|j�|�|jd�|�	|j
�|�|j�|�|j
d�|�|jd�|�d	�|�d
�|�d�|�|��d�|�|j�|�|jd�|�|j
�|�|j�|�|j
d�|�|jd�dS)Nr�r{r
r�r*)r�ry�newliner<r�uΛ
ruΜΜΜΜΜΜΜΜΜΜ
u(ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝuBΛ
ΜΜΜΜΜΜΜΜΜΜ
ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ)rr\r{rXr>r~r�rzr�rSrEr�r�r<r�rBrrrr�test_text_newline_and_encoding�s2�





�z7TestSpooledTemporaryFile.test_text_newline_and_encodingcsltjdd��(�|��j�|��j�Wd�n1s:0Y|��j��fdd�}|�t|�dS)NrPr~cs(��Wd�n1s0YdSrrrrYrrri�szQTestSpooledTemporaryFile.test_context_manager_before_rollover.<locals>.use_closed)rr\r�rzrorBrr�rjrrYr�$test_context_manager_before_rollover�s*z=TestSpooledTemporaryFile.test_context_manager_before_rollovercs�tjdd��F�|��j���d����|��j�|��j�Wd�n1sX0Y|��j��fdd�}|�t	|�dS)NrPr~rgcs(��Wd�n1s0YdSrrrrYrrri�szQTestSpooledTemporaryFile.test_context_manager_during_rollover.<locals>.use_closed)
rr\r�rzr{�flushrBrorr�rjrrYr�$test_context_manager_during_rollover�s
*z=TestSpooledTemporaryFile.test_context_manager_during_rollovercs�tjdd����d����|��j���|��j�Wd�n1sP0Y|��j��fdd�}|�t	|�dS)NrPr~rgcs(��Wd�n1s0YdSrrrrYrrri�szPTestSpooledTemporaryFile.test_context_manager_after_rollover.<locals>.use_closed)
rr\r{r�rBrzr�rorr�rjrrYr�#test_context_manager_after_rollover�s
*z<TestSpooledTemporaryFile.test_context_manager_after_rollovercCs�tjdd�}|�d�|�d�|��|�|j�|�|j�	�d�tjdd�}|�d�|�d�|�|j�|�|j�	�d�tjdd�}|�d�|�d�|�
|j�|�t�|�
��jd�dS)	Nr{r~sabcdefg
rr�sabcdrt)rr\r{rX�truncater�rzr>�_file�getvaluerBr8�fstatr��st_sizerrrr�!test_truncate_with_size_parameter�s 





z:TestSpooledTemporaryFile.test_truncate_with_size_parametercCs|�tjttj�dSr)r�rr\r�types�GenericAliasrrrr�test_class_getitem�s�z+TestSpooledTemporaryFile.test_class_getitem)rNr
r
)r$r%r&r�r�r�rcr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrx�s*
					 rxc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�TestTemporaryFilezTest TemporaryFile().cCst��dSr)rrRrrrrr�szTestTemporaryFile.test_basiccCsRt��}tj|d�}|�d�zt�|�Wn |��t�|��Yn0dSr�)rrTrRr{r8r�rzrbrrr�test_has_no_name
s

z"TestTemporaryFile.test_has_no_namecCs.t��}|�d�|��|��|��dSrf)rrRr{rzrrrrrhs

z%TestTemporaryFile.test_multiple_closecs@�fdd�}|dd�|dd�|dddd	�|d
ddd�dS)
NcsXtj|i|���4}|�|�|�d���||���Wd�n1sJ0YdSr�)rrRr{rXr>r~)�inputr�r��fileobjrrr�	roundtrip%s

z;TestTemporaryFile.test_mode_and_encoding.<locals>.roundtrips1234rVzabdc
r�uΛzutf-16r;zfoo
r
)r�r)rr�rrr�test_mode_and_encoding#s


z(TestTemporaryFile.test_mode_and_encodingc	s�g�tj���fdd�}tjd|d��\tjdtd��.|�ttj�|�t	��d�Wd�n1sj0YWd�n1s�0YdS)Ncs��|��|�dSrrlrmrnrrrz4s
z0TestTemporaryFile.test_no_leak_fd.<locals>.closerprqrrrP)
r8rzrrsr�rrrRr>r:rtrrnrru0sz!TestTemporaryFile.test_no_leak_fdN)	r$r%r&r�r�r�rhr�rurrrrr�s	
r�c@s$eZdZdd�Zdd�Zdd�ZdS)�
NulledModulescGs&dd�|D�|_dd�|jD�|_dS)NcSsg|]
}|j�qSr)r_)�.0�modrrr�
<listcomp>Brz*NulledModules.__init__.<locals>.<listcomp>cSsg|]}|���qSr)�copy)r�rRrrrr�Cr)�refs�contents)r�modulesrrrr"AszNulledModules.__init__cCs"|jD]}|D]}d||<qqdSr)r�)rr%rcrrrr1Es
zNulledModules.__enter__cGs.t|j|j�D]\}}|��|�|�qdSr)�zipr�r��clear�update)r�exc_infor%r�rrrr6JszNulledModules.__exit__N)r$r%r&r"r1r6rrrrr�@sr�c@s�eZdZdZd'dd�Zd(dd�Zd	d
�Zdd�Zej	d
d��Z
ej	dd��Ze�
eed�d�ej	dd���Zejdd��Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Ze�
eed�d�d%d&��ZdS))�TestTemporaryDirectoryzTest TemporaryDirectory().Nr
rPcCsH|durt��}tj|||d�}|�|j|||�|�|j|||�|Sr7)rrXr]rLrE�
do_create2)rrFrGrH�recurse�dirs�filesrdrrrr�Rsz TestTemporaryDirectory.do_createc	Cs�|rBt|�D]4}tj�|d|�}t�|�|�||d||�qt|�D]F}ttj�|d|�d��}|�d�Wd�qJ1s�0YqJdS)Nzdir%drPz
test%d.txtr�sHello world!)ror8r!r��mkdirr�r�r{)rr!r�r�r�rrrErrrrr�Zs
z!TestTemporaryDirectory.do_create2cCstt���}Wd�n1s0Y|�t��}tj|d�Wd�n1sT0Y|�|jjtj�dSr5)rr]rr�r>�	exception�errno�ENOENT)rr��cmrrr�test_mkdtemp_failurees

*z+TestTemporaryDirectory.test_mkdtemp_failurec	Cstt��}zZ|j|d�}|�tj�|j�d|j�|��|�	tj�|j�d|j�Wt�
|�nt�
|�0dS)Nr�z$TemporaryDirectory %s does not exist�*TemporaryDirectory %s exists after cleanup)rrTr�rBr8r!r`rE�cleanupr�r�)rrFr%rrr�test_explicit_cleanupos��z,TestTemporaryDirectory.test_explicit_cleanupcCs�|��}|jdd�}t�|jtj�|jd��|��|�tj�|j�d|j�|�	tj�|j�d�|�
t�|j�dgd�|��dS)Nr�r�Zfoor�z-Directory pointed to by a symlink was deletedz	test0.txtz>Contents of the directory pointed to by a symlink were deleted)r�r8�symlinkrEr!r�r�r�r`rBr>r�)r�d1�d2rrr�(test_cleanup_with_symlink_to_a_directory|s���z?TestTemporaryDirectory.test_cleanup_with_symlink_to_a_directorycs�jdd����}tj�|d�}t|d���tj�|d�}t�|�td�D�]���dK��jt	�d�d	���n��fd
d�}��d��|d
dd�Wd�n1s�0Y��d��|d
dd�Wd�n1s�0Y��d��Vt�
|��t�|�j}||dd�t�|�j}��
||d||f�Wd�n1�sR0Y��d��Vt�
|��t�|�j}||dd�t�|�j}��
||d||f�Wd�n1�s�0YWd�qL1�s�0YqLWd�n1�s0YdS)Nrr��file1r�rM�r��03orWcs��jdd�}tj�|jd�}tj|||d�ztj|�dd�WntyRYn0zt�|��WntyvYn0t�|j��|�	���
tj�|j��dS�Nrr�r���target_is_directoryF)�follow_symlinks)r�r8r!r�rEr�r��NotImplementedErrorr�r�r�r`��targetr�r�r��r�rrr�test�s �zDTestTemporaryDirectory.test_cleanup_with_symlink_modes.<locals>.test�nonexisting file�nonexistingFr��nonexisting dirT�
existing filez%03o != %03o�existing dir)r�r8r!r�r�rzr�ro�subTest�formatr�r�r�r>)rr�r�rMr�Zold_modeZnew_moderr�r�test_cleanup_with_symlink_modes�s:
**
�$
�z6TestTemporaryDirectory.test_cleanup_with_symlink_modes�chflagszrequires os.chflagsc	s�tjtjB������jdd����}tj�|d�}t|d��	�tj�|d�}t�
|���fdd�}��d��|d	d
d�Wd�n1s�0Y��d��|d	d
d�Wd�n1s�0Y��d��Lt�|��t�|�j
}||d
d�t�|�j
}��||�Wd�n1�s20Y��d��Lt�|��t�|�j
}||d
d�t�|�j
}��||�Wd�n1�s�0YWd�n1�s�0YdS)Nrr�r�r�rMcs��jdd�}tj�|jd�}tj|||d�ztj|�dd�WntyRYn0zt�|��WntyvYn0t�|j��|�	���
tj�|j��dSr�)r�r8r!r�rEr�r�r�r�r�r�r`r��r�rrrr��s �zDTestTemporaryDirectory.test_cleanup_with_symlink_flags.<locals>.testr�r�Fr�r�Tr�r�)r��UF_IMMUTABLE�UF_NOUNLINK�check_flagsr�r8r!r�r�rzr�r�r��st_flagsr>)rr�r�rMr�Z	old_flagsZ	new_flagsrr�r�test_cleanup_with_symlink_flags�s0

**,z6TestTemporaryDirectory.test_cleanup_with_symlink_flagsc	CsTt��}z:|j|d�}|j}~|�tj�|�d|�Wt�|�nt�|�0dS)Nr��*TemporaryDirectory %s exists after __del__)	rrTr�rEr�r8r!r`r��rrFr%rErrr�test_del_on_collection�s�z-TestTemporaryDirectory.test_del_on_collectioncCs�|����}dD]l}dj||d�}t�d|�\}}}|����}|�tj�	|�d|�|�dd�}|�
d|�|�d	|�qWd�n1s�0YdS)
N)�builtinsr8�shutilrrr2a�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)
                    )rFr��-cr�r��backslashreplace�
Exception �'ResourceWarning: Implicitly cleaning up�r�r�rZassert_python_okrrBr�r8r!r`rqr�)rrFr��code�rcrI�err�tmp_namerrr�test_del_on_shutdown�s
��z+TestTemporaryDirectory.test_del_on_shutdowncCs�|���v}dj|d�}t�d|�\}}}|����}|�tj�	|�d|�|�dd�}|�
d|�|�d|�Wd�n1s�0YdS)	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�r�r�r�r�r�)rrFr�r�rIr�r�rrr�test_exit_on_shutdowns
�
�z,TestTemporaryDirectory.test_exit_on_shutdownc	Cs�|����}|j|dd�}|j}tjdtfdd��(tjdtd�~t��Wd�n1s^0Y|�t	j
�|�d|�Wd�n1s�0YdS)	N�)rFr�Z
ImplicitlyF)�quiet�always)r,r�)r�rErr/�ResourceWarningr2r3r�r�r8r!r`r�rrr�test_warnings_on_cleanup7s
&�z/TestTemporaryDirectory.test_warnings_on_cleanupcCs$|��}|��|��|��dSr)r�r�r*rrrrhEsz*TestTemporaryDirectory.test_multiple_closecCsb|��}|�0}|�tj�|��|�||j�Wd�n1sB0Y|�tj�|��dSr)r�rBr8r!r`r>rEr�)rr%rErrrrkLs
,z+TestTemporaryDirectory.test_context_managercCs�td�D]�}|dK}|jt|d�d���|jdddd�}|�`tj|jdd	�D]6\}}}|D]}t�tj�	||�|�q\t�||�qN|�
�Wd�n1s�0Y|�tj�|j��Wd�q1s�0YqdS)
Nr�r�r�rWr�rv�r�r�r�F��topdown)
ror�r�r�r8�walkrEr�r!r�r�r�r`)rr�r%�rootr�r�rErrr�
test_modesTs&z!TestTemporaryDirectory.test_modesc
Cs�tj}zvt|d���zt�||�Wn<tyb}z$|�d|d�d|���WYd}~nd}~00t�|d�Wt�|�nt�|�0dS)N�wz chflags() doesn't support flags z#bz: r)	rZTESTFNr�rzr8r�r�r�r�)rr�r|�excrrrr�bs��z"TestTemporaryDirectory.check_flagsc	Cs�tjtjB}|�|�|jdddd�}|�`tj|jdd�D]6\}}}|D]}t�tj	�
||�|�qJt�||�q<|��Wd�n1s�0Y|�tj	�
|j��dS)Nr�rvrFr)r�r�r�r�r�r8rrEr�r!r�r�r�r`)rr�r%rr�r�rErrr�
test_flagsrs
&z!TestTemporaryDirectory.test_flags)Nr
r
rPrPrP)rPrPrP)r$r%r&r�r�r�r�r�rZskip_unless_symlinkr�r�r�r�r�r8r�Zcpython_onlyr�r�r�rrhrkrr�r
rrrrr�Os.





0.
 r��__main__)6rr�r�r8rrrMr2�
contextlibr�r�rQr>r�rr�rZtest.supportrr�r�rr�rrrDrpZTestCaserr)rOrer�r�r��contextmanagerr�r�r�r�rr'r/r6rNrPrxrQrRr�r�r�r$�mainrrrr�<module>sh
23@*%
	 0 .?>}>5


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists