3 Pf @sdddlZddlZddlmZddlmZddlmZddlm Z ddZ Gd d d eZ d d Z dS) N)LockFile) MkdirLockFile) BaseCache)CacheControllercCstj}|tjtjBO}ttdr*|tjO}ttdr>|tjO}ytj|Wntt fk rdYnXtj |||}y tj |dStj |YnXdS)N O_NOFOLLOWO_BINARYwb) osO_WRONLYO_CREATO_EXCLhasattrrrremoveIOErrorOSErroropenfdopenclose)filenameZfmodeflagsfdr /usr/lib/python3.6/file_cache.py_secure_open_write s       rc@sBeZdZdddZeddZd d Zd d Zd dZddZ dS) FileCacheFNcCsN|dk r|dk rtd|r t}|dkr,t}||_||_||_||_||_dS)Nz/Cannot use use_dir_lock and lock_class together) ValueErrorrr directoryforeverfilemodedirmode lock_class)selfrr r!r"Z use_dir_lockr#rrr__init__4szFileCache.__init__cCstj|jjS)N)hashlibZsha224encodeZ hexdigest)xrrrr'GszFileCache.encodecCs4|j|}t|dd|g}tjj|jf|S)N)r'listr pathjoinr)r$nameZhashedpartsrrr_fnKs z FileCache._fnc Cs8|j|}tjj|sdSt|d }|jSQRXdS)Nrb)r/r r+existsrread)r$keyr-fhrrrgetRs    z FileCache.getcCs||j|}ytjtjj||jWnttfk r<YnX|j|*}t |j|j }|j |WdQRXWdQRXdS)N) r/r makedirsr+dirnamer"rrr#rr!write)r$r3valuer-lockr4rrrsetZs  z FileCache.setcCs|j|}|jstj|dS)N)r/r r r)r$r3r-rrrdeletehs zFileCache.delete)FrrNN) __name__ __module__ __qualname__r% staticmethodr'r/r5r;r<rrrrr3s  rcCstj|}|j|S)z\Return the file cache path based on the URL. This does not ensure the file exists! )rZ cache_urlr/)ZurlZ filecacher3rrrurl_to_file_pathns rA) r&r Zpip._vendor.lockfilerZ"pip._vendor.lockfile.mkdirlockfilercacherZ controllerrrrrArrrrs    (;