403Webshell
Server IP : 118.27.122.248  /  Your IP : 216.73.216.153
Web Server : Apache
System : Linux web0264.sh.tyo1 4.18.0-553.79.1.lve.el7h.x86_64 #1 SMP Wed Oct 15 16:34:46 UTC 2025 x86_64
User : c9415830 ( 11735)
PHP Version : 8.4.17
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python36/lib64/python3.6/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python36/lib64/python3.6/test/__pycache__/test_tempfile.cpython-36.opt-2.pyc
3

�
�^|��@s2ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
Z
ddlm
Z
ddlmZeed�r�ddlZdZndZejejkZeed�Zejjd�r�d	Znd
ZGdd�de
j�ZGd
d�de
j�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!ej"dd��Z#dd�Z$Gdd�d�Z%Gdd �d e%e�Z&Gd!d"�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.ej/k	�r�Gd/d0�d0e�Z0Gd1d2�d2�Z1Gd3d4�d4e�Z2e3d5k�r.e
j4�dS)6�N)�mock)�support)�
script_helper�stat��spawnlZopenbsd�0�dc@s$eZdZdd�Zdd�Zdd�ZdS)�TestLowLevelInternalscCs:|jttjd��|jttjd��|jttjd��dS)N��)�assertIs�str�tempfile�_infer_return_type�bytes)�self�r�2/opt/alt/python36/lib64/python3.6/test_tempfile.py�test_infer_return_type_singles(sz4TestLowLevelInternals.test_infer_return_type_singlescCsp|jttjdd��|jttjdd��|jt��tjdd�WdQRX|jt��tjdd�WdQRXdS)Nrr)r
rrrr�assertRaises�	TypeError)rrrr� test_infer_return_type_multiples-sz6TestLowLevelInternals.test_infer_return_type_multiplescCs�|jttjdd��|jttjdd��|jttjdd��|jttjdd��|jttjdd��|jt��tjddd�WdQRX|jt��tjddd�WdQRXdS)Nrr)r
rrrrrr)rrrr�)test_infer_return_type_multiples_and_none5sz?TestLowLevelInternals.test_infer_return_type_multiples_and_noneN)�__name__�
__module__�__qualname__rrrrrrrr
'sr
c@s8eZdZejd�Zejd�Zdd�Zdd�Zdd�Z	d	S)
�BaseTestCasez^[a-z0-9_-]{8}$s^[a-z0-9_-]{8}$cCs*tj�|_|jj�tjdtdtd�dS)N�ignore�mktemp)�category�message�module)r�check_warnings�_warnings_manager�	__enter__�warnings�filterwarnings�RuntimeWarningr)rrrr�setUpHs

zBaseTestCase.setUpcCs|jjddd�dS)N)r$�__exit__)rrrr�tearDownNszBaseTestCase.tearDownc
Cs|tjj|�\}}|dt|��}|t|�t|�d�}|dk	rb|jt|�t|�tkrZtntd�|dk	r�|jt|�t|�tkr�tntd�|dk	r�|jt|�t|�tkr�tntd�|||fdkr�|jt|�td�|jtjj	|�tjj	|�d||f�|j||d||f�|j||d||f�|t|�t|�t|��}t
|t��rV|jn|j}	|j
|	j|�d||	jf�dS)Nzunexpected return typezdefault 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)NNN)�os�path�split�lenr
�typerr�assertEqual�abspath�
isinstance�	str_check�b_check�
assertTrue�match�pattern)
r�name�dir�pre�suf�ndir�nbaseZnpreZnsufZcheckrrr�	nameCheckQs2zBaseTestCase.nameCheckN)
rrr�re�compiler4r5r)r+r?rrrrrCs


