/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__/reference.cpython-36.pyc (16142B)
3 8%EgH @sddlZddlZddlZddlZddlZddlmZddlZy ddl Z Wne k rdddl Z YnXddl m Z mZddlmZddlmZmZddlmZddlmZejd ZGd d d e Zd d ZdS)N) lru_cache)AsyncFileSystemsync)_DEFAULT_CALLBACK) filesystemopen) get_mapper)AbstractFileSystemzfsspec.referencec seZdZdZdZd;fdd ZeddZd d ZdddZd?ddZddZd@ddZddZdAd d!Zd"d#Zd$d%Zd&d'ZdBd)d*ZdCd+d,Zd-d.Zd/d0Zd1d2ZdDd3d4ZdEfd5d6 Zd7d8Zd9d:Z Z!S)FReferenceFileSystemaView byte ranges of some other file as a file system Initial version: single file system target, which must support async, and must allow start and end args in _cat_file. Later versions may allow multiple arbitrary URLs for the targets. This FileSystem is read-only. It is designed to be used with async targets (for now). This FileSystem only allows whole-file access, no ``open``. We do not get original file details from the target FS. Configuration is by passing a dict of references at init, or a URL to a JSON file containing the same; this dict can also contain concrete data for some set of paths. Reference dict format: {path0: bytes_data, path1: (target_url, offset, size)} https://github.com/fsspec/kerchunk/blob/main/README.md referenceNTc  stjfd| i| ||_d|_| |_| |_i|_t|drJ|j}nt |t r|rdd|i}ni}t f|pv|pvi|}| dks|j drddl }ddl}d|_t|f|}|j|jd d kstjd |_jjd d|_|jfd ddDjd|_n| dks$|j drddl}d|_t|df|Z}|j|}|jd d ks`ttj|jd |_tj|jjd d|_|jdd|_WdQRXn.t|df|}tj d||j}WdQRXn|}|jr|j!n |j"|| |dk r||_#dS|dkrTx@|jj$D]2}t%|r2|}t&j'j(|\}}|r|}PqW|dkrxZ|j)j$D]L}t%|r~|}t |t*rj|drjt&j'j(|d\}}|rj|}PqjW|dkr|}t+|fd| i|pi|_#dS)a Parameters ---------- fo : dict or str The set of references to use for this instance, with a structure as above. If str, will use fsspec.open, in conjunction with ref_storage_args to open and parse JSON at this location. target : str For any references having target_url as None, this is the default file target to use ref_storage_args : dict If references is a str, use these kwargs for loading the JSON file target_protocol : str Used for loading the reference file, if it is a path. If None, protocol will be derived from the given path target_options : dict Extra FS options for loading the reference file, if given as a path remote_protocol : str The protocol of the filesystem on which the references will be evaluated (unless fs is provided). If not given, will be derived from the first URL that has a protocol in the templates or in the references, in that order. remote_options : dict kwargs to go with remote_protocol fs : file system instance Directly provide a file system, if you want to configure it beforehand. This takes precedence over target_protocol/target_options template_overrides : dict Swap out any templates in the references file with these - useful for testing. ref_type : "json" | "parquet" | "zarr" If None, guessed from URL suffix, defaulting to JSON. Ignored if fo is not a string. simple_templates: bool Whether templates can be processed with simple replace (True) or if jinja is needed (False, much slower). All reference sets produced by ``kerchunk`` are simple in this sense, but the spec allows for complex. kwargs : passed to parent class loopFreadprotocolzarrrNTversion templatesgencsi|]}|dd|qS)N).0k)zrJ/usr/local/lib/python3.6/site-packages/fsspec/implementations/reference.py sz0ReferenceFileSystem.__init__..keydataurloffsetsizeZparquetrbz[])indexzRead reference from URL %s)rrrrr),super__init__target dataframetemplate_overridessimple_templatesrhasattrr isinstancestrdictendswithZpandasrr Z open_groupattrsAssertionErrorgetrZ DataFrameZ set_indexdfZ fastparquetrZ ParquetFileZkey_value_metadatajsonloadsZ to_pandasloggerinfo_process_dataframe_process_referencesfsvaluescallablefsspeccoreZsplit_protocol referenceslistr)selffor$Zref_storage_argsZtarget_protocolZtarget_optionsZremote_protocolZremote_optionsr7r&r'r Zref_typekwargstextextraZdicpdrmfpfpfrefr_) __class__)rrr#/s8                  zReferenceFileSystem.__init__cCs|jjr|jjS|jS)N)r7 async_implr _loop)r>rrrr szReferenceFileSystem.loopcCs$|j|}tjd||jrN|jj|}|dr>|d}qX|dddg}n |j|}t|trj|j }t|t rtjd|d|j drt j |d d}|ddfSt|d krtjd|d |d }d}d}n.|\}}}tjd|d |d|||}|dkr|j}|||fS)Nzcat: rrrrz Reference: z , type bytessbase64:rz , whole filerz , offset z, size )_strip_protocolr3debugr%r0locr<r)r*encodebytes startswithbase64 b64decodelenr$)r>pathpartrstartendrrrr _cat_commons4           zReferenceFileSystem._cat_commoncsF|j|\}}}t|tr&|||S|jj|||dIdH||S)N)rYrZ)r[r)rRr7 _cat_file)r>rWrYrZr@ part_or_urlstart0end0rrrr\s  zReferenceFileSystem._cat_filecKs@|j|\}}}t|tr&|||S|jj|||d||S)N)rYrZ)r[r)rRr7cat_file)r>rWrYrZr@r]r^r_rrrr`s  zReferenceFileSystem.cat_filecKs||j|<dS)z2Temporarily add binary data or reference as a fileN)r<)r>rWvaluerIrrr pipe_fileszReferenceFileSystem.pipe_filec sL|j|rtj|ddS|j|IdH}t|d}|j|WdQRXdS)NT)exist_okwb)isdirosmakedirsr\rwrite)r>rpathlpathr@rrFrrr _get_files   zReferenceFileSystem._get_filec Ksf|j|rtj|ddS|j|f|}|jdt|t|d}|j|WdQRX|jdt|dS)NT)rcZset_sizerdZabsolute_update)rerfrgr`Z lazy_callrVrrh)r>rirjcallbackr@rrFrrrget_files  zReferenceFileSystem.get_fileFcKs:|jjr t|j|j|||f|Stj|||fd|i|S)N recursive)r7rKrr _getr r/)r>rirjrnr@rrrr/szReferenceFileSystem.getc sfjjrtjj||fSt|trV|s>tdd|DrBtfdd|DSt j |SdS)Ncss|]}d|kVqdS)*Nr)rprrr sz*ReferenceFileSystem.cat..csi|]}tj|f|qSr)r r`)rrq)r@r>rrrsz+ReferenceFileSystem.cat..) r7rKrr Z_catr)r=anyNotImplementedErrorr r`)r>rWrnr@r)r@r>rcats zReferenceFileSystem.catcsHjjtdfdd}jr<jdj|jd<jdS)NicsLddl}d|krHjr4|jddjddjfjS|j|jfjS|S)Nrz{{{z}}})jinja2r'replaceformatrTemplaterender)rrx)r>rr _render_jinjas  z=ReferenceFileSystem._process_dataframe.._render_jinjar)_process_templatesrrr0map_dircache_from_items)r>r}r)r>rr5s  z&ReferenceFileSystem._process_dataframecCsjt|ttfrtj|}|jdd}|dkr8|j|n&|dkrP|j||dntd||j dS)Nrr)r&z Unknown reference spec version: ) r)r*rRr1r2r/_process_references0_process_references1 ValueErrorr)r>r<r&versrrrr6s   z'ReferenceFileSystem._process_referencescCsd|krt|}||_dS)z&Make reference dict for Spec Version 0Zzarr_consolidated_formatN) _unmodel_hdf5r<)r>r<rrrr*sz(ReferenceFileSystem._process_references0csXj sjrHy ddlWn,tk rF}ztd|WYdd}~XnXi_j|jditdfdd}x|jdij D]\}}t |t r|j drt j|d dj|<|j|<q|d}d |kr jr|jd d jd d jfj}n||}t|dkr|gn||d|dgj|<qWjjj|jdgdS)Nrz(Reference Spec Version 1 requires jinja2ricsj|jfjS)N)r{r|r)u)rxr>rrr}:sz?ReferenceFileSystem._process_references1.._render_jinjarefszbase64:rMz{{rvz}}rwrrr)r'rrx ImportErrorrr<r~r/ritemsr)r*rSrTrUryrzrVupdate _process_gen)r>r<r&er}rvrr)rxr>rr1s,        0z(ReferenceFileSystem._process_references1cshddli|_|jdk r$|j|jx>|jD]2\}}d|krV|ffdd |j|<q.||j|<q.WdS)Nrz{{csj|jf|S)N)r{r|)tempr@)rxrrYsz8ReferenceFileSystem._process_templates..)rxrr&rr)r>tmprrr)rxrr~Qs  z&ReferenceFileSystem._process_templatesc s ddl}i}x |D]}dd|djDfddtjjD}x|D]}|j|djf||j}|j|djf||j}d |krd |krt|j|d jf||j} t|j|d jf||j} || | g||<qRd |kd |kAr t d qR|g||<qRWqW|S) NrcSs@i|]8\}}t|tr|nt|jdd|d|jdd|qS)rYrstopstepr)r)r=ranger/)rrrrrrrdsz4ReferenceFileSystem._process_gen..Z dimensionsc3s |]}ttj|VqdS)N)r+zipkeys)rr8) dimensionrrrrksz3ReferenceFileSystem._process_gen..rrrlengthz^Both 'offset' and 'length' are required for a reference generator entry if either is provided.) rxr itertoolsproductr8r{r|rintr) r>ZgensrxoutrZproductsprrrrrr)rrr_s*  z ReferenceFileSystem._process_genc Cs.dgi|_|jr|jj}n |jj}x|D]\}}|jr\|drRt|d}q|d}n4t|tt frtt|}nt|dkrd}n |\}}}d|kr|j dddnd}|}x\|o||jkr g|j|<|jj d|kr|j dddndgj |ddd|j |}qW|j|j |d |dq.WdS) Nrrr/r directory)nametyperfile)Zdircacher%r0Ziterrowsr<rrVr)rRr*rsplit setdefaultappend_parent) r>itrWrXrrIrYparZpar0rrrrs.         z(ReferenceFileSystem._dircache_from_itemsr cKs |dkr t|j|}tj|S)Nr )rtr`ioBytesIO)r>rWmode block_sizeZ cache_optionsr@rrrrrs zReferenceFileSystem.opencKs6|j|}|j|}|dkr t|r(|Sdd|DS)NcSsg|] }|dqS)rr)rorrr sz*ReferenceFileSystem.ls..)rN_ls_from_cacheFileNotFoundError)r>rWdetailr@rrrrlss  zReferenceFileSystem.lsc Ks(y|j|dk Stk r"dSXdS)NF)rr)r>rWr@rrrexistsszReferenceFileSystem.existscCs|j|o|j|ddkS)Nrr)rr4)r>rWrrrreszReferenceFileSystem.isdircCs|j|o|j|ddkS)Nrr)rr4)r>rWrrrisfileszReferenceFileSystem.isfilecs|j||f|S)N)r)r>rWrr@rrr_lsszReferenceFileSystem._lsc sN|rtjf||d|SrD|jtfdd|jDSt|jS)N)maxdepthwithdirsc3s|]}|jr|VqdS)N)rS)rr)rWrrrrsz+ReferenceFileSystem.find..)r"findrNsortedr<)r>rWrrr@)rJ)rWrrs  zReferenceFileSystem.findc s6|jd}fdd|D}|s.dddS|dS)NTcsg|]}|dkr|qS)rr)rr)rWrrrsz,ReferenceFileSystem.info..rr)rrr)r)r>rWr@rZout0r)rWrr4s   zReferenceFileSystem.infocs |j|S)N)r4)r>rWr@rrr_infoszReferenceFileSystem._info) NNNNNNNNTNN)NN)NN)F)F)N)N)r NN)T)T)NF)"__name__ __module__ __qualname____doc__rr#propertyr r[r\r`rbrkrrmr/rur5r6rrr~rrrrrrerrrr4r __classcell__rr)rJrr sLu !      #   r c Csddl}i}x|djD]\}}|jdr|jdd}|jd|}|rf|jd|dd |d}xF|jD]&\}}||d |d |d f||<qpWqtj|j||<qW|S) z'Special JSON format from HDF5 prototyperNmetadataz .zchunkstoresourceuriz#https://([^.]+)\.s3\.amazonaws\.comzhttps://z.s3.amazonaws.comrr) rerr,popfindallryr1dumpsrQ) r<rrHrrarmatchrrrrrrs  $r)rTrrloggingrf functoolsrZ fsspec.corer:Zujsonr1rZasynrr callbacksrr;rrmappingr specr getLoggerr3r rrrrrs*      =