B IoLl @sdddddddddd d d d g Zd dlZd dlZd dlZd dlZd dl Z d dl Z d dl mZd dlZd dlZejZejejBejBZeedreejOZeZeedreejOZeedrejZndZdZeZeedrej Z!needrej"Z!nddZ!ddZ#ddZ$ddZ%GdddZ&d d!Z'd"d#Z(da)d$d%Z*d&d'Z+d(dZ,d)d Z-da.d*d Z/d+d Z0d?d-dZ1d@d.dZ2d/edfd0dZ3Gd1d2d2Z4Gd3d4d4Z5dAd8dZ6ej7d9ksej8j9d:kre6Z:need;a;dBddde=Z>dS)CNamedTemporaryFile TemporaryFileSpooledTemporaryFileTemporaryDirectorymkstempmkdtempmktempTMP_MAX gettempprefixtempdir gettempdirgettempprefixb gettempdirbN)Random O_NOFOLLOWO_BINARYi'ZtmplstatstatcCst|tj}t|dS)N)_osopenO_RDONLYclose)fnfdr+/opt/alt/python37/lib/python3.7/tempfile.py_statPsrcCs*y t|Wntk r dSXdSdS)NFT)rOSError)rrrr_existsTs  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_type]s  r%cCsdt|||}|dkr|}|dkr:|tkr0t}n tt}|dkrX|tkrRt}nt}||||fS)N)r%r!templaterfsencoder r )prefixsuffixdir output_typerrr_sanitize_paramsrs  r,c@s,eZdZdZeddZddZddZdS) _RandomNameSequenceZ%abcdefghijklmnopqrstuvwxyz0123456789_cCs,t}|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}d|S)Ncsg|] }qSrr).0Zdummy)cchooserr sz0_RandomNameSequence.__next__..) charactersr3choicerangejoin)r2Zlettersr)r6r7r__next__sz_RandomNameSequence.__next__N)__name__ __module__ __qualname__r;propertyr3r4r?rrrrr-s r-c Csg}x$dD]}t|}|r ||q Wtjdkr\|tjdtjdddddgn|d d d gy|tWn$t t fk r|tj YnX|S) N)ZTMPDIRZTEMPZTMPntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmpz/tmpz/var/tmpz/usr/tmp) rgetenvappendnameextendpath expanduser expandvarsgetcwdAttributeErrorrcurdir)dirlistZenvnamedirnamerrr_candidate_tempdir_lists    rQc Cs4t}t}x|D]}|tjkr0tj|}xtdD]}t|}tj||}y\t |t d}zr_bin_openflags_iowriterunlinkFileExistsErrorPermissionErrorrGisdiraccessW_OKrFileNotFoundError_errnoENOENT)ZnamerrOr*seqrGfilenamerfprrr_get_default_tempdirs:    rfcCs2tdkr.tztdkr taWdtXtS)N)_name_sequence _once_lockacquirer-releaserrrr_get_candidate_namess  rkc Cst}|tkrttj|}xttD]}t|}tj ||||}yt ||d} WnRt k rnw$Yn>t k rtj dkrtj|rt|tjrw$nYnX| tj|fSWt tjddS)NirDz#No usable temporary file name found)rkr maprr'r=rrVrIr>rr[r\rGr]r^r_rUraEEXIST) r*ZpreZsufflagsr+namesrcrGfilerrrr_mkstemp_inners$ rqcCstS)N)r&rrrrr scCs ttS)N)rr'r rrrrr scCs2tdkr.tztdkr taWdtXtS)N)r rhrirfrjrrrrr s  cCs ttS)N)rr'r rrrrr +sFcCs2t|||\}}}}|rt}nt}t|||||S)N)r,_text_openflagsrWrq)r)r(r*textr+rnrrrr/s c Cst|||\}}}}t}|tkr.ttj|}xttD]}t|}tj ||||}yt |dWnRt k rw8Yn>t k rtjdkrtj |rt|tjrw8nYnX|SWt tjddS)NirDz(No usable temporary directory name found)r,rkr rlrr'r=rrVrIr>mkdirr[r\rGr]r^r_rarm)r)r(r*r+rorcrGrprrrrWs&  r:cCs`|dkrt}t}x:ttD].}t|}tj||||}t|s|SqWt t j ddS)Nz"No usable temporary filename found) r rkr=rrVrrIr>rr[rarm)r)r(r*rorcrGrprrrr~sc@sHeZdZdZdZd ddZejdkreZdZdddZddZddZdd Zd d Zd d ZdS)_TemporaryFileWrapperTcCs$||_||_||_t||||_dS)N)rprGrvru_closer)r2rprGrvrrrrwsz_TemporaryFileWrapper.__init__cs^|jd}t||}t|drD|tfdd}|j|_|}t|tsZt||||S)Nrp__call__cs ||S)Nr)r#kwargs)funcrr func_wrappersz7_TemporaryFileWrapper.__getattr__..func_wrapper) __dict__r0hasattr _functoolswrapsr{rintsetattr)r2rGrparr)r~r __getattr__s     z!_TemporaryFileWrapper.__getattr__cCs|j|S)N)rp __enter__)r2rrrrs z_TemporaryFileWrapper.__enter__cCs|j|||}||S)N)rp__exit__r)r2excvaluetbresultrrrrsz_TemporaryFileWrapper.__exit__cCs|jdS)N)r{r)r2rrrrsz_TemporaryFileWrapper.closeccsx|jD] }|VqWdS)N)rp)r2linerrrr4s z_TemporaryFileWrapper.__iter__N)T) r@rArBrwrrrrr4rrrrrzs  rzw+bTc Cst|||\}}}}t} tjdkr0|r0| tjO} t|||| |\} } y tj| ||||d} t| | |St k rt | t | YnXdS)NrD) bufferingnewlineencoding) r,rWrrGZ O_TEMPORARYrqrXrrz BaseExceptionrZr) moderrrr)r(r*rvr+rnrrGrprrrrs      posixcygwin O_TMPFILEc Cst|||\}}}}t}try$|tjBtj@} t|| d} Wn*tk rXdaYnBtk rjYn0Xyt j| ||||dSt | YnXt |||||\} } yt | t j| ||||dSt | YnXdS)NiF)rrr) r,rW_O_TMPFILE_WORKSrrO_CREATrIsADirectoryErrorrrXrrqrZ) rrrrr)r(r*r+rnZflags2rrGrrrr9s0       c@seZdZdZd6ddZdd 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/Zd7d0d1Zd2d3Zd4d5ZdS)8rFrw+brNc CsPd|krt|_ntjt||d|_||_d|_|||||||d|_dS)Nb)rrF)rrr)r(rrr*)rXBytesIO_file TextIOWrapper _max_size_rolled_TemporaryFileArgs) r2max_sizerrrrr)r(r*rrrrwzs   zSpooledTemporaryFile.__init__cCs,|jr dS|j}|r(||kr(|dS)N)rrtellrollover)r2rprrrr_checks zSpooledTemporaryFile._checkcCsr|jr dS|j}tf|j}|_|`|}t|drN|j| n|| | |dd|_dS)NbufferrT) rrrrrrrrYdetachgetvalueseek)r2rpZnewfileposrrrrs  zSpooledTemporaryFile.rollovercCs|jjrtd|S)Nz%Cannot enter context with closed file)rclosed ValueError)r2rrrrszSpooledTemporaryFile.__enter__cCs|jdS)N)rr)r2rrrrrrrszSpooledTemporaryFile.__exit__cCs |jS)N)rr4)r2rrrr4szSpooledTemporaryFile.__iter__cCs|jdS)N)rr)r2rrrrszSpooledTemporaryFile.closecCs|jjS)N)rr)r2rrrrszSpooledTemporaryFile.closedcCs8y|jjStk r2d|jdkr(|jdSXdS)Nrrr)rrrMr)r2rrrrs zSpooledTemporaryFile.encodingcCs||jS)N)rrfileno)r2rrrrszSpooledTemporaryFile.filenocCs|jdS)N)rflush)r2rrrrszSpooledTemporaryFile.flushcCs |jS)N)risatty)r2rrrrszSpooledTemporaryFile.isattycCs(y|jjStk r"|jdSXdS)Nr)rrrMr)r2rrrrszSpooledTemporaryFile.modecCs"y|jjStk rdSXdS)N)rrGrM)r2rrrrGszSpooledTemporaryFile.namecCs8y|jjStk r2d|jdkr(|jdSXdS)Nrrr)rnewlinesrMr)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|S)N)rr)r2r#rrrrszSpooledTemporaryFile.seekcCs|jjS)N)r softspace)r2rrrrszSpooledTemporaryFile.softspacecCs |jS)N)rr)r2rrrrszSpooledTemporaryFile.tellcCs6|dkr|jn||jkr&||j|dS)N)rtruncaterr)r2sizerrrrs   zSpooledTemporaryFile.truncatecCs|j}||}|||S)N)rrYr)r2srprvrrrrYs  zSpooledTemporaryFile.writecCs|j}||}|||S)N)r writelinesr)r2iterablerprrrrrs  zSpooledTemporaryFile.writelines)rrrNNNNN)N)r@rArBrrwrrrrr4rrCrrrrrrrGrrrrrrrrrYrrrrrrss6        c@sBeZdZdddZeddZddZdd Zd d Zd d Z dS)rNcCs0t||||_tj||j|jd|d|_dS)NzImplicitly cleaning up {!r}) warn_message)rrG_weakrefZfinalize_cleanupformat _finalizer)r2r)r(r*rrrrws zTemporaryDirectory.__init__cCst|t|tdS)N)_shutilrmtree _warningswarnResourceWarning)clsrGrrrrrs zTemporaryDirectory._cleanupcCsd|jj|jS)Nz <{} {!r}>)r __class__r@rG)r2rrr__repr__ szTemporaryDirectory.__repr__cCs|jS)N)rG)r2rrrr#szTemporaryDirectory.__enter__cCs |dS)N)cleanup)r2rrrrrrr&szTemporaryDirectory.__exit__cCs|jrt|jdS)N)rrrrrG)r2rrrr)s zTemporaryDirectory.cleanup)NNN) r@rArBrw classmethodrrrrrrrrrr s   )NNNF)NNN)rrNNNNNT)rrNNNNN)?__all__ functoolsrwarningsriorXosrZshutilrerrnoraZrandomrr1weakrefr_thread allocate_lockZ_allocate_lockO_RDWRrO_EXCLrrrrrWrrr&rhrrrrr%r,r-rQrfrgrkrqr r r r r rrrrurzrrGsysplatformrrrobjectrrrrrs~         -  ( ' +? $  8