rc@seZdZdd�ZdS)�TestExportscCsttj}ddddddddddddddd�}g}x*|D]"}|ddkr2||kr2|j|�q2W|jt|�dkd|�dS)Nr)�NamedTemporaryFile�
TemporaryFile�mkstemp�mkdtempr�TMP_MAX�
gettempprefix�gettempprefixb�
gettempdir�gettempdirb�tempdir�template�SpooledTemporaryFile�TemporaryDirectoryr�_zunexpected keys: %s)r�__dict__�appendr6r/)r�dict�expectedZunexp�keyrrr�test_exportsrs*
zTestExports.test_exportsN)rrrrVrrrrrBqsrBcsNeZdZ�fdd�Zdd�Zdd�Zdd�Zeje	e
d	�d
�dd��Z�ZS)
�TestRandomNameSequencecstj�|_t�j�dS)N)r�_RandomNameSequence�r�superr))r)�	__class__rrr)�s
zTestRandomNameSequence.setUpcCst|j�}|j|ddd�dS)Nr)�nextrYr?)r�srrr�test_get_six_char_str�s
z,TestRandomNameSequence.test_get_six_char_strcCsLi}|j}x<tt�D]0}t|�}|j|ddd�|j||�d||<qWdS)Nrr)rY�range�
TEST_FILESr\r?�assertNotIn)rrSrY�ir]rrr�	test_many�sz TestRandomNameSequence.test_manycCs.d}|j}x|D]}|d7}|dkrPqWdS)Nrr�)rY)rrbrYr]rrr�
supports_iter�s
z$TestRandomNameSequence.supports_iter�forkz!os.fork is required for this testcCs�tj�\}}d}zftj�}|sTtj|�tj|t|j�jd��tj|�tjd�t|j�}tj	|t
|��jd�}Wd|r�ytj|t
j�Wntk
r�YnXtj|d�tj|�tj|�X|j||�dS)N�asciir)r,�piperf�close�writer\rY�encode�_exit�readr/�decode�kill�signal�SIGKILL�OSError�waitpid�assertNotEqual)rZread_fdZwrite_fd�pidZparent_valueZchild_valuerrr�test_process_awareness�s(




z-TestRandomNameSequence.test_process_awareness)
rrrr)r^rcre�unittest�
skipUnless�hasattrr,rv�
__classcell__rr)r[rrW�s
rWc@seZdZdd�Zdd�ZdS)�TestCandidateTempdirListcCs8tj�}|jt|�dk�x|D]}|j|t�q WdS)Nr)r�_candidate_tempdir_list�assertFalser/�assertIsInstancer)r�cand�crrr�test_nonempty_list�s
z+TestCandidateTempdirList.test_nonempty_listcCs�tj���}x*dD]"}tj|�}|stjj|�||<qWtj�}x*dD]"}tj|�}|sZt�|j	||�qDWytj
�}Wnttfk
r�tj
}YnX|j	||�WdQRXdS)N�TMPDIR�TEMP�TMP)r�r�r�)r�r�r�)r�EnvironmentVarGuardr,�getenvr-r2rr|�
ValueError�assertIn�getcwd�AttributeErrorrr�curdir)r�envZenvname�dirnamerrrr�test_wanted_dirs�s 




