o ?Ogs@s gdZddlZddlZddlZddlZddl Z ddl Z ddl mZddlZddlZddlZddlZejZejejBejBZeedrIeejOZeZeedrUeej OZeedr^ej!Z!ndZ!dZ"eZ#d d Z$d d Z%d dZ&GdddZ'ddZ(ddZ)da*ddZ+ddZ,ddZ-ddZ.ddZ/dd Z0da1d!d"Z2d#d$Z3d%d&Z4dBd(d)Z5dCd*d+Z6d,e"dfd-d.Z7Gd/d0d0Z8Gd1d2d2Z9   5dDdd6d7d8Z:ej;d9ksej   dEdd6dd?d?Z?Gd@dAdAZ@dS)F) NamedTemporaryFile TemporaryFileSpooledTemporaryFileTemporaryDirectorymkstempmkdtempmktempTMP_MAX gettempprefixtempdir gettempdirgettempprefixb gettempdirbN)Random O_NOFOLLOWO_BINARYri'tmpcCs&zt|WdStyYdSw)NFT)_oslstatOSError)fnr//opt/alt/python310/lib64/python3.10/tempfile.py_existsLs   rcGs d}|D],}|dur qt|tjrt|}t|tr'|tur$tdt}q|tur/tdt}q|durCtdus?tttrAtStS|S)Nz1Can't mix bytes and non-bytes in path components.) isinstancerPathLikefspathbytesstr TypeErrorr )argsZ return_typeargrrr_infer_return_typeUs&   r"cCsf t|||}|dur|}|dur|turt}ntt}|dur-|tur*t}nt}||||fSN)r"rtemplaterfsencoder r )prefixsuffixdir output_typerrr_sanitize_paramsrs   r*c@s.eZdZ dZeddZddZddZdS) _RandomNameSequenceZ%abcdefghijklmnopqrstuvwxyz0123456789_cCs,t}|t|ddkrt|_||_|jS)N_rng_pid)rgetpidgetattr_RandomZ_rngr,)selfZcur_pidrrrrngs z_RandomNameSequence.rngcCs|Sr#rr0rrr__iter__sz_RandomNameSequence.__iter__cCsd|jj|jddS)N)k)joinr1choices charactersr2rrr__next__sz_RandomNameSequence.__next__N)__name__ __module__ __qualname__r9propertyr1r3r:rrrrr+s  r+c Cs g}dD]}t|}|r||qtjdkr-|tjdtjdddddgn|gd z |tW|St t fyP|tj Y|Sw) N)ZTMPDIRZTEMPZTMPntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmp)z/tmpz/var/tmpz/usr/tmp) rgetenvappendnameextendpath expanduser expandvarsgetcwdAttributeErrorrcurdir)dirlistZenvnamedirnamerrr_candidate_tempdir_lists&   rLc Cs  t}t}|D]~}|tjkrtj|}tdD]l}t|}tj||}z0t |t d}zz t |dWt |nt |wWt |nt |w|WSty`Yqty}tjdkrztj|rzt|tjrzYqYn tyYnwq ttjd|)Ndsblatr?z)No usable temporary directory found in %s)r+rLrrIrDabspathrangenextr7open_bin_openflagswritecloseunlinkFileExistsErrorPermissionErrorrBisdiraccessW_OKrFileNotFoundError_errnoZENOENT)ZnamerrJr(seqrBfilenamefdrrr_get_default_tempdirsD       racCL tdur$tztdurtaWttSWttStwtSr#)_name_sequence _once_lockacquirer+releaserrrr_get_candidate_namess rgc Cs tj|}t}|turttj|}ttD]J}t |}tj ||||}t d|z t ||d} Wn$tyAYqty\tjdkr[tj|r[t|tjr[Yqw| |fSttjd)Nztempfile.mkstemprNr?z#No usable temporary file name found)rrDrOrgrmapr%rPrrQr7_sysauditrRrWrXrBrYrZr[r]EEXIST) r(ZpreZsufflagsr)namesr^rBfiler`rrr_mkstemp_inners0        rocGsR|tjvr||g|RddidStjdkstj|s'||g|RdSdS)Nfollow_symlinksFr?)rsupports_follow_symlinksrBrDislink)funcrDr rrr_dont_follow_symlinkss rtcCs<ztj}Wn tyYnwt||dttj|ddS)Nr)rchflagsrHrtchmod)rDrvrrr _resetpermss   rxcC ttSr#)rfsdecoder$rrrrr # r cCryr#)rr%r$rrrrr 'r{r cCrbr#)r rdrerarfrrrr _gettempdir-s r|cC ttSr#)rrzr|rrrrr 9 r cCr}r#)rr%r|rrrrr =r~r FcCs4 t|||\}}}}|rt}nt}t|||||Sr#)r*_text_openflagsrSro)r'r&r(textr)rlrrrrAs rc Cs t|||\}}}}t}|turttj|}ttD]F}t|}tj ||||}t d|z t |dW|StyGYqtybtjdkratj |rat|tjraYqwttjd)Nztempfile.mkdtemprur?z(No usable temporary directory name found)r*rgrrhrr%rPrrQrDr7rirjmkdirrWrXrBrYrZr[r]rk)r'r&r(r)rmr^rBrnrrrrhs0        rr4cCs^ |durt}t}ttD]}t|}tj||||}t|s(|Sqt t j d)Nz"No usable temporary filename found) r rgrPrrQrrDr7rrWr]rk)r'r&r(rmr^rBrnrrrrs rc@sLeZdZ dZdZd ddZejdkr ejfddZ d d Z dSd dZ dS) _TemporaryFileCloserNFTcCs||_||_||_dSr#)rnrBdeleter0rnrBrrrr__init__s z_TemporaryFileCloser.__init__r?cCsX|js(|jdur*d|_z|jW|jr||jdSdS|jr'||jwwdSdSNT) close_calledrnrUrrB)r0rVrrrrUs  z_TemporaryFileCloser.closecC |dSr#)rUr2rrr__del__ z_TemporaryFileCloser.__del__cCs|js d|_|jdSdSr)rrnrUr2rrrrUsT) r;r<r=rnrrrrBrVrUrrrrrrs   rc@s@eZdZ dddZddZddZdd Zd d Zd d ZdS)_TemporaryFileWrapperTcCs$||_||_||_t||||_dSr#)rnrBrr_closerrrrrrsz_TemporaryFileWrapper.__init__cs^|jd}t||}t|dr"|tfdd}|j|_|}t|ts-t||||S)Nrn__call__cs|i|Sr#r)r kwargsrsrr func_wrappersz7_TemporaryFileWrapper.__getattr__..func_wrapper) __dict__r.hasattr _functoolswrapsrrintsetattr)r0rBrnarrrr __getattr__s     z!_TemporaryFileWrapper.__getattr__cCs|j|Sr#)rn __enter__r2rrrrs z_TemporaryFileWrapper.__enter__cCs|j|||}||Sr#)rn__exit__rU)r0excvaluetbresultrrrrsz_TemporaryFileWrapper.__exit__cCs |jdSr#)rrUr2rrrrU sz_TemporaryFileWrapper.closeccs|jD]}|VqdSr#)rn)r0linerrrr3s z_TemporaryFileWrapper.__iter__Nr) r;r<r=rrrrrUr3rrrrrs  rw+bTerrorsc s t\ttjdkr|rtjOd|vr"t|}dfdd} z,tj|||||| d} zt| d| } t| d| } | _t | |WWS| durotjdkrj|sot )Nr?bcst\}|Sr#)ro)r r`r(rlrBr)r&r'rropener:sz"NamedTemporaryFile..opener bufferingnewlineencodingrrbufferraw) r*rSrrBZ O_TEMPORARY_io text_encodingrRr.rrUrV) moderrrr'r&r(rrrrnrrrrrs4      rposixcygwin O_TMPFILEc s d|vr t|}t\ttrTdfdd}ztj||||||d} t| d| } t| d| } | _| WStyKdaYn t ySYnwdfdd}tj||||||d} t| d| } t| d| } | _| S) Nrcs$tjBtj@}t|dS)NrN)rrO_CREATrR)r Zflags2)r(r`rlrrrtszTemporaryFile..openerrrrFc sJt\}zt|WSty$}ztd}~wwr#)rorrV BaseExceptionrU)r rBer(r`rlr)r&r'rrrs  ) rrr*rS_O_TMPFILE_WORKSrRr.rBIsADirectoryErrorr) rrrrr'r&r(rrrnrrrrrZs@          rc@seZdZ dZ   d7ddddZeejZd d Z d d Z d dZ ddZ ddZ ddZeddZeddZeddZddZddZdd Zed!d"Zed#d$Zed%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd8d1d2Zd3d4Zd5d6Z dS)9rFrrrNrc  Cs^d|vr t|_nt|}tjt|| |d|_||_d|_|||||||| d|_dS)Nr)rrrF)rrr'r&rrr(r)rBytesIO_filer TextIOWrapper _max_size_rolled_TemporaryFileArgs) r0max_sizerrrrr'r&r(rrrrrs    zSpooledTemporaryFile.__init__cCs4|jrdS|j}|r||kr|dSdSdSr#)rrtellrollover)r0rnrrrr_checks  zSpooledTemporaryFile._checkcCsv|jrdS|j}tdi|j}|_|`|}t|dr)|j| n|| | |dd|_dS)NrrTr) rrrrrrrrTdetachgetvalueseek)r0rnZnewfileposrrrrs    zSpooledTemporaryFile.rollovercCs|jjrtd|S)Nz%Cannot enter context with closed file)rclosed ValueErrorr2rrrrszSpooledTemporaryFile.__enter__cC|jdSr#rrUr0rrrrrrrzSpooledTemporaryFile.__exit__cC |jSr#)rr3r2rrrr3 zSpooledTemporaryFile.__iter__cCrr#rr2rrrrUrzSpooledTemporaryFile.closecC|jjSr#)rrr2rrrrzSpooledTemporaryFile.closedcCrr#)rrr2rrrrrzSpooledTemporaryFile.encodingcCrr#)rrr2rrrrrzSpooledTemporaryFile.errorscCs||jSr#)rrfilenor2rrrrs zSpooledTemporaryFile.filenocCrr#)rflushr2rrrrrzSpooledTemporaryFile.flushcCrr#)risattyr2rrrrrzSpooledTemporaryFile.isattycCs(z|jjWSty|jdYSw)Nr)rrrHrr2rrrrs   zSpooledTemporaryFile.modecCs z|jjWStyYdSwr#)rrBrHr2rrrrBs   zSpooledTemporaryFile.namecCrr#)rnewlinesr2rrrr rzSpooledTemporaryFile.newlinescG |jj|Sr#)rreadr0r rrrrrzSpooledTemporaryFile.readcGrr#)rreadlinerrrrrrzSpooledTemporaryFile.readlinecGrr#)r readlinesrrrrrrzSpooledTemporaryFile.readlinescGrr#)rrrrrrrrzSpooledTemporaryFile.seekcCrr#)rrr2rrrrrzSpooledTemporaryFile.tellcCs8|dur |jdS||jkr||j|dSr#)rtruncaterr)r0sizerrrr s  zSpooledTemporaryFile.truncatecC|j}||}|||Sr#)rrTr)r0srnrvrrrrT(  zSpooledTemporaryFile.writecCrr#)r writelinesr)r0iterablernrrrrr.rzSpooledTemporaryFile.writelines)rrrNNNNNr#)!r;r<r=rr classmethod_types GenericAlias__class_getitem__rrrrr3rUr>rrrrrrrrBrrrrrrrrTrrrrrrsN         rc@sbeZdZ  dddZedddZedddZd d Zd d Zd dZ ddZ ee j Z dS)rNFcCs:t||||_||_tj||j|jd||jd|_dS)NzImplicitly cleaning up {!r}) warn_message ignore_errors)rrB_ignore_cleanup_errors_weakrefZfinalize_cleanupformat _finalizer)r0r'r&r(Zignore_cleanup_errorsrrrrAs  zTemporaryDirectory.__init__cs"fdd}tj|ddS)Nc st|dtrAz/|krttj|t|z t|WWdSttfy3j|dYnwWdSt y@YdSwt|dt rJdSsMdS)Nrr) issubclassrXrxrrDrKrVr_rmtreer\)rsrDexc_infoclsrrBrronerrorLs& z+TemporaryDirectory._rmtree..onerror)r)_shutilZrmtree)rrBrrrrrrJszTemporaryDirectory._rmtreecCs|j||dt|tdSNr)r _warningswarnResourceWarning)rrBrrrrrrbszTemporaryDirectory._cleanupcCsd|jj|jS)Nz <{} {!r}>)r __class__r;rBr2rrr__repr__gszTemporaryDirectory.__repr__cCs|jSr#)rBr2rrrrjszTemporaryDirectory.__enter__cCrr#)cleanuprrrrrmrzTemporaryDirectory.__exit__cCs2|js tj|jr|j|j|jddSdSr)rrrrDexistsrBrrr2rrrrpszTemporaryDirectory.cleanupNNNF)F)r;r<r=rrrrrrrrrrrrrrrr5s    rr)NNN)rrNNNNNT)rrNNNNN)A__all__ functoolsrwarningsriorosrZshutilrerrnor]Zrandomrr/sysritypesrweakrefr_thread allocate_lockZ_allocate_lockO_RDWRrO_EXCLrrrrSrrr$rdrr"r*r+rLrarcrgrortrxr r r r|r r rrrrrrrBplatformrrrrrrrrs        ,    '( +? 5  K