/usr/local/lib/python3.6/site-packages/fsspec/implementations/__pycache__
NameSizeModeActions
arrow.cpython-36.pyc73280644editdlrm
cached.cpython-36.pyc230300644editdlrm
dask.cpython-36.pyc46560644editdlrm
dbfs.cpython-36.pyc133510644editdlrm
dvc.cpython-36.pyc26220644editdlrm
ftp.cpython-36.pyc104440644editdlrm
git.cpython-36.pyc37500644editdlrm
github.cpython-36.pyc74040644editdlrm
hdfs.cpython-36.pyc70930644editdlrm
http.cpython-36.pyc207520644editdlrm
jupyter.cpython-36.pyc41310644editdlrm
libarchive.cpython-36.pyc60050644editdlrm
local.cpython-36.pyc119120644editdlrm
memory.cpython-36.pyc66970644editdlrm
reference.cpython-36.pyc161420644editdlrm
sftp.cpython-36.pyc61040644editdlrm
smb.cpython-36.pyc105910644editdlrm
tar.cpython-36.pyc45020644editdlrm
webhdfs.cpython-36.pyc147120644editdlrm
zip.cpython-36.pyc32760644editdlrm
__init__.cpython-36.pyc1560644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/fsspec/implementations/__pycache__/cached.cpython-36.pyc (23030B)
3 8%Eg7l@sddlZddlZddlZddlZddlZddlZddlZddlmZm Z ddl m Z m Z ddl mZddlmZddlmZmZddlmZddlmZdd lmZejd ZGd d d e ZGd ddeZGdddeZGdddZddZ dS)N)movermtree)AbstractFileSystem filesystem)_DEFAULT_CALLBACK)compr) BaseCache MMapCache)BlocksizeMismatchError)AbstractBufferedFile)infer_compressionfsspecc seZdZdZd)Zd*fd d Zd d Zd dZddZddZ ddZ ddZ ddZ d+ddZ ddZdd Zfd!d"Zd#d$Zd%d&Zd'd(ZZS),CachingFileSystema4Locally caching filesystem, layer over any other FS This class implements chunk-wise local storage of remote files, for quick access after the initial download. The files are stored in a given directory with random hashes for the filenames. If no directory is given, a temporary one is used, which should be cleaned up by the OS after the process ends. The files themselves as sparse (as implemented in MMapCache), so only the data which is accessed takes up space. Restrictions: - the block-size must be the same for each access of a given file, unless all blocks of the file have already been read - caching can only be applied to file-systems which produce files derived from fsspec.spec.AbstractBufferedFile ; LocalFileSystem is also allowed, for testing blockcachecachedNTMP F: c  stjf| |dk|dkAs&td|dkr:tjg} nt|trL|g} n|} tj| d dd| _ |pni_ |_ |_ |_ | _|_t|tr|nt|jtr|jn|jd_j|dk r|n t|fj _fdd } | _dS) a Parameters ---------- target_protocol: str (optional) Target filesystem protocol. Provide either this or ``fs``. cache_storage: str or list(str) Location to store files. If "TMP", this is a temporary directory, and will be cleaned up by the OS when this process ends (or later). If a list, each location will be tried in the order given, but only the last will be considered writable. cache_check: int Number of seconds between reload of cache metadata check_files: bool Whether to explicitly see if the UID of the remote file matches the stored one before using. Warning: some file systems such as HTTP cannot reliably give a unique hash of the contents of some path, so be sure to set this option to False. expiry_time: int The time in seconds after which a local copy is considered useless. Set to falsy to prevent expiry. The default is equivalent to one week. target_options: dict or None Passed to the instantiation of the FS, if fs is None. fs: filesystem instance The target filesystem to run against. Provide this or ``protocol``. same_names: bool (optional) By default, target URLs are hashed, so that files from different backends with the same basename do not conflict. If this is true, the original basename is used. compression: str (optional) To decompress on download. Can be 'infer' (guess from the URL name), one of the entries in ``fsspec.compression.compr``, or None for no decompression. NzKPlease provide one of filesystem instance (fs) or remote_protocol, not bothrT)exist_okrcsjjtj|S)N)fs_strip_protocoltype)path)selfG/usr/local/lib/python3.6/site-packages/fsspec/implementations/cached.pyrysz3CachingFileSystem.__init__.._strip_protocol)super__init__ ValueErrortempfilemkdtemp isinstancestrosmakedirsstoragekwargs cache_check check_filesexpiry compression same_namesprotocoltarget_protocol load_cacherrr) rr/Z cache_storager)r* expiry_timeZtarget_optionsrr-r,r(r'r) __class__)rrr*s.0    zCachingFileSystem.__init__cCstj|jddddS)NrT)rr)r%r&r')rrrr_mkcacheszCachingFileSystem._mkcachec Csg}x|jD]}tjj|d}tjj|rt|dJ}tj|}x.|jD]"}t |dt rJt |d|d<qJW|j |WdQRXq |j iq W|j |pig|_tj|_dS)z#Read set of stored blocks from filecacherbblocksN)r'r%rjoinexistsopenpickleloadvaluesr#listsetappendr3 cached_filestime last_cache)rr@r'fnfZloaded_cached_filescrrrr0s     zCachingFileSystem.load_cachec Cstjj|jd d}|jd }tjj|rt|d}tj|}WdQRXx|j D]\}}||krV|ddks||ddkrd|d<n"||d}|j |d||d<t |d||d|d<||d|d<qVWx*|j D]\}}||kr|||<qWn|}d d |j D}x2|j D]&}t |dtr$t|d|d<q$Wtj\}} t|d }tj||WdQRX|jt| |||jd<tj|_dS)z#Save set of stored blocks from filerr4r5Nr6TrAuidcSsi|]\}}|j|qSr)copy).0kvrrr sz0CachingFileSystem.save_cache..wbrrr)r%rr7r'r@r8r9r:r;itemsupdatemaxr<r#r>r=r!mkstempdumpr3rrArB) rrCr4rDr@rIrEr6fd2Zfn2rrr save_caches:        zCachingFileSystem.save_cachecCsP|j|jsdStj|j|jk}tdd|jD}|sD| rL|jdS)z0Reload caches if time elapsed or any disappearedNcss|]}tjj|VqdS)N)r%rr8)rHr'rrr sz1CachingFileSystem._check_cache..)r3r)rArBallr'r0)rZtimecondZ existcondrrr _check_caches zCachingFileSystem._check_cachecCs|j|}|jxt|j|jD]~\}}||kr4q"||j}|jr\|d|jj|kr\q"|j rzt j |d|j krzq"t j j ||d}t j j|r"||fSq"WdS)z Is path in cache and still validrFrArCF)rrVzipr'r@rGr*rukeyr+rAr%rr7r8)rrr'r4detailrCrrr _check_files     zCachingFileSystem._check_filecCst|jd|jdS)zRemove all files and metadat from the cache In the case of multiple cache locations, this clears only the last one, which is assumed to be the read/write one. rNr)rr'r0)rrrr clear_cacheszCachingFileSystem.clear_cachecCsd|j|}|j|}|sdS|\}}|j|jdrXtj||jdj||jnt ddS)zRemove cached version of given file Deletes local copy of the given (remote) path. If it is found in a cache location which is not the last, it is assumed to be read-only, and raises PermissionError NrzTsz)CachingFileSystem._open..rr)rr_openrZloggerdebugr9 hash_namer-r%rr7r'r>rArXr@r3r,r rrjr r Z _fetch_rangesizer4rlrS) rrrdrerfrgr(rYrChashr6compr)rlrDrrrnsh      zCachingFileSystem._opencCs t||dS)N) same_name)rq)rrrurrrrqXszCachingFileSystem.hash_namec Cs|jr dS|j|j}|jd |}|ddk rPt|d|j|jkrPd|d<y tjd|j tjdWn>t t fk rtjdYnt k rtjdYnX|d|_dS) z9Called when a file is closing, so store the set of blocksNrr6Tz going to saveZsavedz&Cache saving failed while closing filez-Cache save failed due to interpreter shutdownr) closedrrr@lenrjrrrorprSIOErrorOSError NameError)rrDrlrrErrrrk[s  $ z"CachingFileSystem.close_and_updatecsd&krfddSd'kr"td(kr8ttSd"krHtStjd#}|jd$d}|krp|S|dk r|jkr|jSt|}t|}tj|stj |rt |d% s|j dkr|j ||S|St jSdS))Nr0rnrSrkr__getattribute__ __reduce___make_local_detailsr9catcat_fileget read_blocktailheadrZrVr3r[rb local_file_paths_from_path get_mapper open_many commit_manyrq__hash____eq__to_jsoncsttj||S)N)getattrr__get__)argskw)itemrrrrmsz4CachingFileSystem.__getattribute__.. __reduce_ex___cacher2__dict__r__self__)r0rnrSrkrr{r|r}r9r~rrrrrrZrVr3r[rbr3rrrrrrqrrr)r)r)AttributeErrorrrobjectr{rrinspect isfunctionisdatadescriptorhasattrrrr)rrdrclsm)r2)rrrr{osh       z"CachingFileSystem.__getattribute__cCs~||kr dSt|t|sdS|j|jko||j|jko||j|jko||j|jko||j|jko||j|jko||j|jko||j |j kS)zTest for equality.TF) r#rr'r(r)r*r+r,r-r/)rotherrrrrs       zCachingFileSystem.__eq__cCsXtt|jtt|jAt|jAt|jAt|jAt|jAt|j At|j AS)zCalculate hash.) rstupler'r$r(r)r*r+r,r-r/)rrrrrs zCachingFileSystem.__hash__cCs tddS)z[Calculate JSON representation. Not implemented yet for CachingFileSystem. z5CachingFileSystem JSON representation not implementedN)NotImplementedError)rrrrrszCachingFileSystem.to_json)rr) NrrFrNNFN)r5NTN)__name__ __module__ __qualname____doc__r.rr3r0rSrVrZr[rbrnrqrkr{rrr __classcell__rr)r2rrs8K*   U B rc@sJeZdZdZdZdZddZddZdd Zd d e fd d Z dddZ dS)WholeFileCacheFileSystema Caches whole remote files on first access This class is intended as a layer over any other file system, and will make a local copy of each file accessed, so that all subsequent reads are local. This is similar to ``CachingFileSystem``, but without the block-wise functionality and so can work even when sparse files are not allowed. See its docstring for definition of the init arguments. The class still needs access to the remote store for listing files, and may refresh cached files. filecacheTcsddD}djkr"jnfdd|DSjr@tfdd|D}ddt||D}fddt||D}ddt||D}|rވjj||fd d|D}jdjd d t||Dj d dfddt||DS)NcSsg|] }|jqSr)r)rHZofrrr sz6WholeFileCacheFileSystem.open_many..rccs g|]}tj|jddqS)F)rdrf) LocalTempFilerrd)rHr) open_filesrrrrscsg|]}j|qSr)rZ)rHsp)rrrrscSsg|]\}}|s|qSrr)rHprrrrrscs.g|]&\}}tjjjdj|jqS)rr)r%rr7r'rqr-)rHrr)rrrrscSsg|]\}}|s|qSrr)rHrCrrrrrscs2g|]*}|j|jdtjjj|dqS)T)rhrCr6rArF)rqr-rArrX)rHr)rrrrsrcSsi|]\}}||qSrr)rHrrYrrrrK sz6WholeFileCacheFileSystem.open_many..cSst|tr|dS|S)Nr)r#r)rCrrr firstpartsz5WholeFileCacheFileSystem.open_many..firstpartcs*g|]"\}}t|r|n|jdqS))rd)r9rd)rHZfn0Zfn1)rrrrrsr) rdr3r,rrWrrr@rNrS)rrpathsr`ZdownpathZdownfn0ZdownfnZ newdetailr)rrrrrs,       z"WholeFileCacheFileSystem.open_manycCs&|jjdd|Ddd|DdS)NcSsg|] }|jqSr)rC)rHrDrrrrsz8WholeFileCacheFileSystem.commit_many..cSsg|] }|jqSr)r)rHrDrrrrs)rput)rrrrrrsz$WholeFileCacheFileSystem.commit_manycCs^|j||j}tjj|jd|}||dtj|jj|d}||j d|<t j d||S)NrT)rhrCr6rArFzCopying %s to local cacherr) rqr-r%rr7r'rArrXr@rorp)rrrsrCrYrrrr}sz,WholeFileCacheFileSystem._make_local_detailsFraisecKs|j|||jddd}g}g}g} x^|D]V} |j| } | s\|j| } |j| |j| nt| trj| nd| f\} } | j| q*W|r|jj|||ji} |j t |x2t || D]$\} } t | dj | | <|jdqWt|trt |dkr|dkr| |d} | S)Nmaxdepth) recursiverr5rFr)Z expand_pathrrZr}r?r#rrrSZset_sizerwrWr9readZrelative_updater$)rrrZon_errorcallbackr(rZgetpathsZ storepathsfnsrrYrCoutrrrr~+s0     $ zWholeFileCacheFileSystem.catr5c Ks|j|}d|kr*|jj|fd|i|S|j|}|r|\}}|d|d}}|dkrtjd|t||}|jd|_|St d|n |j |}||d<|j |j r`|jj|f|}t|d } t |trtd |jj|j|_|j d krt|n|j } t| |d d }d} x,| rHt|dd} |j| } | j| qWWdQRXWdQRXn|jj|||j|j||S)NrcrdrCr6TzOpening local copy of %srhz?Attempt to open partially cached file %sas a wholly cached filerLrrir5)rdrjiiP)rrrnrZrorpr9rrhr r}r3r,r#r rr4fetcherrrr rrrwriterS) rrrdr(rYrCrar6rDf2rtdatablockrrrrnOsB         &zWholeFileCacheFileSystem._openN)r5) rrrrr.rrrr}rr~rnrrrrrs 0 rcsJeZdZdZdZdZfddZddZdd Zd d Z dd dZ Z S)SimpleCacheFileSystemaCaches whole remote files on first access This class is intended as a layer over any other file system, and will make a local copy of each file accessed, so that all subsequent reads are local. This implementation only copies whole files, and does not keep any metadata about the download time or file details. It is therefore safer to use in multi-threaded/concurrent situations. This is the only of the caching filesystems that supports write: you will be given a real local open file, and upon close and commit, it will be uploaded to the target filesystem; the writability or the target URL is not checked until that time. Z simplecacheTc sb|j}xdD] }d||<qWtjf|x(|jD]}tjj|s4tj|ddq4Wig|_dS)Nr)r1r*FT)r)r)r1r*) rGrrr'r%rr8r&r@)rr(rkeyr')r2rrrs    zSimpleCacheFileSystem.__init__cCsH|j|j||j}x,|jD]"}tjj||}tjj|r|SqWdS)N)rVrqr-r'r%rr7r8)rrshar'rCrrrrZs   z!SimpleCacheFileSystem._check_filecCsdS)Nr)rrrrrSsz SimpleCacheFileSystem.save_cachecCsdS)Nr)rrrrr0sz SimpleCacheFileSystem.load_cacher5c KsD|j|}d|kr t|||dS|j|}|r8t||S|j||j}tjj|j d|}t j d|||d<|j |j r*|jj|f|}t|d|}t|trtd|jj|j|_|j dkrt|n|j }t||d d}d } x*| rt|d d} |j| } |j| qWWdQRXWdQRXn|jj|||j||S)Nrc)rdrzCopying %s to local cacherdrLrrir5TrjrrrriiP)rrrZr9rqr-r%rr7r'rorpr3r,rrnr#r rr4rrrr rrrrr) rrrdr(rCrrDrrtrrrrrrns2      $zSimpleCacheFileSystem._open)r5) rrrrr.rrrZrSr0rnrrr)r2rrs rc@s^eZdZdZdddZdd Zd d Zd d ZddZddZ ddZ e ddZ ddZ dS)rz8A temporary local file, which will be uploaded on commitNrLTrcCsd|r||_t|||_ntj\}|_t|||_||_|rH|jj|||_||_d|_ ||_ dS)NF) rCr9fhr!rPrdseekrrrvrf)rrrrCrdrfrfdrrrrs  zLocalTempFile.__init__cCs t|j|j|jd|j|jffS)Nzrb+)rrrrCrftell)rrrrr|szLocalTempFile.__reduce__cCs|jS)N)r)rrrr __enter__szLocalTempFile.__enter__cCs |jdS)N)rl)rexc_typeexc_valexc_tbrrr__exit__szLocalTempFile.__exit__cCs"|jjd|_|jr|jdS)NT)rrlrvrfcommit)rrrrrls zLocalTempFile.closecCs|jjtj|jdS)N)rrlr%r]rC)rrrrdiscards zLocalTempFile.discardcCs|jj|j|jdS)N)rrrCr)rrrrrszLocalTempFile.commitcCs t|jjtr|jjS|jSdS)N)r#rnamer$rC)rrrrrszLocalTempFile.namecCs t|j|S)N)rr)rrrrr __getattr__szLocalTempFile.__getattr__)NrLTr)rrrrrr|rrrlrrpropertyrrrrrrrs  rcCs(|rtjj|}ntj|jj}|S)N)r%rbasenamehashlibsha256encode hexdigest)rrursrrrrq srq)!rrloggingr%r:r!rAshutilrrr rrZfsspec.callbacksrZfsspec.compressionrZ fsspec.corerr Zfsspec.exceptionsr Z fsspec.specr Z fsspec.utilsr getLoggerrorrrrrqrrrrs0      G+O7