z)TestCandidateTempdirList.test_wanted_dirsN)rrrr�r�rrrrr{�s	r{c@seZdZdd�ZdS)�TestGetDefaultTempdirc-stj����fdd�}tjtd|���tj�|jtj��g�dd��tjtd���6|j	t
��tj�WdQRX|jtj��g�WdQRX��fdd�}tjtd|��6�|j	t
��tj�WdQRX|jtj��g�WdQRXWdQRXWdQRXdS)	Ncs�gS)Nrr)�our_temp_directoryrr�our_candidate_listszKTestGetDefaultTempdir.test_no_files_left_behind.<locals>.our_candidate_listr|c_s
t��dS)N)rr)�args�kwargsrrr�
raise_OSErrorszFTestGetDefaultTempdir.test_no_files_left_behind.<locals>.raise_OSError�opencs�||�}�|_|S)N)rj)r�r��fp)�	orig_openr�rr�
bad_writers
zCTestGetDefaultTempdir.test_no_files_left_behind.<locals>.bad_writer)rrOr�	swap_attrZ_get_default_tempdirr1r,�listdir�ior�FileNotFoundError)rr�r�r)r�r�r�r�test_no_files_left_behinds 
z/TestGetDefaultTempdir.test_no_files_left_behindN)rrrr�rrrrr�sr�c@seZdZdd�Zdd�ZdS)�TestGetCandidateNamescCstj�}|j|tj�dS)N)r�_get_candidate_namesr~rX)r�objrrr�test_retval)sz!TestGetCandidateNames.test_retvalcCs"tj�}tj�}|j||k�dS)N)rr�r6)r�a�brrr�test_same_thing.sz%TestGetCandidateNames.test_same_thingN)rrrr�r�rrrrr�&sr�ccs>tj�}z$tjtd|��dVWdQRXWdtj|�XdS)NrL)rrFrr��rmtree)r:rrr�_inside_empty_temp_dir6s
r�cstjtd�fdd��S)Nr�cst��S)N)�iterr)�namesrr�<lambda>Csz'_mock_candidate_names.<locals>.<lambda>)rr�r)r�r)r�r�_mock_candidate_names@sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�TestBadTempdircCs�t���tjtj�j}}|tjtjBtjBM}tj	tj|�zPtj
tjtj�r\|jd�|j
t��|j�WdQRX|jtjtj�g�Wdtj	tj|�XWdQRXdS)Nz!can't set the directory read-only)r�r,rrrL�st_mode�S_IWUSR�S_IWGRP�S_IWOTH�chmod�access�W_OKZskipTestr�PermissionError�	make_tempr1r�)rZoldmode�moderrr�test_read_only_directoryHs
z'TestBadTempdir.test_read_only_directorycCs^t��Ntjjtjd�}tjtd|��$|jt	��|j
�WdQRXWdQRXWdQRXdS)N�nonexistentrL)r�r,r-�joinrrLrr�rr�r�)rrLrrr�test_nonexisting_directoryVs
z)TestBadTempdir.test_nonexisting_directorycCspt��`tjjtjd�}t|d�j�tj	td|��(|j
ttf��|j
�WdQRXWdQRXWdQRXdS)N�file�wbrL)r�r,r-r�rrLr�rirr�r�NotADirectoryErrorr�r�)rrLrrr�test_non_directory]sz!TestBadTempdir.test_non_directoryN)rrrr�r�r�rrrrr�Fsr�c@s�eZdZGdd�d�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Ze	j
ed�dd��Ze	j
e
d�dd��Ze	j
ed�dd��Zdd�Zdd�Zdd�ZdS)�TestMkstempInnerc@s<eZdZejZejZej	Z
ejZdd�Z
dd�Zdd�ZdS)zTestMkstempInner.mkstempedcCs>|r|j}n|j}tj|||�}tj|||||�\|_|_dS)N)�_bflags�_tflagsrr�_mkstemp_inner�fdr9)rr:r;r<�bin�flags�output_typerrr�__init__os
z#TestMkstempInner.mkstemped.__init__cCstj|j|�dS)N)r,rjr�)rrrrrrjvsz TestMkstempInner.mkstemped.writecCs|j|j�|j|j�dS)N)�_closer��_unlinkr9)rrrr�__del__ysz"TestMkstempInner.mkstemped.__del__N)rrrr�_bin_openflagsr��_text_openflagsr�r,rir��unlinkr�r�rjr�rrrr�	mkstempedisr�NrcCsrtj|||�}|dkr0|tkr(tj�}ntj�}|dkr>|�}|dkrL|�}|j||||�}|j|j|||�|S)N)rrrrJrKr�r?r9)rr:r;r<r�r�r�rrr�	do_create}s
zTestMkstempInner.do_createcCs^|j�jd�|jdd�jd�|jdd�jd�|jddd�jd�|jddd�jd�dS)	Nsblatr�)r;r�)r<)r;r<�aaz.txt)r�rj)rrrr�
test_basic�s
zTestMkstempInner.test_basiccCs�tj�}|j|dd�jd�|j|dd�jd�|j|dd�jd�|j|ddd�jd�|j|dd	d�jd�|jt��|jd
dd�jd�WdQRX|jt��|j|d
d�jd�WdQRX|jt��|j|dd
d�jd�WdQRXdS)Nr)r:r<sblat�a)r:r;�b)r:r;r<saas.txtr)rrKr�rjrr)rZdir_brrr�test_basic_with_bytes_names�sz,TestMkstempInner.test_basic_with_bytes_namescCs.ttt��}x|D]}|jdd�||<qWdS)Nr�)r;)�listr_r`r�)r�extantrbrrr�test_basic_many�s
z TestMkstempInner.test_basic_manycCs0tj�}z|j|d�jd�Wdtj|�XdS)N)r:sblat)rrFr�rjr,�rmdir)rr:rrr�test_choose_directory�sz&TestMkstempInner.test_choose_directoryzos.stat not availablecCsJ|j�}tjtj|j�j�}d}tjdkr:|d?}|d}|j||�dS)	Ni��win32�r��@�	�I)	r�r�S_IMODEr,r9r��sys�platformr1)rr�r�rT�userrrr�test_file_mode�s
zTestMkstempInner.test_file_modezos.spawnl not availablecCs�tjrd}nd}|j�}|jtj|j�d�d|j}yt}Wntk
r\t	j
d}YnXtjjtjj
tjj|��d�}t	jdkr�dt	j}d|}nt	j}tjtjt	j||||�}|j|dkd	|�|j|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�r1r,�get_inheritabler��__file__�	NameErrorr��argvr-r�r�r2r��
executabler�P_WAITr})rr�r�r��meZtesterZ	decoratedZretvalrrr�test_noinherit�s(




zTestMkstempInner.test_noinheritztext mode not availablecCsL|jdd�}|jd�|jd�tj|jdtj�|jtj|jd�d�dS)Nr)r�sblatsextra
rdsblat)r�rjr,�lseekr��SEEK_SETr1rm)r�frrr�
test_textmode�s


zTestMkstempInner.test_textmodecCstjtj�tj�dtjt�S)Nr)rr�rJrHr�r)rrrrr��s

zTestMkstempInner.make_tempcCszt��jtddd��R|j�\}}tj|�|j|jd��|j�\}}tj|�|j|jd��WdQRXWdQRXdS)N�aaa�bbb)r�r�r�r,rir6�endswith)rZfd1Zname1Zfd2Zname2rrr�!test_collision_with_existing_file�s

z2TestMkstempInner.test_collision_with_existing_filecCslt��\tddd��Dtj�}|j|jd��|j�\}}tj|�|j|jd��WdQRXWdQRXdS)Nr�r�)	r�r�rrFr6r�r�r,ri)rr:r�r9rrr�&test_collision_with_existing_directorys
z7TestMkstempInner.test_collision_with_existing_directory)NNNr)rrrr�r�r�r�r�r�rwrx�has_statr��
has_spawnlr��has_textmoder�r�r�r�rrrrr�fs
&
r�c@seZdZdd�Zdd�ZdS)�TestGetTempPrefixcCsLtj�}|j|t�|jt|�d�tj�}|j|t�|jt|�d�dS)Nr)rrHr~rZ
assertGreaterr/rIr)r�pZpbrrr�test_sane_templatesz$TestGetTempPrefix.test_sane_templatecCsdtj�d}tjdd�}z:tjj||�}tj|tjtjB�}tj	|�tj
|�Wdtj|�XdS)Nz
xxxxxx.xxxr)�prefix)rrHrFr,r-r�r��O_RDWR�O_CREATrir�r�)rr��dr�rrr�test_usable_template#s
z&TestGetTempPrefix.test_usable_templateN)rrrr�rrrrrr�sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestGetTempDircCsXxRtj�tj�fD]>}|jtjj|�p.|tjkd|�|jtjj|�d|�qWdS)Nz%r is not an absolute pathz%r is not a directory)	rrJrKr6r,r-�isabsr��isdir)rrrrr�test_directory_exists7s

