Files
952-11/env/python/dll/Python312/Lib/__pycache__/tempfile.cpython-312.pyc
T

254 lines
40 KiB
Plaintext
Raw Normal View History

2024-08-19 17:05:14 +08:00
Ë
*åf¤�ãóè—dZgd¢ZddlZddlZddlZddlZ ddl
Z ddl Z
ddlmZddlZddlZddlZddlZej0Ze j4e j6ze j8zZee d«ree j>zZeZ ee d«re e jBzZ ee d«r
e jDZ"ndZ"d Z#e«Z$d
„Z%d „Z&d „Z'Gd
„d«Z(d„Z)d„Z*da+d„Z,d„Z-d„Z.d„Z/d„Z0d„Z1da2d„Z3d„Z4d„Z5d.d„Z6d/d„Z7de#dfd„Z8Gd„d«Z9Gd „d!«Z: d0dd"d#œd$„Z;e jxd%k7sejzd&k(re;Z>nee d'«a? d1dd(œd)„Z>Gd*„d+ej€«ZAGd,„d-«ZBy)2a�Temporary files.
This module provides generic, low- and high-level interfaces for
creating temporary files and directories. All of the interfaces
provided by this module can be used without fear of race conditions
except for 'mktemp'. 'mktemp' is subject to race conditions and
should not be used; it is provided for backward compatibility only.
The default path names are returned as str. If you supply bytes as
input, all return values will be in bytes. Ex:
>>> tempfile.mkstemp()
(4, '/tmp/tmptpu9nin8')
>>> tempfile.mkdtemp(suffix=b'')
b'/tmp/tmppbi8f0hy'
This module also provides some data items to the user:
TMP_MAX - maximum number of names that will be tried before
giving up.
tempdir - If this is set to a string before the first use of
any routine from this module, it will be considered as
another candidate location to store temporary files.
)
ÚNamedTemporaryFileÚ
TemporaryFileÚSpooledTemporaryFileÚTemporaryDirectoryÚmkstempÚmkdtempÚmktempÚTMP_MAXÚ
gettempprefixÚtempdirÚ
gettempdirÚgettempprefixbÚ gettempdirbéN)ÚRandomÚ
O_NOFOLLOWÚO_BINARYr i'ÚtmpcóN— tj|«y#t$rYywxYw)NTF)Ú_osÚlstatÚOSError)Úfns úDC:\Users\RCi\AppData\Local\Programs\Python\Python312\Lib\tempfile.pyÚ_existsrLs+€ðÜ � ‰ �"Œ
ðøô òÙðúó ‚˜ $£$cóR—d}|D]w}|€Œt|tj«rtj|«}t|t«r|t
ur t
d«‚t}Œ_|tur t
d«‚t
}Œy|€&t�ttt
«rt
StS|S)zBLook at the type of all args and divine their implied return type.Nz1Can't mix bytes and non-bytes in path components.)Ú
isinstancerÚPathLikeÚfspathÚbytesÚstrÚ TypeErrorr )ÚargsÚ return_typeÚargs rÚ_infer_return_typer&Us©€à€KØòˆØ ˆ;Ø ä �cœ3Ÿ<™<Ô (Ü—*‘*˜S“/ˆCä �cœ5Ô !ØœcÑ!Üð!3ó4ð4ä‰KàœeÑ#Üð!3ó4ð4ä‰Kð!ð"ÐÜ ˆ?œj¬´#Ô6܈JôˆLØ ÐócóÌ—t|||«}|€|«}|€(|turt}ntjt«}|€|tur t «}n
t
«}||||fS)z9Common parameter processing for most APIs in this module.)r&r!ÚtemplaterÚfsencoder r)ÚprefixÚsuffixÚdirÚ output_types rÚ_sanitize_paramsr/rsf€ä$ V¨V°SÓ9€KØ
€~Ù“ˆØ
€~Ø œ#Ñ Ü‰Fä—\‘\¤(Ó+ˆFØ
€{Ø œ#Ñ Ü“,‰Cä“-ˆCØ �6˜3  Ð +Ð+r'có0—eZdZdZdZed„«Zd„Zd„Zy)Ú_RandomNameSequencea,An instance of _RandomNameSequence generates an endless
sequence of unpredictable strings which can safely be incorporated
into file names. Each string is eight characters long. Multiple
threads can safely use the same instance at the same time.
_RandomNameSequence is an iterator.Ú%abcdefghijklmnopqrstuvwxyz0123456789_cóŽ—tj«}|t|dd«k7rt«|_||_|jS)NÚ_rng_pid)rÚgetpidÚgetattrÚ_RandomÚ_rngr4)ÚselfÚcur_pids rÚrngz_RandomNameSequence.rngŽs8€ä—*‘*“,ˆØ ”g˜d J°Ó5Ò 5Ü› ˆDŒIØ#ˆDŒMØ�y‰yÐr'có—|S©N©©r9s rÚ__iter__z_RandomNameSequence.__iter__–s€Øˆ r'cón—dj|jj|jd¬««S)NÚé)Úk)Újoinr;ÚchoicesÚ
charactersr?s rÚ__next__z_RandomNameSequence.__next__™s)€Ø�w‰w�t—x‘x×'Ñ'¨¯©¸1Ð'Ó=Ó>Ð>r'N) Ú__name__Ú
__module__Ú __qualname__Ú__doc__rGÚpropertyr;r@rHr>r'rr1r1„s*„ñ+ð9€Jà
ñóðòó?r'r1có —g}dD]+}tj|«}|sŒ|j|«Œ-tjdk(rR|j tj
j
d«tj
jd«ddddg«n|j gd ¢« |jtj««|S#ttf$r#|jtj«Y|SwxYw)
z[Generate a list of candidate temporary directories which
_get_default_tempdir will try.)ÚTMPDIRÚTEMPÚTMPÚntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmp)z/tmpz/var/tmpz/usr/tmp) rÚgetenvÚappendÚnameÚextendÚpathÚ
expanduserÚ
expandvarsÚgetcwdÚAttributeErrorrÚcurdir)ÚdirlistÚenvnameÚdirnames rÚ_candidate_tempdir_listr`œsÝ€ð€Gð+ò,ˆÜ—*‘*˜WÓ%ˆÚ �G—N‘N 7Õ+ð,ô
 ‡x�x�4ÒØ�‰œŸ™×,Ñ,Ð-DÓEÜŸ™×,Ñ,Ð-AÓBØ# Y°¸'ðDõ Eð �‰Ò9Ô:ð#Ø�‰”s—z‘z“|Ô$ð €Nøô
œGÐ $ò#Ø�‰”s—z‘zÕ"à €Nð#úsÂ,#CÃ.DÄDcó|—t«}t«}|D]Ó}|tjk7rtjj |«}t
d«D]‘}t|«}tjj||«} tj|td«} tj|d«tj|« tj|«|ccSŒÕt+t,j.d|z«‚#tj|«wxYw#tj|«wxYw#t$rYŒòt$r^tj dk(rFtjj#|«r'tj$|tj&«rY�ŒSY�Œ—t($rY�Œ£wxYw)aqCalculate the default directory to use for temporary files.
This routine should be called exactly once.
We determine whether or not a candidate temp dir is usable by
trying to create and write to a file in that directory. If this
is successful, the test file is deleted. To prevent denial of
service, the name of the test file must be randomized.édé€sblatrRz)No usable temporary directory found in %s)r1r`rr\rWÚabspathÚrangeÚnextrEÚopenÚ_bin_openflagsÚwriteÚcloseÚunlinkÚFileExistsErrorÚPermissionErrorrUÚisdirÚaccessÚW_OKrÚFileNotFoundErrorÚ_errnoÚENOENT)Únamerr]r-ÚseqrUÚfilenameÚfds rÚ_get_default_tempdirrx·sS€ô
Ó !€EÜ%Ó'€GàòˆØ ”#—*‘*Ò Ü—(‘(×"Ñ" 3Ó'ˆC䘓:ò ˆCܘ“;ˆDÜ—x‘x—}‘} S¨$Ó/ˆHð
Ü—X‘X˜h¬¸Ó>�ð)ð&ÜŸ ™  " gÔ.äŸ ™  "�
ä—J‘J˜xÔ(Ø”
ñ ð ô8 œFŸM™MØGØ#ñ$ó %ð%øôŸ ™  "�
ûä—J‘J˜xÕ(ûä"ò
ÙÜ"ò
ô—H‘H Ò$¬¯©¯©¸Ô)<Ü—J‘J˜s¤C§H¡HÔ-ÚÛÜò
Ûð
úsIÂD>Â#D
Â9D$ÃD>Ä
D!Ä!D$Ä$D;Ä;D>Ä> F;Å AF;Æ.F;Æ:F;cóÊ—t€?tj« t€
t«atj «tStS#tj «wxYw)z7Common setup sequence for all user-callable interfaces.)Ú_name_sequenceÚ
_once_lockÚacquirer1Úreleaser>r'rÚ_get_candidate_namesr~åsP€ôÐÜ×ÑÔð !ÜÐ%Ü!4Ó!6�ä × Ñ Ô Ü ÐŒ>Ðøô
× Ñ Õ úó œA Á A"cóœ—tjj|«}t«}|turt tj |«}tt«D]f}t|«}tjj|||z|z«}tjd|« tj||d«} | |fcStt(j*d«‚#t$rYŒŽt$rZtj dk(rEtjj#|«r&tj$|tj&«rYŒî‚wxYw)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.ztempfile.mkstemprcrRz#No usable temporary file name found)rrWrdr~r Úmapr*rer rfrEÚ_sysÚauditrgrlrmrUrnrorprrÚEEXIST)
r-ÚpreÚsufÚflagsr.ÚnamesrurUÚfilerws
rÚ_mkstemp_innerrŠós
€ô �(‰(×
Ñ
˜3Ó
€CÜ Ó "€EØ”eÑÜ”C—L‘L %Ó(ˆä”W‹~òˆÜ�E‹{ˆÜ�x‰x�}‰}˜S #¨¡*¨sÑ"2Ó3ˆÜ �
‰
Ð% tÔ,ð Ü—‘˜$  uÓ-ˆBð�4ˆxŠð!ô$ œ&Ÿ-™-Ø?ó AðAøôò Ù Üò ô—‘˜DÒ ¤S§X¡X§^¡^°CÔ%8Ü—
‘
˜3¤§¡Ô)Ùàð úsÂ&Cà E Ã)AE Å E cóº—|tjvr
||g|¢­ddiŽytjdk(stjj |«s
||g|¢­Žyy)NÚfollow_symlinksFrR)rÚsupports_follow_symlinksrUrWÚislink)ÚfuncrWr#s rÚ_dont_follow_symlinksr�sO€à Œs×+Ñ+Ñ+Ù ˆTÐ0�DÒ0¨%Ó0Ü �‰�TÒ ¤§¡§¡°Ô!6Ù ˆTÐ�DÔð"7r'có”— tj}t||d«ttj|d«y#t$rYŒ'wxYw)NréÀ)rÚchflagsr�r[Úchmod)rWr“s rÚ _resetpermsr•sB€ð0Ü—+‘+ˆô ˜g t¨QÔ/Üœ#Ÿ)™) T¨5Õ1øô ò
Ù ð
ús‚;» AÁAcó4—tjt«S)z7The default prefix for temporary directories as string.)rÚfsdecoder)r>r'rr
r
#ó€ä �<‰<œÓ !Ð!r'có4—tjt«S)z6The default prefix for temporary directories as bytes.)rr*r)r>r'rr
r
'r˜r'cóÊ—t€?tj« t€
t«atj «tStS#tj «wxYw)z&Private accessor for tempfile.tempdir.)r r{r|rxr}r>r'rÚ _gettempdirr›-sL€ô€Ü×ÑÔð !܈Ü.Ó0�ä × Ñ Ô Ü €NŒ7€Nøô
× Ñ Õ úrcó<—tjt««S)z Returns tempfile.tempdir as str.)rr—r›r>r'rr r 9ó€ä �<‰<œ ›
Ó &Ð&r'có<—tjt««S)z"Returns tempfile.tempdir as bytes.)rr*r›r>r'rrr=r�r'cób—t|||«\}}}}|rt}nt}t|||||«S)aŒUser-callable function to create and return a unique temporary
file. The return value is a pair (fd, name) where fd is the
file descriptor returned by os.open, and name is the filename.
If 'suffix' is not None, the file name will end with that suffix,
otherwise there will be no suffix.
If 'prefix' is not None, the file name will begin with that prefix,
otherwise a default prefix is used.
If 'dir' is not None, the file will be created in that directory,
otherwise a default directory is used.
If 'text' is specified and true, the file is opened in text
mode. Else (the default) the file is opened in binary mode.
If any of 'suffix', 'prefix' and 'dir' are not None, they must be the
same type. If they are bytes, the returned name will be bytes; str
otherwise.
The file is readable and writable only by the creating user ID.
If the operating system uses permission bits to indicate whether a
file is executable, the file is executable by no one. The file
descriptor is not inherited by children of this process.
Caller is responsible for deleting the file when done with it.
)r/Ú_text_openflagsrhrŠ)r,r+r-Útextr.r‡s rrrAs;€ô:(8¸ÀÈÓ'LÑ$€FˆF�C˜á ܉äˆä ˜#˜v v¨u°kÓ BÐBr'có¸—t|||«\}}}}t«}|turttj
|«}t
t«D]€}t|«}tjj|||z|z«}tjd|« t j|d«tjj)|«cStt*j,d«‚#t$rYŒ¨t$r[tj dk(rFtjj#|«r't j$|tj&«rY�Œ ‚wxYw)aUser-callable function to create and return a unique temporary
directory. The return value is the pathname of the directory.
Arguments are as for mkstemp, except that the 'text' argument is
not accepted.
The directory is readable, writable, and searchable only by the
creating user.
Caller is responsible for deleting the directory when done with it.
ztempfile.mkdtempr’rRz(No usable temporary directory name found)r/r~r r�rr*rer rfrWrEr‚rƒÚmkdirrlrmrUrnrorprdrrr„)r,r+r-r.rˆrurUr‰s rrrhs€ô(8¸ÀÈÓ'LÑ$€FˆF�C˜ä Ó "€EØ”eÑÜ”C—L‘L %Ó(ˆä”W‹~ò&ˆÜ�E‹{ˆÜ�x‰x�}‰}˜S &¨4¡-°&Ñ"8Ó9ˆÜ �
‰
Ð% tÔ,ð Ü �I‰I�d˜EÔ "ô�x‰x×Ñ Ó%Ò%ð!&ô$ œ&Ÿ-™-ØDó FðFøôò Ù Üò ô—‘˜DÒ ¤S§X¡X§^¡^°CÔ%8Ü—
‘
˜3¤§¡Ô)Úàð úsÂC+Ã+ EÃ6AEÅErBcó
—|€
t«}t«}tt«D]B}t |«}t
j j|||z|z«}t|«rŒ@|cSttjd«‚)aêUser-callable function to return a unique temporary file name. The
file is not created.
Arguments are similar to mkstemp, except that the 'text' argument is
not accepted, and suffix=None, prefix=None and bytes file names are not
supported.
THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED. The file name may
refer to a file that did not exist at some point, but by the time
you get around to creating it, someone else may have beaten you to
the punch.
z"No usable temporary filename found) r r~rer rfrrWrErrlrrr„)r,r+r-rˆrurUr‰s rrr�sw€ð$ €{Ü‹lˆä Ó "€EÜ”W‹~òˆÜ�E‹{ˆÜ�x‰x�}‰}˜S &¨4¡-°&Ñ"8Ó9ˆÜ�t�}ØŠKð ô œ&Ÿ-™-Ø>ó @ð@r'cóf—eZdZdZdZdZd d„Zejdk(ejfd„Z
d„Z d„Z y)
Ú_TemporaryFileCloserz–A separate object allowing proper closing of a temporary file's
underlying file object, without adding a __del__ method to the
temporary file.Fcó<—||_||_||_||_yr=)r‰rUÚdeleteÚdelete_on_close©r9r‰rUr¨r©s rÚ__init__z_TemporaryFileCloser.__init__¸s€ØˆŒ ؈Œ ؈Œ Ø.ˆÕr'rRcóŠ—|jsed|_ |js!d|_|jj«|jr#|r |j
s ||j «yyyy#t$rYywxYw#|jr2|r |j
s# ||j «w#t$rYwwxYwwwxYw©NT)Úcleanup_calledÚ close_calledr‰rjr¨r©rUrq)r9Úwindowsrks rÚcleanupz_TemporaryFileCloser.cleanup¾s»€Ø×"Ò"Ø"&ˆDÔ ð
Ø×(Ò(Ø(,�DÔ%Ø—I‘I—O‘OÔ%ð—;’;©°D×4HÒ4HðÙ˜tŸy™yÕ)ð5I�;ð#øô-òÙðûð—;’;©°D×4HÒ4HðÙ˜tŸy™yÕ)øÜ,òÙðúð5I�;úsA•-BÁA3Á3 A?Á>A?ÂCÂB1Â0CÂ1 B=Â:CÂ<B=Â=Ccó—|jsMd|_ |jj«|jr|jr|j «yyyy#|jr|jr|j «wwwxYwr­)r¯r‰rjr¨r©r±r?s rrjz_TemporaryFileCloser.closeÎsm€Ø× Ò Ø $ˆDÔ ð
#Ø— ‘ —‘Ô!à—;’; 4×#7Ò#7Ø—L‘L•Nð$8�;ð !øð
—;’; 4×#7Ò#7Ø—L‘L•Nð$8�;ús •AÁ,Bcó$—|j«yr=)r±r?s rÚ__del__z_TemporaryFileCloser.__del__×s €Ø � ‰ �r'N©TT)
rIrJrKrLr®r¯r«rrUrkr±rjr´r>r'rr¦r¦°s;„ñð€NØ€Ló/ð #Ÿx™x¨4Ñ/¸¿¹óò #ór'r¦có6—eZdZdZd d„Zd„Zd„Zd„Zd„Zd„Z y)
Ú_TemporaryFileWrapperzÄTemporary file wrapper
This class provides a wrapper around files opened for
temporary use. In particular, it seeks to automatically
remove the file when it is no longer needed.
cóF—||_||_t||||«|_yr=)r‰rUr¦Ú_closerrªs rr«z_TemporaryFileWrapper.__init__ãs%€ØˆŒ ؈Œ Ü+¨D°$¸Ø,;ó=ˆ� r'cóô‡—|jd}t||«}t|d«r2|Štj‰«ˆfd„«}|j
|_|}t
|t«s
t|||«|S)Nr‰Ú__call__có•—‰|i|¤ŽSr=r>)r#Úkwargsr�s €rÚ func_wrapperz7_TemporaryFileWrapper.__getattr__.<locals>.func_wrapperñsø€á˜TÐ, VÑ,Ð,r') Ú__dict__r6ÚhasattrÚ
_functoolsÚwrapsr¹rÚintÚsetattr)r9rUr‰Úar¾r�s @rÚ __getattr__z!_TemporaryFileWrapper.__getattr__ésyø€ð�}‰}˜VÑ$ˆÜ �D˜$Ó ˆÜ �1�jÔ !؈DÜ
×
Ñ
˜dÓ
#ó
-ó$ð
-ð$(§<¡<ˆLÔ ØˆAܘ!œSÔ!Ü �D˜$ Ô "؈r'có:—|jj«|Sr=)r‰Ú __enter__r?s rrÈz_TemporaryFileWrapper.__enter__þs€Ø � ‰ ×ÑÔØˆ r'cót—|jj|||«}|jj«|Sr=)r‰Ú__exit__r¹r±)r9ÚexcÚvalueÚtbÚresults rrÊz_TemporaryFileWrapper.__exit__s/€Ø—‘×#Ñ# C¨°Ó3ˆØ � ‰ ×ÑÔØˆ
r'có8—|jj«y)zA
Close the temporary file, possibly deleting it.
N)r¹rjr?s rrjz_TemporaryFileWrapper.close s€ð
� ‰ ×ÑÕr'c#ó6K—|jD]}|–—Œy­wr=)r‰)r9Úlines rr@z_TemporaryFileWrapper.__iter__s èø€ð —I‘Iò ˆDØ‹Jñ ùs‚Nrµ)
rIrJrKrLr«rÆrÈrÊrjr@r>r'rr·r·Ûs%„ñó=ò ò*ò ò
ór'r·T)Úerrorsr©c ó
‡‡‡‡
‡‡—t‰‰‰«\ŠŠŠŠtŠ
tjdk(r|r| r‰
tjzŠ
d|vrt j |«}dŠˆˆ
ˆˆˆˆfd„}
t j‰||||||
¬«} t| d| «} t| d| «} ‰| _t| ‰|| «S#| j«‚xYw#‰�,tjdk(r|r| stj‰«‚xYw)a“Create and return a temporary file.
Arguments:
'prefix', 'suffix', 'dir' -- as for mkstemp.
'mode' -- the mode argument to io.open (default "w+b").
'buffering' -- the buffer size argument to io.open (default -1).
'encoding' -- the encoding argument to io.open (default None)
'newline' -- the newline argument to io.open (default None)
'delete' -- whether the file is automatically deleted (default True).
'delete_on_close' -- if 'delete', whether the file is deleted on close
(default True) or otherwise either on context manager exit
(if context manager was used) or on object finalization. .
'errors' -- the errors argument to io.open (default None)
The file is created as mkstemp() would do it.
Returns an object with a file-like interface; the name of the file
is accessible as its 'name' attribute. The file will be automatically
deleted when it is closed unless the 'delete' argument is set to False.
On POSIX, NamedTemporaryFiles cannot be automatically deleted if
the creating process is terminated abruptly with a SIGKILL signal.
Windows can delete the file even in this case.
rRÚbNcó,•—t‰‰‰‰‰«\}Š|Sr=)rŠ)r#rwr-r‡rUr.r+r,s €€€€€€rÚopenerz"NamedTemporaryFile.<locals>.openerAsø€ä! # v¨v°u¸kÓJ‰ˆˆD؈ r'©Ú bufferingÚnewlineÚencodingrÒrÖÚbufferÚraw) r/rhrrUÚ O_TEMPORARYÚ_ioÚ
text_encodingrgr6r·rjrk)ÚmoderØrÚrÙr,r+r-r¨rÒr©rÖr‰rÜr‡rUr.s ``` @@@rrrsý€ô6(8¸ÀÈÓ'LÑ$€FˆF�C˜ä €Eô ‡x�x�4Ò™F¡Ø
”—‘Ñ ˆà
�$�Ü×$Ñ$ XÓ.ˆà €D÷ñðÜ�x‰x˜˜T¨YØ '°(À6Ø%ô'ˆð ܘ$ ¨$Ó/ˆCܘ#˜u cÓ*ˆC؈CŒHÜ(¨¨t°V¸_ÓMÐ Møð Ø �J‰JŒLØ ûðØ Ð Ü �H‰H˜Ò ¡©OÜ �J‰J�tÔ Ø
úsÁ/C .B;Â;CÃCÃ1DÚposixÚcygwinÚ O_TMPFILE©rÒc óÚ‡‡‡‡ ‡ ‡
—d|vrtj|«}t‰‰‰«\ŠŠŠŠ
tŠ trIdŠ ˆˆ ˆ fd„} tj
‰||||||¬«} t
| d| «}
t
|
d|
«}
‰ |
_| SdŠ ˆˆ ˆ ˆ
ˆˆfd„}tj
‰||||||¬«} t
| d| «}
t
|
d|
«}
‰ |
_| S#t$rdaYŒXt$rYŒbwxYw) a€Create and return a temporary file.
Arguments:
'prefix', 'suffix', 'dir' -- as for mkstemp.
'mode' -- the mode argument to io.open (default "w+b").
'buffering' -- the buffer size argument to io.open (default -1).
'encoding' -- the encoding argument to io.open (default None)
'newline' -- the newline argument to io.open (default None)
'errors' -- the errors argument to io.open (default None)