3 öLÖj™}ã@s¼dZddddddddd d d d d g ZddlZddlZddlZddlZ ddl Z ddl Z ddlmZddlmZddlZy ddlZWnek ršddlZYnXejZe je jBe jBZee dƒrÈee j OZeZ!ee dƒràe!e j"OZ!ee dƒròe j#Z#ndZ#dZ$eƒZ%ee dƒ�re j&Z'nee dƒ�r(e jZ'ndd„Z'dd„Z(dd„Z)dd„Z*Gd d!„d!ƒZ+d"d#„Z,d$d%„Z-da.d&d'„Z/d(d)„Z0d*d+„Z1d,d-„Z2d.d/„Z3e j4e j5e jhe j6k�o´e j4e j7kZ8d0d1„Z9ye j:e j;Be j BZd4d „Z?d5d „Z@daAd6d „ZBd7d „ZCdKd9d„ZDdLd:d„ZEd;e$dfd„d>ƒZGGd?d@„d@ƒZHdNdDd„ZIe jJdEk�s€e jKjLdFk�r†eIZMnee dGƒaNdPdHd„ZMGdId„dƒZOGdJd„dePƒZQdS)Qa�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)ÚS_ISLNKÚ O_NOFOLLOWÚO_BINARYi'ZtmpÚlstatÚstatcCstj|tjƒ}tj|ƒdS)N)Ú_osÚopenÚO_RDONLYÚclose)ÚfnÚfd©rú /usr/lib64/python3.6/tempfile.pyÚ_statUsrc Cs*y t|ƒWntk r dSXdSdS)NFT)rÚOSError)rrrrÚ_existsYs  rcGs`d}xJ|D]B}|dkrq t|tƒr8|tkr2tdƒ‚t}q |tkrHtdƒ‚t}q W|dkr\tS|S)zBLook at the type of all args and divine their implied return type.Nz1Can't mix bytes and non-bytes in path components.)Ú isinstanceÚbytesÚstrÚ TypeError)ÚargsZ return_typeÚargrrrÚ_infer_return_typebs  r&cCsdt|||ƒ}|dkr|ƒ}|dkr:|tkr0t}n tjtƒ}|dkrX|tkrRtƒ}ntƒ}||||fS)z9Common parameter processing for most APIs in this module.N)r&r"ÚtemplaterÚfsencoder r )ÚprefixÚsuffixÚdirÚ output_typerrrÚ_sanitize_paramsws  r-c@s0eZdZdZdZedd„ƒZdd„Zdd„Zd S) Ú_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.Z%abcdefghijklmnopqrstuvwxyz0123456789_cCs,tjƒ}|t|ddƒkr&tƒ|_||_|jS)NÚ_rng_pid)rÚgetpidÚgetattrÚ_RandomZ_rngr/)ÚselfZcur_pidrrrÚrng“s z_RandomNameSequence.rngcCs|S)Nr)r3rrrÚ__iter__›sz_RandomNameSequence.__iter__cs0|j‰|jj‰‡‡fdd„tdƒDƒ}dj|ƒS)Ncsg|] }ˆˆƒ‘qSrr)Ú.0Zdummy)ÚcÚchooserrú ¡sz0_RandomNameSequence.__next__..éÚ)Ú charactersr4ZchoiceÚrangeÚjoin)r3Zlettersr)r7r8rÚ__next__žsz_RandomNameSequence.__next__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__r<Úpropertyr4r5r?rrrrr.‰s  r.c Cs¨g}x$dD]}tj|ƒ}|r |j|ƒq Wtjdkr\|jtjjdƒtjjdƒddd d gƒn|jd d d gƒy|jtjƒƒWn$t t fk r¢|jtj ƒYnX|S)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\tmpz/tmpz/var/tmpz/usr/tmp)rErFrG) rÚgetenvÚappendÚnameÚextendÚpathÚ expanduserÚ expandvarsÚgetcwdÚAttributeErrorrÚcurdir)ÚdirlistZenvnameÚdirnamerrrÚ_candidate_tempdir_list¤s    rUcCs4tƒ}tƒ}�x|D�]}|tjkr0tjj|ƒ}xêtdƒD]Þ}t|ƒ}tjj||ƒ}y\tj |t dƒ}zrÚ_bin_openflagsÚ_ioÚwriterÚunlinkÚFileExistsErrorÚPermissionErrorrKÚisdirÚaccessÚW_OKrÚFileNotFoundErrorÚ_errnoÚENOENT)ZnamerrSr+ÚseqrKÚfilenamerÚfprrrÚ_get_default_tempdir¿s:    rjc Cs2tdkr.tjƒztdkr tƒaWdtjƒXtS)z7Common setup sequence for all user-callable interfaces.N)Ú_name_sequenceÚ _once_lockÚacquirer.ÚreleaserrrrÚ_get_candidate_namesîs  roc CsÎtƒ}|tkrttj|ƒ}x¢ttƒD]–}t|ƒ}tjj ||||ƒ}ytj ||dƒ} WnRt k rnw$Yn>t k rªtj dkr¤tjj|ƒr¤tj|tjƒr¤w$n‚YnX| tjj|ƒfSWt tjdƒ‚dS)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.i€rHz#No usable temporary file name foundN)ror!Úmaprr(r=rrZrMr>rr_r`rKrarbrcrYreÚEEXIST) r+ZpreZsufÚflagsr,ÚnamesrgrKÚfilerrrrÚ_mkstemp_innerüs$ rucGsJ|tjkr ||f|žddiŽn&tjdks8tjj|ƒ rF||f|žŽdS)NÚfollow_symlinksFrH)rÚsupports_follow_symlinksrKrMÚislink)ÚfuncrMr$rrrÚ_dont_follow_symlinkss rzc Cs0y tj}Wntk rYnXt||dƒdS)Nr)rÚchflagsrQrz)rMr{rrrÚ _resetflags s  r|cCst|ƒttj|dƒdS)NiÀ)r|rzrÚchmod)rMrrrÚ _resetperms(sr~cCs,|dkrt|ƒdSt|ƒtj|dƒdS)NiÀ)r~r|rr})Údir_fdrMrrrÚ_resetperms_fd3s r€cCs¼|dkrt|ƒdSt|ƒtjtjkrt k r¼tjdkr¶tj j|ƒr¶tj|tjƒr¶w8n‚YnX|SWt tjdƒ‚dS)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. iÀrHz(No usable temporary directory name foundN)r-ror!rprr(r=rrZrMr>Úmkdirr_r`rKrarbrcrerq)r*r)r+r,rsrgrKrtrrrr£s&  r;cCs`|dkrtƒ}tƒ}x:ttƒD].}t|ƒ}tjj||||ƒ}t|ƒs|SqWt t j dƒ‚dS)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. Nz"No usable temporary filename found) r ror=rrZrrMr>rr_rerq)r*r)r+rsrgrKrtrrrrÊsc@sLeZdZdZdZdZd dd„Zejdkr@ej fdd „Z d d „Z nd d „Z dS)Ú_TemporaryFileCloserz–A separate object allowing proper closing of a temporary file's underlying file object, without adding a __del__ method to the temporary file.NFTcCs||_||_||_dS)N)rtrKÚdelete)r3rtrKr‰rrrÚ__init__òsz_TemporaryFileCloser.__init__rHc Cs>|j r:|jdk r:d|_z|jjƒWd|jr8||jƒXdS)NT)Ú close_calledrtrr‰rK)r3r^rrrrs z_TemporaryFileCloser.closecCs |jƒdS)N)r)r3rrrÚ__del__ sz_TemporaryFileCloser.__del__cCs|jsd|_|jjƒdS)NT)r‹rtr)r3rrrrs)T) r@rArBrCrtr‹rŠrrKr^rrŒrrrrrˆês   rˆc@sBeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)Ú_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. TcCs$||_||_||_t|||ƒ|_dS)N)rtrKr‰rˆÚ_closer)r3rtrKr‰rrrrŠsz_TemporaryFileWrapper.__init__cs^|jd}t||ƒ}t|dƒrD|‰tjˆƒ‡fdd„ƒ}|j|_|}t|tƒsZt|||ƒ|S)NrtÚ__call__cs ˆ||ŽS)Nr)r$Úkwargs)ryrrÚ func_wrapper+sz7_TemporaryFileWrapper.__getattr__..func_wrapper) Ú__dict__r1ÚhasattrÚ _functoolsÚwrapsrŽr ÚintÚsetattr)r3rKrtÚar‘r)ryrÚ __getattr__#s     z!_TemporaryFileWrapper.__getattr__cCs|jjƒ|S)N)rtÚ __enter__)r3rrrrš8s z_TemporaryFileWrapper.__enter__cCs|jj|||ƒ}|jƒ|S)N)rtÚ__exit__r)r3ÚexcÚvalueÚtbÚresultrrrr›>sz_TemporaryFileWrapper.__exit__cCs|jjƒdS)zA Close the temporary file, possibly deleting it. N)rŽr)r3rrrrCsz_TemporaryFileWrapper.closeccsx|jD] }|VqWdS)N)rt)r3Úlinerrrr5Js z_TemporaryFileWrapper.__iter__N)T) r@rArBrCrŠr™ršr›rr5rrrrr�s r�úw+béTc Cs”t|||ƒ\}}}}t} tjdkr0|r0| tjO} t|||| |ƒ\} } y tj| ||||d�} t| | |ƒSt k rŽtj | ƒtj | ƒ‚YnXdS)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 deleted on close (default True). 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. rH)Ú bufferingÚnewlineÚencodingN) r-r[rrKZ O_TEMPORARYrur\rr�Ú BaseExceptionr^r) Úmoder£r¥r¤r*r)r+r‰r,rrrrKrtrrrrTs      ÚposixÚcygwinÚ O_TMPFILEc Csêt|||ƒ\}}}}t}tršy$|tjBtj@} tj|| dƒ} Wn*tk rXdaYnBtk rjYn0Xyt j| ||||d�Stj | ƒ‚YnXt |||||ƒ\} } ytj | ƒt j| ||||d�Stj | ƒ‚YnXdS)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) The file is created as mkstemp() would do it. Returns an object with a file-like interface. The file has no name, and will cease to exist when it is closed. i€F)r£r¤r¥N) r-r[Ú_O_TMPFILE_WORKSrrªÚO_CREATrÚIsADirectoryErrorrr\rrur^) r§r£r¥r¤r*r)r+r,rrZflags2rrKrrrr…s0       c@sðeZdZdZdZd8dd„Zd d „Zd d „Zd d„Zdd„Z dd„Z dd„Z e dd„ƒZ e dd„ƒZdd„Zdd„Zdd„Ze dd „ƒZe d!d"„ƒZe d#d$„ƒZd%d&„Zd'd(„Zd)d*„Zd+d,„Ze d-d.„ƒZd/d0„Zd9d1d2„Zd3d4„Zd5d6„ZdS):rz�Temporary file wrapper, specialized to switch from BytesIO or StringIO to a real file when it exceeds a certain size or when a fileno is needed. Frúw+br¢Nc CsHd|krtjƒ|_ntjdd�|_||_d|_|||||||dœ|_dS)NÚbÚ )r¤F)r§r£r*r)r¥r¤r+)r\ÚBytesIOÚ_fileÚStringIOÚ _max_sizeÚ_rolledÚ_TemporaryFileArgs) r3Úmax_sizer§r£r¥r¤r*r)r+rrrrŠÆs zSpooledTemporaryFile.__init__cCs,|jr dS|j}|r(|jƒ|kr(|jƒdS)N)rµr´ÚtellÚrollover)r3rtr·rrrÚ_check×s zSpooledTemporaryFile._checkcCsN|jr dS|j}tf|jŽ}|_|`|j|jƒƒ|j|jƒdƒd|_dS)NrT)rµr²rr¶r]ÚgetvalueÚseekr¸)r3rtZnewfilerrrr¹ÝszSpooledTemporaryFile.rollovercCs|jjrtdƒ‚|S)Nz%Cannot enter context with closed file)r²ÚclosedÚ ValueError)r3rrrršîszSpooledTemporaryFile.__enter__cCs|jjƒdS)N)r²r)r3rœr�ržrrrr›ószSpooledTemporaryFile.__exit__cCs |jjƒS)N)r²r5)r3rrrr5÷szSpooledTemporaryFile.__iter__cCs|jjƒdS)N)r²r)r3rrrrúszSpooledTemporaryFile.closecCs|jjS)N)r²r½)r3rrrr½ýszSpooledTemporaryFile.closedc Cs8y|jjStk r2d|jdkr(‚|jdSXdS)Nr¯r§r¥)r²r¥rQr¶)r3rrrr¥s zSpooledTemporaryFile.encodingcCs|jƒ|jjƒS)N)r¹r²Úfileno)r3rrrr¿ szSpooledTemporaryFile.filenocCs|jjƒdS)N)r²Úflush)r3rrrrÀszSpooledTemporaryFile.flushcCs |jjƒS)N)r²Úisatty)r3rrrrÁszSpooledTemporaryFile.isattyc Cs(y|jjStk r"|jdSXdS)Nr§)r²r§rQr¶)r3rrrr§szSpooledTemporaryFile.modec Cs"y|jjStk rdSXdS)N)r²rKrQ)r3rrrrKszSpooledTemporaryFile.namec Cs8y|jjStk r2d|jdkr(‚|jdSXdS)Nr¯r§r¤)r²ÚnewlinesrQr¶)r3rrrrÂ"s zSpooledTemporaryFile.newlinescGs |jj|ŽS)N)r²Úread)r3r$rrrrÃ+szSpooledTemporaryFile.readcGs |jj|ŽS)N)r²Úreadline)r3r$rrrrÄ.szSpooledTemporaryFile.readlinecGs |jj|ŽS)N)r²Ú readlines)r3r$rrrrÅ1szSpooledTemporaryFile.readlinescGs|jj|ŽdS)N)r²r¼)r3r$rrrr¼4szSpooledTemporaryFile.seekcCs|jjS)N)r²Ú softspace)r3rrrrÆ7szSpooledTemporaryFile.softspacecCs |jjƒS)N)r²r¸)r3rrrr¸;szSpooledTemporaryFile.tellcCs6|dkr|jjƒn||jkr&|jƒ|jj|ƒdS)N)r²Útruncater´r¹)r3ÚsizerrrrÇ>s   zSpooledTemporaryFile.truncatecCs|j}|j|ƒ}|j|ƒ|S)N)r²r]rº)r3ÚsrtÚrvrrrr]Fs  zSpooledTemporaryFile.writecCs|j}|j|ƒ}|j|ƒ|S)N)r²Ú writelinesrº)r3ÚiterablertrÊrrrrËLs  zSpooledTemporaryFile.writelineséÿÿÿÿ)rr®rÍNNNNN)N)r@rArBrCrµrŠrºr¹ršr›r5rrDr½r¥r¿rÀrÁr§rKrÂrÃrÄrÅr¼rÆr¸rÇr]rËrrrrr¿s8        c@sTeZdZdZddd„Zeddd„ƒZedd „ƒZd d „Zd d „Z dd„Z dd„Z dS)ra+Create and return a temporary directory. This has the same behavior as mkdtemp but can be used as a context manager. For example: with TemporaryDirectory() as tmpdir: ... Upon exiting the context, the directory and everything contained in it are removed. NcCs0t|||ƒ|_tj||j|jdj|ƒd�|_dS)NzImplicitly cleaning up {!r})Ú warn_message)rrKÚ_weakrefÚfinalizeÚ_cleanupÚformatÚ _finalizer)r3r*r)r+rrrrŠ_s zTemporaryDirectory.__init__Fcs8ˆdkr ˆ‰d‡‡‡‡‡fdd„ }tjˆ||dd�dS)Ncsjt|dtƒ�rLˆr&|ˆkr&ˆr$dS‚ˆ|tˆƒd…}|dksHt rT|d}}n|dkrb|}n|}y¬|ˆkr‚t|tjj|ƒƒt|||ƒytj ||d�Wnnt k r̈j |ˆ|ˆk||d�YnDtk �rtjj |ƒsòˆrðdS‚ˆj |ˆ|ˆk||d�YnXWn6t k �r(Yn"tk �rHˆ�rBdS‚YnXnt|dt ƒ�r^nˆ�sf‚dS)Nr)r)Ú ignore_errorsÚrepeatedrÚfullname)Ú issubclassr`ÚlenÚ_rmtree_use_dir_fdr€rrMrTr„r^r­Ú_rmtreerardr)ryrMÚexc_infoZ entry_namerZfullpathÚbase)ÚclsrÖrÔrKrÕrrÚonerrorksN     z+TemporaryDirectory._rmtree..onerrorT)rÞrZ _onexc_kwargs)NN)Ú_shutilZrmtree)rÝrKrÔrÕrrÖrÞr)rÝrÖrÔrKrÕrrÚes ; zTemporaryDirectory._rmtreecCs|j|ƒtj|tƒdS)N)rÚÚ _warningsÚwarnÚResourceWarning)rÝrKrÎrrrrÑ©s zTemporaryDirectory._cleanupcCsdj|jj|jƒS)Nz <{} {!r}>)rÒÚ __class__r@rK)r3rrrÚ__repr__®szTemporaryDirectory.__repr__cCs|jS)N)rK)r3rrrrš±szTemporaryDirectory.__enter__cCs |jƒdS)N)Úcleanup)r3rœr�ržrrrr›´szTemporaryDirectory.__exit__cCs|jjƒr|j|jƒdS)N)rÓÚdetachrÚrK)r3rrrrå·s zTemporaryDirectory.cleanup)NNN)FFNN) r@rArBrCrŠÚ classmethodrÚrÑräršr›rårrrrrSs   B )NNNF)NNNrÍ)r¡rÍNNNNNTrÍ)r¡rÍNNNNN)RrCÚ__all__Ú functoolsr”ÚwarningsràÚior\ÚosrZshutilrßÚerrnoreZrandomrr2rrr‚ÚweakrefrÏÚ_threadÚ ImportErrorZ _dummy_threadÚ allocate_lockZ_allocate_lockÚO_RDWRr¬ÚO_EXCLr…r“rr[rrr'rlrrrr&r-r.rUrjrkrorurzr|r~r}r^Úsupports_dir_fdÚ supports_fdrÙr€rÚ O_NONBLOCKr�rQr„r r r r r rrrrˆr�rrKÚsysÚplatformrr«rÚobjectrrrrrÚsž           -  !  ( ' +? $  8