z$TestGetTempDir.test_directory_existscCstj�}|jd�|j�dS)Nsblat)rrCrjri)rr�rrr�test_directory_writable@s
z&TestGetTempDir.test_directory_writablecCsPtj�}tj�}tj�}|j||k�|jt|�t|��|j|tj|��dS)N)	rrJrKr6rtr0r1r,�fsdecode)rr�r�r�rrrr�JszTestGetTempDir.test_same_thingcCs`tjd�}tjd}t_z0tj��}||d<|jtj�|�WdQRXWd|t_tj|�XdS)Nz-Tempr�)rrFrLrr�r1rJr�)rZcase_sensitive_tempdirZ_tempdirr�rrr�test_case_sensitiveTs

z"TestGetTempDir.test_case_sensitiveN)rrrrrr�r	rrrrr4s	

rc@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)�TestMkstempNc
Cs�tj|||�}|dkr0|tkr(tj�}ntj�}|dkr>|�}|dkrL|�}tj|||d�\}}tjj|�\}}tjj	|�}	|j
|	|d|	|f�z|j||||�Wdtj|�tj
|�XdS)N)r:r��suffixz+Directory '%s' incorrectly returned as '%s')rrrrJrKrEr,r-r.r2r1r?rir�)
rr:r;r<r�r�r9r=r>Zadirrrrr�fs$

zTestMkstemp.do_createcCsL|j�|jdd�|jdd�|jddd�|jddd�|jdd	�dS)
Nr�)r;r�)r<)r;r<r�z.txt�.)r:)r�)rrrrr�}szTestMkstemp.test_basiccCs�tj�}|j|dd�|j|dd�|j|dd�|j|ddd�|j|ddd�|jd	d
�|jt��|jdddd�WdQRX|jt��|jd	ddd�WdQRX|jt��|jd	dd
d�WdQRXdS)Nr)r:r<r�)r:r;r�)r:r;r<saas.txt�.)r:rr�z.txt)rrKr�rr)rrrrrr��sz'TestMkstemp.test_basic_with_bytes_namescCs*tj�}z|j|d�Wdtj|�XdS)N)r:)rrFr�r,r�)rr:rrrr��sz!TestMkstemp.test_choose_directory)NNN)rrrr�r�r�r�rrrrr
cs
	r
c@sbeZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Ze	j
ed�dd��Zdd�Z
dd�ZdS)�TestMkdtempcCstj�S)N)rrF)rrrrr��szTestMkdtemp.make_tempNcCs�tj|||�}|dkr0|tkr(tj�}ntj�}|dkr>|�}|dkrL|�}tj|||d�}y|j||||�|Stj|��YnXdS)N)r:r�r)	rrrrJrKrFr?r,r�)rr:r;r<r�r9rrrr��s 

zTestMkdtemp.do_createcCs^tj|j��tj|jdd��tj|jdd��tj|jddd��tj|jddd��dS)Nr�)r;r�)r<)r;r<r�z.txt)r,r�r�)rrrrr��s
zTestMkdtemp.test_basiccCs�tj�}tj|j|d��tj|j|dd��tj|j|dd��tj|j|ddd��tj|j|ddd��|jt��tj|j|d	dd��WdQRX|jt��tj|j|dd
d��WdQRX|jt��tj|jdddd��WdQRXdS)N)r:r�)r:r;r�)r:r<)r:r;r<saas.txtr�z.txtr)rrKr,r�r�rr)rrrrrr��s  z'TestMkdtemp.test_basic_with_bytes_namesc
CsXttt��}z"x|D]}|jdd�||<qWWdx |D]}t|t�r6tj|�q6WXdS)Nr�)r;)r�r_r`r�r3rr,r�)rr�rbrrrr��s


