a lj9@s|ddlZddlZddlmZddlmZddlmZzeWne yVe e fZYn0ddZ Gdd d eZ d d ZdS) N)dedent) BaseCache)CacheControllerc Cstj}|tjtjBO}ttdr*|tjO}ttdr>|tjO}zt|Wntt fybYn0t |||}zt |dWSt |Yn0dS)N O_NOFOLLOWO_BINARYwb) osO_WRONLYO_CREATO_EXCLhasattrrrremoveIOErrorOSErroropenfdopenclose)filenameZfmodeflagsfdrN/usr/lib/python3.9/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py_secure_open_writes      rc@sBeZdZdddZeddZd d Zd d Zd dZddZ dS) FileCacheFNc Cs|dur|durtdzddlm}ddlm}Wn"tyVtd} t| Yn0|rb|}n |durn|}||_||_||_ ||_ ||_ dS)Nz/Cannot use use_dir_lock and lock_class togetherr)LockFile) MkdirLockFilez NOTE: In order to use the FileCache you must have lockfile installed. You can install it via pip: pip install lockfile ) ValueErrorZlockfilerZlockfile.mkdirlockfiler ImportErrorr directoryforeverfilemodedirmode lock_class) selfr!r"r#r$Z use_dir_lockr%rrZnoticerrr__init__:s&   zFileCache.__init__cCst|SN)hashlibZsha224encodeZ hexdigest)xrrrr*aszFileCache.encodecCs6||}t|dd|g}tjj|jg|RS)N)r*listr pathjoinr!)r&nameZhashedpartsrrr_fnes z FileCache._fncCs\||}z8t|d}|WdWS1s60YWntyVYdS0dS)Nrb)r2rreadFileNotFoundError)r&keyr0fhrrrgetls   , z FileCache.getc Cs||}zttj||jWnttfy:Yn0||H}t |j|j }| |Wdn1sv0YWdn1s0YdSr() r2r makedirsr.dirnamer$rrr%rr#write)r&r6valuer0lockr7rrrsetus  z FileCache.setcCs6||}|js2zt|Wnty0Yn0dSr()r2r"r rr5)r&r6r0rrrdeletes   zFileCache.delete)FrrNN) __name__ __module__ __qualname__r' staticmethodr*r2r8r>r?rrrrr8s '  rcCst|}||S)z\Return the file cache path based on the URL. This does not ensure the file exists! )rZ cache_urlr2)urlZ filecacher6rrrurl_to_file_paths rE)r)r textwraprcacherZ controllerrr5 NameErrorrrrrrErrrrs    )T