kghddlmZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZe r ddlmZdd lmZGd d ZGd d ee ZGddeeZddZdS)) annotationsN)dedent)IO TYPE_CHECKING)Path) BaseCacheSeparateBodyBaseCache)CacheController)datetime) BaseFileLockcheZdZdZ d$d%dZed&dZd'dZd(dZ d)d*dZ d+d!Z d,d#Z dS)-_FileCacheMixinz2Shared implementation for both FileCache variants.FN directory str | Pathforeverboolfilemodeintdirmode lock_classtype[BaseFileLock] | NonereturnNonec |ddlm}|}n,#t$rtd}t|wxYw||_||_||_||_||_dS)Nr)FileLockz NOTE: In order to use the FileCache you must have filelock installed. You can install it via pip: pip install cachecontrol[filecache] ) filelockr ImportErrorrrrrrr)selfrrrrrrnotices /builddir/build/BUILD/imunify360-venv-2.6.0/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py__init__z_FileCacheMixin.__init__s &!------%  & & &Ff%% % &#    $s )6xstrcrtj|SN)hashlibsha224encode hexdigest)r$s r"r*z_FileCacheMixin.encode6s&~ahhjj))33555namec||}t|dd|gz}tjj|jg|RS)N)r*listospathjoinr)r r-hashedpartss r"_fnz_FileCacheMixin._fn:sMT""VBQBZ  F8+w|DN3U3333r,key bytes | Nonec||} t|d5}|cdddS#1swxYwYdS#t$rYdSwxYw)Nrb)r6openreadFileNotFoundError)r r7r-fhs r"getz_FileCacheMixin.getAsxx}} dD!! !Rwwyy ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !!   44 s3AA AA  AA A A#"A#valuebytesexpiresint | datetime | Nonec\||}|||dSr'r6_write)r r7r@rBr-s r"setz_FileCacheMixin.setJs-xx}} D%     r,r2datactj|}tj||jd||dz5t j|\}} tj||tj |n#tj |wxYwtj ||j tj ||ddddS#1swxYwYdS)z: Safely write the data to the given path. T)exist_okz.lock)dirN) r1r2dirnamemakedirsrrtempfilemkstempwriteclosechmodrreplace)r r2rHrLfdr-s r"rFz_FileCacheMixin._writePs '//$'' GT\D9999 __TG^ , , # #!)g666JR T"""  HT4= ) ) ) JtT " " " # # # # # # # # # # # # # # # # # #s*C-.BC-B..2C--C14C1suffixc|||z}|js( tj|dS#t$rYdSwxYwdSr')r6rr1remover=)r r7rUr-s r"_deletez_FileCacheMixin._deletebsbxx}}v%|   $$      s7 AA)FrrN) rrrrrrrrrrrr)r$r%rr%)r-r%rr%)r7r%rr8r')r7r%r@rArBrCrr)r2r%rHrArr)r7r%rUr%rr) __name__ __module__ __qualname____doc__r# staticmethodr*r6r?rGrFrXr,r"rrs<< 04 %%%%%:666\64444HL!!!!! ####$r,rceZdZdZddZdS) FileCachezc Traditional FileCache: body is stored in memory, so not suitable for large downloads. r7r%rrc2||ddS)NrXr r7s r"deletezFileCache.deleteqs S"r,Nr7r%rr)rYrZr[r\rer^r,r"r`r`ks2 r,r`c*eZdZdZd dZdd Zdd Zd S)SeparateBodyFileCachezh Memory-efficient FileCache: body is stored in a separate file, reducing peak memory usage. r7r%rIO[bytes] | Nonecv||dz} t|dS#t$rYdSwxYw)N.bodyr:)r6r;r=)r r7r-s r"get_bodyzSeparateBodyFileCache.get_body{sMxx}}w& d## #    44 s * 88bodyrArcb||dz}|||dS)NrkrE)r r7rmr-s r"set_bodyzSeparateBodyFileCache.set_bodys0xx}}w& D$r,c^||d||ddS)Nrbrkrcrds r"rezSeparateBodyFileCache.deletes0 S" S'"""""r,N)r7r%rri)r7r%rmrArrrf)rYrZr[r\rlrorer^r,r"rhrhusZ     ######r,rhurlr% filecachercTtj|}||S)z\Return the file cache path based on the URL. This does not ensure the file exists! )r cache_urlr6)rqrrr7s r"url_to_file_pathrus&  #C ( (C ==  r,)rqr%rrr`rr%) __future__rr(r1rNtextwraprtypingrrpathlibrpip._vendor.cachecontrol.cacherr #pip._vendor.cachecontrol.controllerr r rr rr`rhrur^r,r"r|sn#""""" $$$$$$$$KKKKKKKK??????&!!!!!!%%%%%%RRRRRRRRj#####O-B###,r,