zTestMkdtemp.test_basic_manycCs0tj�}ztj|j|d��Wdtj|�XdS)N)r:)rrFr,r�r�)rr:rrrr��sz!TestMkdtemp.test_choose_directoryzos.stat not availablecCsb|j�}zHtjtj|�j�}|dM}d}tjdkrB|d?}|d	}|j||�Wdtj|�XdS)
Ni�i�r�r�rr�r�r�r�)	r�rr�r,r�r�r�r1r�)rr:r�rTr�rrr�	test_mode�s
zTestMkdtemp.test_modecCslt��\tddd��Dtjdd�}|j�|j|jjd��tj�}|j|jd��WdQRXWdQRXdS)Nr�r�F)�delete)	r�r�rrCrir6r9r�rF)rr�r:rrrr��sz-TestMkdtemp.test_collision_with_existing_filecCs^t��Ntddd��6tj�}|j|jd��tj�}|j|jd��WdQRXWdQRXdS)Nr�r�)r�r�rrFr6r�)rZdir1Zdir2rrrr�sz2TestMkdtemp.test_collision_with_existing_directory)NNN)rrrr�r�r�r�r�r�rwrxr�rr�r�rrrrr�s
rcsPeZdZ�fdd�Z�fdd�ZGdd�d�Zddd	�Zd
d�Zdd
�Z�Z	S)�
TestMktempcstj�|_t�j�dS)N)rrFr:rZr))r)r[rrr)s
zTestMktemp.setUpcs&|jrtj|j�d|_t�j�dS)N)r:r,r�rZr+)r)r[rrr+szTestMktemp.tearDownc@s(eZdZejZejZdd�Z	dd�Z
dS)zTestMktemp.mktempedcCs.tj|||d�|_tjtj|j|jd��dS)N)r:r�ri�)rrr9r,rir�r�)rr:r;r<rrrr� szTestMktemp.mktemped.__init__cCs|j|j�dS)N)r�r9)rrrrr�&szTestMktemp.mktemped.__del__N)rrrr,r�r�rr�r�r�r�rrrr�mktempedsrrcCs(|j|j||�}|j|j|j||�|S)N)rr:r?r9)rr;r<r�rrrr�)szTestMktemp.do_createcCs@|j�|jdd�|jdd�|jddd�|jddd�dS)Nr�)r;r�)r<)r;r<r�z.txt)r�)rrrrr�/s
zTestMktemp.test_basiccCs.ttt��}x|D]}|jdd�||<qWdS)Nr�)r;)r�r_r`r�)rr�rbrrrrc7s
zTestMktemp.test_many)rr)
rrrr)r+rr�r�rcrzrr)r[rr
s
rc@sfeZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�TestNamedTemporaryFileNrTcCs8|dkrtj�}tj||||d�}|j|j|||�|S)N)r:r�rr)rrJrCr?r9)rr:r;r<rr�rrrr�Ls
z TestNamedTemporaryFile.do_createcCs@|j�|jdd�|jdd�|jddd�|jddd�dS)Nr�)r;r�)r<)r;r<r�z.txt)r�)rrrrr�Vs
z!TestNamedTemporaryFile.test_basiccCsP|j�}tj|�}|j}|j}~|d�~|d�~tjdd�rL|j|��dS)NsfoosbarT)Zcpython)r��weakref�refrjrZcheck_impl_detail�assertIsNone)rr��wrrjZwrite2rrr�test_method_lookup^s
z)TestNamedTemporaryFile.test_method_lookupcsVdddg��fdd�}x&t|��D]\}}|j|�|�q"W|j|t��d�dS)Nsspam
seggs
sbeans
cs*tjdd�}|jdj���|jd�|S)Nzw+b)r�rr)rrCrjr��seek)r�)�linesrr�	make_filers
z3TestNamedTemporaryFile.test_iter.<locals>.make_filer)�	enumerater1r/)rrrb�lr)rr�	test_iterns

z TestNamedTemporaryFile.test_itercCs(tj�}|jtjj|j�d|j�dS)Nz$NamedTemporaryFile %s does not exist)rrCr6r,r-�existsr9)rr�rrr�test_creates_named{sz)TestNamedTemporaryFile.test_creates_namedcCsXtj�}z>tj|d�}|jd�|j�|jtjj|j	�d|j	�Wdtj
|�XdS)N)r:sblatz(NamedTemporaryFile %s exists after close)rrFrCrjrir}r,r-rr9r�)rr:r�rrr�test_del_on_close�s
z(TestNamedTemporaryFile.test_del_on_closecCsvtj�}d}zFtj|dd�}|j}|jd�|j�|jtjj	|j�d|j�Wd|dk	rftj
|�tj|�XdS)NF)r:rsblatz)NamedTemporaryFile %s missing after close)rrFrCr9rjrir6r,r-rr�r�)rr:�tmpr�rrr�test_dis_del_on_close�s

z,TestNamedTemporaryFile.test_dis_del_on_closecCs.tj�}|jd�|j�|j�|j�dS)Nsabc
)rrCrjri)rr�rrr�test_multiple_close�s

z*TestNamedTemporaryFile.test_multiple_closec
sXtj���|jtjj�j��WdQRX|jtjj�j���fdd�}|jt	|�dS)Nc	s��WdQRXdS)Nrr)r�rr�
use_closed�sz?TestNamedTemporaryFile.test_context_manager.<locals>.use_closed)
rrCr6r,r-rr9r}rr�)rr%r)r�r�test_context_manager�s

z+TestNamedTemporaryFile.test_context_managercsng�tj���fdd�}tjd|d��>tjdtd��$|jttj�|jt	��d�WdQRXWdQRXdS)Ncs�j|��|�dS)N)rR)r�)�closed�os_closerrri�s
z5TestNamedTemporaryFile.test_no_leak_fd.<locals>.closezos.close)�side_effectzio.openr)
r,rir�patchr�rrrCr1r/)rrir)r'r(r�test_no_leak_fd�sz&TestNamedTemporaryFile.test_no_leak_fdcCsttj�}|jtj|�|jt��tjd|d�WdQRX|jt��tjd|d�WdQRX|j	t
j|�g�dS)Nr)r�r:�)rrFZ
addCleanuprr�rr�rCrr1r,r�)rr:rrr�
test_bad_mode�sz$TestNamedTemporaryFile.test_bad_mode)NrrT)rrrr�r�rrr r!r#r$r&r+r-rrrrrIs




rc@s�eZdZd*dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�ZdS)+�TestSpooledTemporaryFilerNrcCs&|dkrtj�}tj||||d�}|S)N)�max_sizer:r�r)rrJrN)rr/r:r;r<r�rrrr��sz"TestSpooledTemporaryFile.do_createcCs4|j�}|j|j�|jdddd�}|j|j�dS)Nr	r�z.txt)r/r;r<)r�r}�_rolled)rr�rrrr��sz#TestSpooledTemporaryFile.test_basiccCs�tj�}zhtjd|d�}|j|j�|jdd�|j|j�|j}|j�|jt	|t
�odtjj
|�d|�Wdtj|�XdS)N�
)r/r:sblat �z*SpooledTemporaryFile %s exists after close)rrFrNr}r0rjr6r9rir3rr,r-rr�)rr:r��filenamerrrr!�sz*TestSpooledTemporaryFile.test_del_on_closecCsP|jdd�}|j|j�x&td�D]}|jdd�|jd�q"W|j|j�dS)N�)r/r2r�xrdsxxxxxxxxxxxxxxxxxxxx)r�r}r0r_rrj)rr�rbrrr�test_rewrite_small�sz+TestSpooledTemporaryFile.test_rewrite_smallcCs^|jdd�}|j|j�|jd�|j|j�|jd�|j|j�|jd�|j|j�dS)Nr4)r/r5rdr1sxxxxxxxxxxxxxxxxxxxxs
xxxxxxxxxx)r�r}r0rjr6)rr�rrr�test_write_sequential�s


z.TestSpooledTemporaryFile.test_write_sequentialcCs4|j�}|jd�|jd�|j�}|j|d�dS)Nr5�y�zrsxyz)r5r8r9)r��
writelinesrrmr1)rr��bufrrr�test_writelines�s


z(TestSpooledTemporaryFile.test_writelinescCs<|jdd�}|jd
�|j|j�|jd�|j|j�dS)N�#)r/r5rdr1r2�xxxxxxxxxxxxxxxxxxxx�
xxxxxxxxxx�xxxxx)r>r?r@)r�r:r}r0rjr6)rr�rrr�test_writelines_sequentials


z3TestSpooledTemporaryFile.test_writelines_sequentialcCsJ|jdd�}|j|j�|jdd�|j|j�|jd�|j|j�dS)Nr4)r/r	rr5)r�r}r0rrjr6)rr�rrr�test_sparses
z$TestSpooledTemporaryFile.test_sparsecCs:|jdd�}|j|j�|j|j�dk�|j|j�dS)Nr4)r/r)r�r}r0r6�fileno)rr�rrr�test_filenosz$TestSpooledTemporaryFile.test_filenocCs:tj�}|jd�|j|j�|j�|j�|j�dS)Nsabc
)rrNrjr}r0ri)rr�rrr�#test_multiple_close_before_rollovers
z<TestSpooledTemporaryFile.test_multiple_close_before_rollovercCs>tjdd�}|jd�|j|j�|j�|j�|j�dS)Nr)r/sabc
)rrNrjr6r0ri)rr�rrr�"test_multiple_close_after_rollover(s
z;TestSpooledTemporaryFile.test_multiple_close_after_rollovercCs`|jdd�}|j}|j}|j}|dd�|dd�|dd�|j|d�dddd�dS)Nr4)r/r�r=r�r�F)r�rmrjrr1)rr�rmrjrrrr�test_bound_methods1s
z+TestSpooledTemporaryFile.test_bound_methodscCs�tjdd�}|jd�|j|j�|j|jd�|j|j�|j	t
��|jWdQRX|j	t
��|jWdQRX|jd�|j
|j�|j|jd�|j|j�|j	t
��|jWdQRX|j	t
��|jWdQRXdS)Nr1)r/r5zw+bzrb+s
xxxxxxxxxx)rrNrjr}r0r1r�rr9rr��newlines�encodingr6�assertIsNotNone)rr�rrr�test_properties?s"

