3 0fm@s>dddddddddd d d d g Zd dlZd dlZd dlZd dlZd dl Z d dl Z d dl mZd dlZy d dlZWnek rd dlZYnXejZejejBejBZeedreejOZeZeedreejOZeedrejZndZdZ eZ!eedrej"Z#needrej$Z#nddZ#ddZ%ddZ&ddZ'GdddZ(d d!Z)d"d#Z*da+d$d%Z,d&d'Z-d(d)Z.d*d+Z/d,dZ0d-d Z1da2d.d Z3d/d Z4dCd1dZ5dDd2dZ6d3e dfd4dZ7Gd5d6d6Z8Gd7d8d8Z9dFdkre:Z>need?a?dHd@dZ>GdAddZ@GdBddeAZBdS)INamedTemporaryFile TemporaryFileSpooledTemporaryFileTemporaryDirectorymkstempmkdtempmktempTMP_MAX gettempprefixtempdir gettempdirgettempprefixb gettempdirbN)Random O_NOFOLLOWO_BINARYi'ZtmplstatstatcCstj|tj}tj|dS)N)_osopenO_RDONLYclose)fnfdr /usr/lib64/python3.6/tempfile.py_statTsrc Cs*y t|Wntk r dSXdSdS)NFT)rOSError)rrrr_existsXs  rcGs`d}xJ|D]B}|dkrq t|tr8|tkr2tdt}q |tkrHtdt}q W|dkr\tS|S)Nz1Can't mix bytes and non-bytes in path components.) isinstancebytesstr TypeError)argsZ return_typeargrrr_infer_return_typeas  r%cCsdt|||}|dkr|}|dkr:|tkr0t}n tjt}|dkrX|tkrRt}nt}||||fS)N)r%r!templaterfsencoder r )prefixsuffixdir output_typerrr_sanitize_paramsvs  r,c@s,eZdZdZeddZddZddZdS) _RandomNameSequenceZ%abcdefghijklmnopqrstuvwxyz0123456789_cCs,tj}|t|ddkr&t|_||_|jS)N_rng_pid)rgetpidgetattr_RandomZ_rngr.)selfZcur_pidrrrrngs z_RandomNameSequence.rngcCs|S)Nr)r2rrr__iter__sz_RandomNameSequence.__iter__cs0|j|jjfddtdD}dj|S)Ncsg|] }qSrr).0Zdummy)cchooserr sz0_RandomNameSequence.__next__..) charactersr3Zchoicerangejoin)r2Zlettersr)r6r7r__next__sz_RandomNameSequence.__next__N)__name__ __module__ __qualname__r;propertyr3r4r>rrrrr-s r-c Csg}x$dD]}tj|}|r |j|q Wtjdkr\|jtjjdtjjdddd d gn|jd d d gy|jtjWn$t t fk r|jtj YnX|S)NTMPDIRTEMPTMPntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmpz/tmpz/var/tmpz/usr/tmp)rCrDrE) rgetenvappendnameextendpath expanduser expandvarsgetcwdAttributeErrorrcurdir)dirlistZenvnamedirnamerrr_candidate_tempdir_lists    rScCs4t}t}x|D]}|tjkr0tjj|}xtdD]}t|}tjj||}y\tj |t d}zt k rtj dkrtjj|rtj|tjrw$nYnX| tjj|fSWt tjddS)NirFz#No usable temporary file name found)rmr maprr'r<rrXrKr=rr]r^rIr_r`rarWrcEEXIST) r*ZpreZsufflagsr+namesrerIfilerrrr_mkstemp_inners$ rscGsJ|tjkr ||f|ddin&tjdks8tjj| rF||f|dS)Nfollow_symlinksFrF)rsupports_follow_symlinksrIrKislink)funcrKr#rrr_dont_follow_symlinkss rxc Cs>y tj}Wntk rYnXt||dttj|ddS)Nri)rchflagsrOrxchmod)rKryrrr _resetpermss   r{cCstS)N)r&rrrrr *scCs tjtS)N)rr'r rrrrr .sc Cs2tdkr.tjztdkr taWdtjXtS)N)r rjrkrhrlrrrrr 4s  cCs tjtS)N)rr'r rrrrr @sFcCs2t|||\}}}}|rt}nt}t|||||S)N)r,_text_openflagsrYrs)r)r(r*textr+rprrrrDs c Cst|||\}}}}t}|tkr.ttj|}xttD]}t|}tj j ||||}ytj |dWnRt k rw8Yn>t k rtjdkrtj j|rtj|tjrw8nYnX|SWt tjddS)NirFz(No usable temporary directory name found)r,rmr rnrr'r<rrXrKr=mkdirr]r^rIr_r`rarcro)r)r(r*r+rqrerIrrrrrrls&  r:cCs`|dkrt}t}x:ttD].}t|}tjj||||}t|s|SqWt t j ddS)Nz"No usable temporary filename found) r rmr<rrXrrKr=rr]rcro)r)r(r*rqrerIrrrrrrsc@sHeZdZdZdZd ddZejdkr|j r:|jdk r:d|_z|jjWd|jr8||jXdS)NT) close_calledrrrrrI)r2r\rrrrs z_TemporaryFileCloser.closecCs |jdS)N)r)r2rrr__del__sz_TemporaryFileCloser.__del__cCs|jsd|_|jjdS)NT)rrrr)r2rrrrs)T) r?r@rArrrrrrIr\rrrrrrrs   rc@s>eZdZdddZddZddZdd Zd d Zd d ZdS)_TemporaryFileWrapperTcCs$||_||_||_t||||_dS)N)rrrIrr_closer)r2rrrIrrrrrsz_TemporaryFileWrapper.__init__cs^|jd}t||}t|drD|tjfdd}|j|_|}t|tsZt||||S)Nrr__call__cs ||S)Nr)r#kwargs)rwrr func_wrappersz7_TemporaryFileWrapper.__getattr__..func_wrapper) __dict__r0hasattr _functoolswrapsrrintsetattr)r2rIrrarr)rwr __getattr__s     z!_TemporaryFileWrapper.__getattr__cCs|jj|S)N)rr __enter__)r2rrrrs z_TemporaryFileWrapper.__enter__cCs|jj|||}|j|S)N)rr__exit__r)r2excvaluetbresultrrrrsz_TemporaryFileWrapper.__exit__cCs|jjdS)N)rr)r2rrrr sz_TemporaryFileWrapper.closeccsx|jD] }|VqWdS)N)rr)r2linerrrr4s z_TemporaryFileWrapper.__iter__N)T) r?r@rArrrrrr4rrrrrs  rw+bTc Cst|||\}}}}t} tjdkr0|r0| tjO} t|||| |\} } y tj| ||||d} t| | |St k rtj | tj | YnXdS)NrF) bufferingnewlineencoding) r,rYrrIZ O_TEMPORARYrsrZrr BaseExceptionr\r) moderrrr)r(r*rr+rprrIrrrrrrs      posixcygwin O_TMPFILEc Cst|||\}}}}t}try$|tjBtj@} tj|| d} Wn*tk rXdaYnBtk rjYn0Xyt j| ||||dStj | YnXt |||||\} } ytj | t j| ||||dStj | YnXdS)NiF)rrr) r,rY_O_TMPFILE_WORKSrrO_CREATrIsADirectoryErrorrrZrrsr\) rrrrr)r(r*r+rpZflags2rrIrrrrNs0       c@seZdZdZd7ddZdd Zd d Zd d ZddZddZ ddZ e ddZ e ddZ ddZddZddZe ddZe d d!Ze d"d#Zd$d%Zd&d'Zd(d)Zd*d+Ze d,d-Zd.d/Zd8d0d1Zd2d3Zd4d5ZdS)9rFrw+brNc CsHd|krtj|_ntjdd|_||_d|_|||||||d|_dS)Nb )rF)rrr)r(rrr*)rZBytesIO_fileStringIO _max_size_rolled_TemporaryFileArgs) r2max_sizerrrrr)r(r*rrrrs zSpooledTemporaryFile.__init__cCs,|jr dS|j}|r(|j|kr(|jdS)N)rrtellrollover)r2rrrrrr_checks zSpooledTemporaryFile._checkcCsN|jr dS|j}tf|j}|_|`|j|j|j|jdd|_dS)NrT)rrrrr[getvalueseekr)r2rrZnewfilerrrrszSpooledTemporaryFile.rollovercCs|jjrtd|S)Nz%Cannot enter context with closed file)rclosed ValueError)r2rrrrszSpooledTemporaryFile.__enter__cCs|jjdS)N)rr)r2rrrrrrrszSpooledTemporaryFile.__exit__cCs |jjS)N)rr4)r2rrrr4szSpooledTemporaryFile.__iter__cCs|jjdS)N)rr)r2rrrrszSpooledTemporaryFile.closecCs|jjS)N)rr)r2rrrrszSpooledTemporaryFile.closedc Cs8y|jjStk r2d|jdkr(|jdSXdS)Nrrr)rrrOr)r2rrrrs zSpooledTemporaryFile.encodingcCs|j|jjS)N)rrfileno)r2rrrrszSpooledTemporaryFile.filenocCs|jjdS)N)rflush)r2rrrrszSpooledTemporaryFile.flushcCs |jjS)N)risatty)r2rrrrszSpooledTemporaryFile.isattyc Cs(y|jjStk r"|jdSXdS)Nr)rrrOr)r2rrrrszSpooledTemporaryFile.modec Cs"y|jjStk rdSXdS)N)rrIrO)r2rrrrIszSpooledTemporaryFile.namec Cs8y|jjStk r2d|jdkr(|jdSXdS)Nrrr)rnewlinesrOr)r2rrrrs zSpooledTemporaryFile.newlinescGs |jj|S)N)rread)r2r#rrrrszSpooledTemporaryFile.readcGs |jj|S)N)rreadline)r2r#rrrrszSpooledTemporaryFile.readlinecGs |jj|S)N)r readlines)r2r#rrrrszSpooledTemporaryFile.readlinescGs|jj|dS)N)rr)r2r#rrrrszSpooledTemporaryFile.seekcCs|jjS)N)r softspace)r2rrrrszSpooledTemporaryFile.softspacecCs |jjS)N)rr)r2rrrrszSpooledTemporaryFile.tellcCs6|dkr|jjn||jkr&|j|jj|dS)N)rtruncaterr)r2sizerrrrs   zSpooledTemporaryFile.truncatecCs|j}|j|}|j||S)N)rr[r)r2srrrvrrrr[s  zSpooledTemporaryFile.writecCs|j}|j|}|j||S)N)r writelinesr)r2iterablerrrrrrrs  zSpooledTemporaryFile.writelines)rrrNNNNN)N)r?r@rArrrrrrr4rrBrrrrrrrIrrrrrrrrr[rrrrrrs6        c@sNeZdZdddZeddZeddZdd Zd d Zd d Z ddZ dS)rNcCs0t||||_tj||j|jdj|d|_dS)NzImplicitly cleaning up {!r}) warn_message)rrI_weakreffinalize_cleanupformat _finalizer)r2r)r(r*rrrr(s zTemporaryDirectory.__init__cs fdd}tj|ddS)Ncst|dtr|yV|kr(ttjj|t|ytj|Wn"ttfk r`j|YnXWqt k rxYqXnt|dt rndS)Nr) issubclassr^r{rrKrRr\r_rmtreerb)rwrKexc_info)clsrIrronerror0sz+TemporaryDirectory._rmtree..onerror)r)_shutilZrmtree)rrIrr)rrIrr.szTemporaryDirectory._rmtreecCs|j|tj|tdS)N)r _warningswarnResourceWarning)rrIrrrrrEs zTemporaryDirectory._cleanupcCsdj|jj|jS)Nz <{} {!r}>)r __class__r?rI)r2rrr__repr__JszTemporaryDirectory.__repr__cCs|jS)N)rI)r2rrrrMszTemporaryDirectory.__enter__cCs |jdS)N)cleanup)r2rrrrrrrPszTemporaryDirectory.__exit__cCs|jjr|j|jdS)N)rdetachrrI)r2rrrrSs zTemporaryDirectory.cleanup)NNN) r?r@rAr classmethodrrrrrrrrrrrs   )NNNF)NNNr)rrNNNNNTr)rrNNNNN)C__all__ functoolsrwarningsriorZosrZshutilrerrnorcZrandomrr1weakrefr_thread ImportErrorZ _dummy_thread allocate_lockZ_allocate_lockO_RDWRrO_EXCLr|rrrYrrr&rjrrrrr%r,r-rSrhrirmrsrxr{r r r r r rrrrrrrIsysplatformrrrobjectrrrrrs          -   ( ' +? $  8