z(TestSpooledTemporaryFile.test_propertiescCs"tjddd�}|jd�|jd�|j|j�d�|jd�|jd�|j|j�d�|j|j�|j|jd�|j	|j
�|j	|j�|j	|j�|jd�|jd�|j|j�d	�|jd
�|jd�|j|j�d�|j
|j�|j|jd�|j|j
�|j|jtj�|j|j�dS)Nzw+r1)r�r/zabc
rzdef
zabc
def
zxyzzy
zabc
def
xyzzy
zfoobar
zabc
def
xyzzy
foobar
)rrNrjrr1rmr}r0r�rr9rIrJr6rKr,�linesep)rr�rrr�test_text_modeSs.







z'TestSpooledTemporaryFile.test_text_modecCs�tjddddd�}|jd�|jd�|j|j�d�|j|j�|j|jd�|j	|j
�|j	|j�|j	|j�|jd�|jd�|j|j�d�|j
|j�|j|jd�|j|j
�|j|j�|j|jd�dS)Nzw+r1rzutf-8)r�r/�newlinerJuΛ
ruΛrdz
u(ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛu*ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
u(ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛu,Λ
ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛu.Λ
ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ
)rrNrjrr1rmr}r0r�rr9rIrJr6rK)rr�rrr�test_text_newline_and_encodingps$




z7TestSpooledTemporaryFile.test_text_newline_and_encodingc
sXtjdd���|j�j�|j�j�WdQRX|j�j��fdd�}|jt|�dS)Nr)r/c	s��WdQRXdS)Nrr)r�rrr%�szQTestSpooledTemporaryFile.test_context_manager_before_rollover.<locals>.use_closed)rrNr}r0r'r6rr�)rr%r)r�r�$test_context_manager_before_rollover�sz=TestSpooledTemporaryFile.test_context_manager_before_rolloverc
svtjdd��<�|j�j��jd��j�|j�j�|j�j�WdQRX|j�j��fdd�}|jt	|�dS)Nr)r/sabc
c	s��WdQRXdS)Nrr)r�rrr%�szQTestSpooledTemporaryFile.test_context_manager_during_rollover.<locals>.use_closed)
rrNr}r0rj�flushr6r'rr�)rr%r)r�r�$test_context_manager_during_rollover�s
z=TestSpooledTemporaryFile.test_context_manager_during_rolloverc
sntjdd���jd��j�|j�j���|j�j�WdQRX|j�j��fdd�}|jt	|�dS)Nr)r/sabc
c	s��WdQRXdS)Nrr)r�rrr%�szPTestSpooledTemporaryFile.test_context_manager_after_rollover.<locals>.use_closed)
rrNrjrRr6r0r}r'rr�)rr%r)r�r�#test_context_manager_after_rollover�s
z<TestSpooledTemporaryFile.test_context_manager_after_rollovercCs�tjdd�}|jd�|jd�|j�|j|j�|j|jj	�d�tjdd�}|jd�|jd�|j|j�|j|jj	�d�tjdd�}|jd�|jd�|j
|j�tr�|jtj
|j��jd�dS)	Nr1)r/sabcdefg
rr�sabcdrd)rrNrjr�truncater}r0r1Z_file�getvaluer6r�r,�fstatrC�st_size)rr�rrr�!test_truncate_with_size_parameter�s"





z:TestSpooledTemporaryFile.test_truncate_with_size_parameter)rNrr)rrrr�r�r!r6r7r<rArBrDrErFrHrLrNrPrQrSrTrZrrrrr.�s&
		
		r.c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestTemporaryFilecCstj�dS)N)rrD)rrrrr��szTestTemporaryFile.test_basicc	CsRtj�}tj|d�}|jd�ytj|�Wn |j�tj|��YnXdS)N)r:sblat)rrFrDrjr,r�ri)rr:r�rrr�test_has_no_name�s

z"TestTemporaryFile.test_has_no_namecCs.tj�}|jd�|j�|j�|j�dS)Nsabc
)rrDrjri)rr�rrrr$�s

z%TestTemporaryFile.test_multiple_closecs@�fdd�}|dd�|dd�|dddd	�|d
ddd�dS)
Nc
s@tj||��*}|j|�|jd��j||j��WdQRXdS)Nr)rrDrjrr1rm)�inputr�r�Zfileobj)rrr�	roundtrip�s

z;TestTemporaryFile.test_mode_and_encoding.<locals>.roundtrips1234zw+bzabdc
zw+uΛzutf-16)rJzfoo
r)rOr)rr^r)rr�test_mode_and_encoding�s


z(TestTemporaryFile.test_mode_and_encodingcsng�tj���fdd�}tjd|d��>tjdtd��$|jttj�|jt	��d�WdQRXWdQRXdS)Ncs�j|��|�dS)N)rR)r�)r'r(rrri�s
z0TestTemporaryFile.test_no_leak_fd.<locals>.closezos.close)r)zio.openr)
r,rirr*r�rrrDr1r/)rrir)r'r(rr+�sz!TestTemporaryFile.test_no_leak_fdN)rrrr�r\r$r_r+rrrrr[�s
	
r[c@s$eZdZdd�Zdd�Zdd�ZdS)�
NulledModulescGs&dd�|D�|_dd�|jD�|_dS)NcSsg|]
}|j�qSr)rQ)�.0�modrrr�
<listcomp>sz*NulledModules.__init__.<locals>.<listcomp>cSsg|]}|j��qSr)�copy)rarrrrrcs)�refs�contents)r�modulesrrrr�szNulledModules.__init__cCs*x$|jD]}x|D]}d||<qWqWdS)N)re)rrrUrrrr%s
zNulledModules.__enter__cGs2x,t|j|j�D]\}}|j�|j|�qWdS)N)�ziprerf�clear�update)r�exc_inforr�rrrr*
szNulledModules.__exit__N)rrrr�r%r*rrrrr`sr`c@sjeZdZddd�Zdd�Zdd	�Zejd
d��Zej	dd
��Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�TestTemporaryDirectoryNrrc	Cs�|dkrtj�}tj|||d�}|j|j|||�|rR|j|j|||d�}d|_ttjj	|jd�d��}|j
d�WdQRX|S)N)r:r�rrztest.txtr�sHello world!)rrJrOr?r9r�r�r,r-r�rj)rr:r;r<�recurser"�d1r�rrrr�sz TestTemporaryDirectory.do_createcCsLtj��}WdQRX|jt��}tj|d�WdQRX|j|jjtj�dS)N)r:)rrOrr�r1Z	exception�errno�ENOENT)rr��cmrrr�test_mkdtemp_failure"s


z+TestTemporaryDirectory.test_mkdtemp_failurecCsjtj�}zP|j|d�}|jtjj|j�d|j�|j�|j	tjj|j�d|j�Wdtj
|�XdS)N)r:z$TemporaryDirectory %s does not existz*TemporaryDirectory %s exists after cleanup)rrFr�r6r,r-rr9�cleanupr}r�)rr:rrrr�test_explicit_cleanup,sz,TestTemporaryDirectory.test_explicit_cleanupcCs�|j�}|jdd�}tj|jtjj|jd��|j�|jtjj|j�d|j�|j	tjj|j�d�|j
tj|j�dgd�|j�dS)Nr)rmZfooz*TemporaryDirectory %s exists after cleanupz-Directory pointed to by a symlink was deletedztest.txtz>Contents of the directory pointed to by a symlink were deleted)r�r,�symlinkr9r-r�rsr}rr6r1r�)rrnZd2rrr�(test_cleanup_with_symlink_to_a_directory9sz?TestTemporaryDirectory.test_cleanup_with_symlink_to_a_directorycCsJtj�}z0|j|d�}|j}~|jtjj|�d|�Wdtj|�XdS)N)r:z*TemporaryDirectory %s exists after __del__)	rrFr�r9r}r,r-rr�)rr:rr9rrr�test_del_on_collectionNsz-TestTemporaryDirectory.test_del_on_collectionc
Cs�|j��|}xtdD]l}dj||d�}tjd	|�\}}}|j�j�}|jtjj	|�d
|�|jdd�}|j
d
|�|jd|�qWWdQRXdS)N�builtinsr,�shutilr�rr&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, "test.txt"), "w") as f:
                        f.write("Hello world!")

                    {mod}.tmp = tmp

                    warnings.filterwarnings("always", category=ResourceWarning)
                    )r:rbz-cz*TemporaryDirectory %s exists after cleanupzutf-8�backslashreplacez
Exception z'ResourceWarning: Implicitly cleaning up)rxr,ryr�rr&)r��formatr�assert_python_okrn�stripr}r,r-rrar�)rr:rb�code�rc�out�err�tmp_namerrr�test_del_on_shutdown[s


z+TestTemporaryDirectory.test_del_on_shutdowncCs~|j��l}dj|d�}tjd|�\}}}|j�j�}|jtjj	|�d|�|jdd�}|j
d|�|jd|�WdQRXdS)	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:z-cz*TemporaryDirectory %s exists after cleanupzutf-8rzz
Exception z'ResourceWarning: Implicitly cleaning up)r�r{rr|rnr}r}r,r-rrar�)rr:r~rr�r�r�rrr�test_exit_on_shutdown{s


z,TestTemporaryDirectory.test_exit_on_shutdowncCsz|j��h}|j|dd�}|j}tjdtfdd��tjdtd�~tj�WdQRX|jt	j
j|�d|�WdQRXdS)	N�)r:rmZ
ImplicitlyF)�quiet�always)r z*TemporaryDirectory %s exists after __del__)r�r9rr#�ResourceWarningr&r'Z
gc_collectr}r,r-r)rr:rr9rrr�test_warnings_on_cleanup�s
z/TestTemporaryDirectory.test_warnings_on_cleanupcCs$|j�}|j�|j�|j�dS)N)r�rs)rrrrrr$�sz*TestTemporaryDirectory.test_multiple_closec
CsN|j�}|�&}|jtjj|��|j||j�WdQRX|jtjj|��dS)N)r�r6r,r-rr1r9r})rrr9rrrr&�s
z+TestTemporaryDirectory.test_context_manager)Nrrr)rrrr�rrrtrZskip_unless_symlinkrvZcpython_onlyrwr�r�r�r$r&rrrrrls




 rl�__main__)5rror�r,rpr�r@r&�
contextlibrrwrZtestrZtest.supportrryrr�r�r�r�r�r��
startswithr`ZTestCaser
rrBrWr{r�r��contextmanagerr�r�r�r�r�rr
rrrr.rCrDr[r`rlr�mainrrrr�<module>sb

.H*%
 / />l<~}> 


Youez - 2016 - github.com/yon3zu
LinuXploit