f^ddlmZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZddlmZmZmZmZddlmZdd lmZmZdd lmZdd lmZdd lmZmZm Z m!Z!m"Z"m#Z#m$Z$ejJd Z&dZ'Gdde(Z)Gdde)Z*GddejVZ,y)) annotationsN)ESPIPE) has_magic)sha256)AnyClassVarDictTuple)DEFAULT_CALLBACK) apply_configconf)DirCache) Transaction)_unstrip_protocolglob_translate isfilelike other_paths read_blockstringify_pathtokenizefsspecc||i|SN)clsargskwargss T/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/fsspec/spec.py make_instancer s   c,eZdZdZfdZfdZxZS)_Cacheda Metaclass for caching file system instances. Notes ----- Instances are cached according to * The values of the class attributes listed in `_extra_tokenize_attributes` * The arguments passed to ``__init__``. This creates an additional reference to the filesystem, which prevents the filesystem from being garbage collected when all *user* references go away. A call to the :meth:`AbstractFileSystem.clear_instance_cache` must *also* be made for a filesystem instance to be garbage collected. ct||i|tjdrt j |_ni|_tj|_ y)Nweakref_instance_cache) super__init__rgetweakrefWeakValueDictionary_cacheosgetpid_pid)rrr __class__s rr'z_Cached.__init__5sH $)&) 88, - 446CJCJ99;r!ct|}tfdjD}tjt j g||i|}|jdd}tjjk7r3jjtj_|s0jr$|jvr|_ j|St<|i|}||_||_||_|j&r|j(rddlm}||jr|s|_ |j|<|S)Nc38K|]}t|dywrgetattr).0attrrs r z#_Cached.__call__..Cs )-GCt $ sskip_instance_cacheFr )mirror_sync_methods)r tuple_extra_tokenize_attributesrr. threading get_identpopr,r-r+clearcachable_latestr&__call__ _fs_token_ storage_argsstorage_options async_implr8asyn) rrr extra_tokenstokenskipobjr8r/s ` rrAz_Cached.__call__As8c6* 141O1O   9..0 37 :F JP zz/7 99;#(( " JJ   yy{CH #**)<CK::e$ $'"D3F3C"CN#C "(C ~~#"9"95#C(||D# $' 5!Jr!)__name__ __module__ __qualname____doc__r'rA __classcell__)r/s@rr#r#$s r!r#c6eZdZUdZdZdZdZdZdZde d<d Z dZ dZ d Z eZd Zd e d <de d<dZedZedZdZdZdZdZedZdcdZedZedZedZdZ dZ!dddZ"dedZ#dfd Z$d!Z%ded"Z&d#Z'dgd$Z(dhd%Z)did&Z*ddd'Z+d(Z,d)Z-d*Z.d+Z/d,Z0d-Z1d.Z2d/Z3djd0Z4 djd1Z5dkd2Z6d3Z7ddd4Z8 dld5Z9dmd6Z:e;d fd7Zde;d fd:Z?dnd;Z@dnd<ZAd=ZB dod>ZCdpd?ZDdpd@ZEdAZFdBZGdpdCZHedDZI dqdEZJ drdFZKdedGZLdHZMdddIZNddJdsdKZOedtdLZPddJdudMZQedvdNZRdOZSdwdPZTedQZUdRZVdSZWdkdTZXdUZYdedVZZdfdWZ[dedXZ\dYZ]dZZ^d[Z_dxd\Z`d]Zadpd^Zbdfd_Zcdfd`ZddydaZedbZfy )zAbstractFileSystemz An abstract super-class for pythonic file-systems Implementations are expected to be compatible with or, better, subclass from here. TFi@/abstractzClassVar[str | tuple[str, ...]]protocolNrzTuple[Any, ...]rCDict[str, Any]rDc4|jryd|_d|_d|_g|_t di||_|j ddrtjdt|j ddrtjdtd|_ y) aCreate and configure file-system instance Instances may be cachable, so if similar enough arguments are seen a new instance is not required. The token attribute exists to allow implementations to cache instances if they wish. A reasonable default should be provided if there are no arguments. Subclasses should call this method. Parameters ---------- use_listings_cache, listings_expiry_time, max_paths: passed to ``DirCache``, if the implementation supports directory listing caching. Pass use_listings_cache=False to disable such caching. skip_instance_cache: bool If this is a cachable implementation, pass True here to force creating a new instance even if a matching instance exists, and prevent storing this instance. asynchronous: bool loop: asyncio-compatible IOLoop or None NTFadd_docsz add_docs is no longer supported. add_aliaseszadd_aliases has been removed.r) _cached_intrans _transaction"_invalidated_caches_in_transactionrdircacher=warningswarn FutureWarningrB)selfrrDs rr'zAbstractFileSystem.__init__{s0 <<    24/ 3?3   z4 0 MM>2&&r!cbt|t|xr|j|jk(Sr) isinstancetyperirbothers r__eq__zAbstractFileSystem.__eq__s%%d,R5??1RRr!cRtt||j|jffSr)r rrrCrDrfs r __reduce__zAbstractFileSystem.__reduce__s$tDz4+<+R>RSSSr!ct|tr|Dcgc]}|j|c}St|}t|jt r |jfn |j}|D]N}|j |dzr|t|dzd})|j |dzs>|t|dzd}P|jd}|xs |jScc}w)zTurn path from fully-qualified to file-system-specific May require FS-specific handling, e.g., for relative paths or links. ://Nz::rR) rqlist_strip_protocolrrTstr startswithlenrstrip root_marker)rpathpprotosrTs rr}z"AbstractFileSystem._strip_protocols dD !489qC''*9 9d#$.s||S$A#,,s||Hx%/0CMA-/0D1CMA-/0  {{3&s&:sC"ct|jtr |jfn |j}|D]}|j|ds|cS|dd|S)z6Format FS-specific path to generic, including protocolryr)rqrTr~r)rbnamerrTs runstrip_protocolz#AbstractFileSystem.unstrip_protocolsZ%/ s%C$--!H(3/0 )Cv&&r!ciS)afIf kwargs can be encoded in the paths, extract them here This should happen before instantiation of the class; incoming paths then should be amended to strip the options in methods. Examples may look like an sftp path "sftp://user@host:/my/path", where the user and host should become kwargs and later get stripped. r)rs r_get_kwargs_from_urlsz(AbstractFileSystem._get_kwargs_from_urlss  r!cr|j|jvr|j|jS|S)zReturn the most recently instantiated FileSystem If no instance has been created, then create one with defaults )r@r+rs rcurrentzAbstractFileSystem.currents. ;;#** $::ckk* *u r!c^|j|j||_|jS)zA context within which files are committed together upon exit Requires the file class to implement `.commit()` and `.discard()` for the normal and exception cases. )r\transaction_typerfs r transactionzAbstractFileSystem.transactions/    $ $ 5 5d ;D    r!cTd|_|j||_|jS)z@Begin write transaction for deferring files, non-context versionT)r[rr\rrfs rstart_transactionz$AbstractFileSystem.start_transactions(  11$7r!c|jjd|_|jD]}|j ||jj y)z-Finish write transaction, non-context versionN)rcompleter\r]invalidate_cacher>rbrs rend_transactionz"AbstractFileSystem.end_transactionsL !!# ;;D  ! !$ '< //557r!cT|jr|jj|yy)z Discard any cached directory information Parameters ---------- path: string or None If None, clear all listings cached else listings at or under given path. N)r[r]appendrs rrz#AbstractFileSystem.invalidate_caches$ ==  3 3 : :4 @ r!c y)a Create directory entry at path For systems that don't have true directories, may create an for this instance only and not touch the real filesystem Parameters ---------- path: str location create_parents: bool if True, this is equivalent to ``makedirs`` kwargs: may be permissions, etc. Nrrbrcreate_parentsrs rmkdirzAbstractFileSystem.mkdirs r!cy)aRecursively make directories Creates directory at path and any intervening required directories. Raises exception if, for instance, the path already exists but is a file. Parameters ---------- path: str leaf directory name exist_ok: bool (False) If False, will error if the target already exists Nrrbrexist_oks rmakedirszAbstractFileSystem.makedirs*s r!cy)zRemove a directory, if emptyNrrs rrmdirzAbstractFileSystem.rmdir: r!c t)apList objects at path. This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested. The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include: - full path to the entry (without protocol) - size of the entry, in bytes. If the value cannot be determined, will be ``None``. - type of entry, "file", "directory" or other Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc. May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive. Parameters ---------- path: str detail: bool if True, gives a list of dictionaries, where each is the same as the result of ``info(path)``. If False, gives a list of paths (str). kwargs: may have additional backend-specific options, such as version information Returns ------- List of strings if detail is False, or list of directory information dicts if detail is True. rdrbrdetailrs rlszAbstractFileSystem.ls>s N"!r!ch|j|} |j|jdS#t$rYnwxYw |j|Dcgc]+}|d|k(s|d|jdk(r |ddk(r|-ncc}w}}t |dk(r t ||S#t$rYywxYw)zCheck cache for listing Returns listing, if found (may be empty list for a directly that exists but contains nothing), None if not in cache. rRrrr directoryrN)_parentr^rKeyErrorrFileNotFoundError)rbrparentffiless r_ls_from_cachez!AbstractFileSystem._ls_from_cachegs d# ==S!12 2    v.V9$fIS!11ai;6NE 5zQ'--L   s*1 ==B%0B"B%% B10B1c+K||dkr td|j|}i}i}i}|jdd} |j|fddi|} | D]S} | djd } | jd dd }| d d k(r| |k7r | ||<| ||<D| |k(r| |d <O| ||<U| st|}t|}|r|||f||dz}|dkr |s|||fy|D]$}|j||f|| |d|Ed{&|s|||fyy#tt f$r4} |dk(rt |r|| | r |iifcYd} ~ S|ggfcYd} ~ Sd} ~ wwxYw7Ww)aReturn all files belows path List all files, recursing into subdirectories; output is iterator-style, like ``os.walk()``. For a simple list of files, ``find()`` is available. When topdown is True, the caller can modify the dirnames list in-place (perhaps using del or slice assignment), and walk() will only recurse into the subdirectories whose names remain in dirnames; this can be used to prune the search, impose a specific order of visiting, or even to inform walk() about directories the caller creates or renames before it resumes walk() again. Modifying dirnames when topdown is False has no effect. (see os.walk) Note that the "files" outputted will include anything that is not a directory, such as links. Parameters ---------- path: str Root to recurse into maxdepth: int Maximum recursion depth. None means limitless, but not recommended on link-based file-systems. topdown: bool (True) Whether to walk the directory tree from the top downwards or from the bottom upwards. on_error: "omit", "raise", a collable if omit (default), path with exception will simply be empty; If raise, an underlying exception will be raised; if callable, it will be called with a single OSError instance as argument kwargs: passed to ``ls`` Nr maxdepth must be at least 1rFTraiserrRrrrrU)maxdepthrtopdown) ValueErrorr}r=rrOSErrorcallablerrsplitr|walk)rbrrron_errorr full_dirsdirsrrlistingeinfopathnamerds rrzAbstractFileSystem.walksB  HqL:; ;##D) He, dggd:4:6:GDF|**3/H??3*2.DF|{*x4/?"* $!T T! b "d :DKE e# #   MH!|e++A tyy! !     e# #a"7+ 7"(# R|#R<  P sS.>s-#*-s*?[rFrRrUrTrrrrrr)rrer,raltseprendswithr}r9rrminr=rexistsrrindexcountrcompilerrmatchr|)rbrrrrseps ends_with_sepappend_slash_to_dirnameidx_star idx_qmark idx_bracemin_idxrrootdepthidx_double_starsdepth_double_starsallpathspatternrrrs rglobzAbstractFileSystem.glob(s  HqL:; ;02 RWW^^,RWW[[N d+ ##D)"/# 4== -- -4 &*YYs^q%8499S>c$i&*iin&9DIIcNs4y &*iin&9DIIcNs4y h 95He,t{{4*6* 6M )$))D";F";<<II D'N "8Gn++C0G 'A+&D1'--c2Q6ED1'--c2Q6E 4<##'99T? %)*:*;%<%B%B3%G!%K" 22X=499TXEDXQWX  2!FG**W%"(.."23  4}}/4<;3NG  tG     J9   s-Kc : |j|fi|y#YyxYw)z!Is there a file at the given pathTFrrbrrs rrzAbstractFileSystem.existsys'  DIId %f % sc $|j|S)zEIf there is a file at the given path (including broken links))rrs rlexistszAbstractFileSystem.lexistss{{4  r!c |j|}|j|j|fddi|}|Dcgc]}|djd|k(s|}}|r|dS|j|fddi|}|jd}|Dcgc]}|djd|k(s|}}t |dk(rd|dvrd|dd<|dSt |dkDs|r|dd d St |cc}wcc}w) agGive details of entry at path Returns a single dictionary, with exactly the same information as ``ls`` would with ``detail=True``. The default implementation should calls ls and could be overridden by a shortcut. kwargs are passed on to ```ls()``. Some file systems might not be able to measure the file's size, in which case, the returned dict will include ``'size': None``. Returns ------- dict with keys: name (full path in the FS), size (in bytes), type (file, directory, or something else) and other FS-specific keys. rTrrRrr rNr)rrrr)r}rrrrr)rbrrroout1s rrzAbstractFileSystem.infos"##D)dggdll4(@@@?Q6!1!1#!6$!>q?? q6Mdggd24262{{3@a!F)"2"23"74"?@@ t9>T!W$"&Q7N Y]c ![A A#D) )@ AsC4C4C9+C9cJtt|j|dS)aUnique value for current version of file If the checksum is the same from one moment to another, the contents are guaranteed to be the same. If the checksum changes, the contents *might* have changed. This should normally be overridden; default will probably capture creation/modification timestamp (which would be good) or maybe access timestamp (which would be bad) rm)rnrrrs rchecksumzAbstractFileSystem.checksums8DIIdO,b11r!cD|j|jddS)zSize in bytes of filerN)rr(rs rrzAbstractFileSystem.sizesyy""6400r!cJ|Dcgc]}|j|c}Scc}w)z-Size in bytes of each file in a list of paths)r)rbpathsrs rrzAbstractFileSystem.sizess&+, ! ,,,s cP |j|ddk(S#t$rYywxYw)zIs this entry directory-like?rrrF)rrrs rrzAbstractFileSystem.isdirs1 99T?6*k9 9  s  %%c@ |j|ddk(S#YyxYw)zIs this entry file-like?rrfileFrrs rrzAbstractFileSystem.isfiles) 99T?6*f4 4 sc ~|j|fd|||d|5}|jcdddS#1swYyxYw)zGet the contents of the file as a string. Parameters ---------- path: str URL of file on this filesystems encoding, errors, newline: same as `open`. rmodeencodingerrorsnewlineNopenread)rbrr r r rrs r read_textzAbstractFileSystem.read_textsSTYY       668   s3<c |j|fd|||d|5}|j|cdddS#1swYyxYw)aWrite the text to the given file. An existing file will be overwritten. Parameters ---------- path: str URL of file on this filesystems value: str Text to write. encoding, errors, newline: same as `open`. wrNrwrite)rbrvaluer r r rrs r write_textzAbstractFileSystem.write_textsUTYY       "775> " " "s4=c z|j|dfi|5}|?|dk\r|j|n(|jtd|j|z|?|dkr|j|z}|j ||j z cdddS|j cdddS#1swYyxYw)ahGet the content of a file Parameters ---------- path: URL of file on this filesystems start, end: int Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively kwargs: passed to ``open()``. rbNr)rseekmaxrrtell)rbrstartendrrs rcat_filezAbstractFileSystem.cat_filesTYYtT ,V ,  A:FF5MFF3q!&&5.127&&3,CvvcAFFHn-  668   sA9B1B11B:c x|j|dfi|5}|j|dddy#1swYyxYw)zSet the bytes of given filewbNr)rbrrrrs r pipe_filezAbstractFileSystem.pipe_files9 TYYtT ,V ,  GGEN   s09c t|tr$|j|j||fi|yt|tr<|j D](\}}|j|j||fi|*yt d)aPut value into path (counterpart to ``cat``) Parameters ---------- path: string or dict(str, bytes) If a string, a single remote location to put ``value`` bytes; if a dict, a mapping of {path: bytesvalue}. value: bytes, optional If using a single path, these are the bytes to put there. Ignored if ``path`` is a dict zpath must be str or dictN)rqr~r!r}dictrr)rbrrrkvs rpipezAbstractFileSystem.pipesz dC DNN4//5u G G d # 1t33A6DVD%78 8r!c |tt|tstt|ts|gt |z}t|ts|gt |z}t |t |k7st |t |k7rt g}t |||D])\}} } |j|j|| | +|S#t$r"} |dk(r|j| nYd} ~ Td} ~ wwxYw)aYGet the contents of byte ranges from one or more files Parameters ---------- paths: list A list of of filepaths on this filesystems starts, ends: int or list Bytes limits of the read. If using a single int, the same value will be used to read all the specified files. Nreturn) rerqr| TypeErrorrrziprr Exception) rbrstartsendsmax_gaprrrrsrs r cat_rangeszAbstractFileSystem.cat_ranges,s  % %%&O&$'XE *F$%6CJ&D v;#e* $D SZ(? 5&$/GAq!  4==Aq120  x'JJqM" s("C C9C44C9c N|j||}t|dkDs't|ts|d|j |k7r"i}|D]} |j |fi|||<|S|j |dfi|S#t $r}|dk(r|dk(r|||<Yd}~Rd}~wwxYw)aFetch (potentially multiple) paths' contents Parameters ---------- recursive: bool If True, assume the path(s) are directories, and get all the contained files on_error : "raise", "omit", "return" If raise, an underlying exception will be raised (converted to KeyError if the type is in self.missing_exceptions); if omit, keys with exception will simply not be included in the output; if "return", all keys are included in the output, but the value will be bytes or an exception instance. kwargs: passed to cat_file Returns ------- dict of {path: contents} if there are multiple paths or the path has been otherwise expanded  recursiver rrr(N) expand_pathrrqr|r}rr+)rbrr3rrrrrs rcatzAbstractFileSystem.catNs*   ; JN$%Qx4//55C& - d =f =CIJ 4==q4V4 4!&7*8+$%D &sB B$ BB$c ddlm}t|r|}n)|j|rt j |dy|d}|j |j |d|j|dfi|5}| t|d} |jt|d dd} | rM|j|j} |j| } | t| } |j| | rMt|s|j dddy#t|s|jwwxYw#1swYyxYw) z Copy single remote file to localr )LocalFileSystemTrN) auto_mkdirrr r)implementations.localr7rrr,rrrset_sizer3r blocksizerrrelative_updateclose) rbrpathlpathcallbackoutfilerr7fsf1data segment_lens rget_filezAbstractFileSystem.get_filevs': e G ZZ  KK -  - BJJu% 5 TYYud -f - $ud+ $!!'"fd";<774>>2D")--"5K"*&)$i ,,[9 "%(MMO $ $"%(MMO) $ $s%=E A,D:ED==EE c >t|trt|tr|}|}nddlm} m} m} t|t } |j|||}| r1|r|-|D cgc]} | | r |j| r| !}} |syt|t r| |}t|dk(}t|t xr | |xs| j|}| xr,t|xr|xst| xr |xr | | }t|||| }|jt||jt||D]6\}}|j||5}|j ||fd|i|ddd8ycc} w#1swYHxYw)aTCopy file(s) to local. Copies a specific file or tree of files (if recursive=True). If lpath ends with a "/", it will be assumed to be a directory, and target files will go within. Can submit a list of paths, which may be glob-patterns and will be expanded. Calls get_file for each source. r r7make_path_posix trailing_sepr3rNrflattenrA)rqr|r:r7rJrKr~r4rrrrr;wrapr*branchedrG)rbr?r@r3rArrrpathslpathsr7rJrK source_is_strrsource_is_file dest_is_dirrchilds rr(zAbstractFileSystem.gets$ eT "z%'>FF   'uc2M%%ey8%TFi83G%+VLOtzzRS}!VV%%'. [A-N$UC0U#E'8'>'>u'E #5!4nV!%((T[TeAT=T !)) F #f+&$MM#ff*=>LE5""5%0 FE eUEUEfE F F?1W2 F Fs F,F>F,FF c tjj|r|j|dyt |d5}|j dd}|j ||j d|j|jtj|d|j|dfi|5}|j|kr^|j|j}|j|} | t|} |j| |j|kr^ddddddy#1swYxYw#1swYyxYw)zCopy single file to remoteTr8Nrrr{r )r,rrrrrr;mkdirsrfspathrrr<rrr=) rbr@r?rArrDrf2rErFs rput_filezAbstractFileSystem.put_files 77==  MM%$M / %  :"771a=D   d # GGAJ KK RYYu%56K F5$1&1 :Rggi$&774>>2D"$((4.K"*&)$i ,,[9 ggi$& : : :  : : : :s&A>E >A1E0E E E  Ec t|trt|tr|}|}n-ddlm} m} m} t|t } | r| |}| } | j|||}| r1|r|-|Dcgc]}| |r | j|r|!}}|syt|dk(}t|t xr| |xs|j|}t|t r|j|n|Dcgc]}|j|c}}| xr,t|xr|xst| xr |xr | | }t|||| }|jt||jt||D]6\}}|j!||5}|j"||fd|i|ddd8ycc}wcc}w#1swYMxYw)aCopy file(s) from local. Copies a specific file or tree of files (if recursive=True). If rpath ends with a "/", it will be assumed to be a directory, and target files will go within. Calls put_file for each source. r rIrLNrMrA)rqr|r:r7rJrKr~r4rrr}rrr;rOr*rPr[)rbr@r?r3rArrrQrRr7rJrKrSrCrrTrUrrVs rputzAbstractFileSystem.puts" eT "z%'>FF   'uc2M'. "B^^EY^RFi83G%+TLOrxxPQ{!TT [A-N$UC0U#8tzz%'8  eS)$$U+7<=!d**1-=  #5!4nV!%((T[TeAT=T !)) F #f+&$MM#ff*=>LE5""5%0 FE eUEUEfE F F?5U> F Fs$0 G>GG9G!G  G ct|j|d5}|j|cdddS#1swYyxYw)z&Get the first ``size`` bytes from filerNr rbrrrs rheadzAbstractFileSystem.head(s2 YYtT " a66$<   s.7c|j|d5}|jt| |j d|j cdddS#1swYyxYw)z%Get the last ``size`` bytes from filerr{N)rrrrrr_s rtailzAbstractFileSystem.tail-sM YYtT " a FF3uqvvg& *668   s 8AAc trrdrbpath1path2rs rcp_filezAbstractFileSystem.cp_file3s!!r!c ||rd}n|d}t|trt|tr|}|}nddlm} t|t} |j |||}| r1|r|-|D cgc]} | | r |j | r| !}} |syt|dk(} t|txr| |xs|j |} | xr,t|xr| xst| xr | xr | | }t|||| }t||D]\}} |j||fi|ycc} w#t$r |dk(rY4wxYw)a?Copy within two locations in the filesystem on_error : "raise", "ignore" If raise, any not-found exceptions will be raised; if ignore any not-found exceptions will cause the path to be skipped; defaults to raise unless recursive is true, where the default is ignore Nignorerr )rKrLrM) rqr|r:rKr~r4rrrrr*rgr)rbrerfr3rrrpaths1paths2rKrSrrTrUrp1p2s rcopyzAbstractFileSystem.copy6s   H  H eT "z%'>FF ;&uc2M%%ey8%TFi83G%+VLOtzzRS}!VV [A-N$UC0U#8tzz%'8 #5!4nV!%((T[TeAT=T !)) F&&)FB  R.v.*)W.% w&' s$% D33D3D3D88E  E c ||dkr tdt|ttjfr|j |g||}nt }|Dcgc]}|j|}}|D]}t|r`t |j|fd|i|}||z}|r:||dkr;|t |j t|f|||dz ndd|z}n|r%t |j|f|ddd|}||z}||vs|dus|j|s|j||s t|t|Scc}w) zTurn one or more globs or directories into a list of all matching paths to files or directories. kwargs are passed to ``glob`` or ``find``, which may in turn call ``ls`` Nr rrrLTFr)rrqr~r,PathLiker4setr}rrr|rraddrr) rbrr3rrrrbitrecs rr4zAbstractFileSystem.expand_pathls  HqL:; ; dS"++. /""D69h?C%C59:D((+:D:Q<idiiGHGGHC3JC $/HM$s,D,, $S *39A9MASW#)  ! (04QWC 3JCCGGAJ9:#D) )c{A;sE c ||k(rtjd|y|j||||d|j||y)z)Move file(s) from one location to anotherz6%s mv: The paths are the same, so no files were moved.r)r3ronerrorr2N)loggerdebugrnrm)rbrerfr3rrs rmvzAbstractFileSystem.mvsI E> LLQSW X IIu Hg   GGEYG /r!c&|j|y)z Delete a fileN)_rmrs rrm_filezAbstractFileSystem.rm_files  r!ct)zDelete one filerdrs rr|zAbstractFileSystem._rms "!r!cn|j|||}t|D]}|j|y)aDelete files. Parameters ---------- path: str or list of str File(s) to delete. recursive: bool If file(s) are directories, recursively delete contents and then also remove the directory maxdepth: int or None Depth to pass to walk for finding files to delete, if recursive. If None, there will be no limit and infinite recursion may be possible. rLN)r4reversedr})rbrr3rrs rryzAbstractFileSystem.rms4 HM$A LLO r!c|j|}d|vr=|jdddj|j}|j|zS|jS)NrRr r)r}rlstripr)rrrs rrzAbstractFileSystem._parentsV""4( $;[[a(+223??CF??V+ +?? "r!c &t|||||fd|i|S)z4Return raw bytes-mode file-like from the file-system cache_options)AbstractBufferedFile)rbrr  block_size autocommitrrs r_openzAbstractFileSystem._opens4$       (    r!c ddl}|j|}d|vra|jdddz}dDcic]}||vr||j|} }|j|j ||f|||d|fi| S|jd|j } |j|f||| |d |} |'dd lm } dd l m } | ||}| |}|| |d } | s)d |vr%|jjj| | Scc}w)a6 Return a file-like object from the filesystem The resultant instance must function correctly in a context ``with`` block. Parameters ---------- path: str Target file mode: str like 'rb', 'w' See builtin ``open()`` block_size: int Some indication of buffering - this is a value in bytes cache_options : dict, optional Extra arguments to pass through to the cache. compression: string or None If given, open file using compression codec. Can either be a compression name (a key in ``fsspec.compression.compr``) or "infer" to guess the compression from the filename suffix. encoding, errors, newline: passed on to TextIOWrapper for text mode rNbtrU)r r r )rr compressionr)r rrr)compr)get_compression)r r)ior}replacer= TextIOWrapperrr[rfsspec.compressionr fsspec.corerrrr)rbrr rrrrrr$ text_kwargsacrrrcompresss rrzAbstractFileSystem.opens^> ##D) d?<<R(3.D;;6::a= K $2##  *"/ +      Ldmm*;>@@r!c|j|d5}|j}||}| ||z|kDr||z }t||||cdddS#1swYyxYw)aRead a block of bytes from Starting at ``offset`` of the file, read ``length`` bytes. If ``delimiter`` is set then we ensure that the read starts and stops at delimiter boundaries that follow the locations ``offset`` and ``offset + length``. If ``offset`` is zero then we start at zero. The bytestring returned WILL include the end delimiter string. If offset+length is beyond the eof, reads to eof. Parameters ---------- fn: string Path to filename offset: int Byte offset to start read length: int Number of bytes to read. If None, read to end. delimiter: bytes (optional) Ensure reading starts and stops at delimiter bytestring Examples -------- >>> fs.read_block('data/file.csv', 0, 13) # doctest: +SKIP b'Alice, 100\nBo' >>> fs.read_block('data/file.csv', 0, 13, delimiter=b'\n') # doctest: +SKIP b'Alice, 100\nBob, 200\n' Use ``length=None`` to read to the end of the file. >>> fs.read_block('data/file.csv', 0, None, delimiter=b'\n') # doctest: +SKIP b'Alice, 100\nBob, 200\nCharlie, 300' See Also -------- :func:`fsspec.utils.read_block` rN)rrr)rbfnoffsetlength delimiterrrs rrzAbstractFileSystem.read_block@seJYYr4  >"!CLL>2!+EE4=!AU1Xu//0A0AB ,,_=   r!c"ddlm}|}t|}|j|}| t d|j dd|j dd||j |j ddi|j |S) a Recreate a filesystem instance from dictionary representation. See ``.to_dict()`` for the expected structure of the input. Parameters ---------- dct: Dict[str, Any] Returns ------- file system instance, not necessarily of this particular class. Warnings -------- This can import arbitrary modules (as determined by the ``cls`` key). Make sure you haven't installed any modules that may execute malicious code at import time. r rNz#Not a serialized AbstractFileSystemrrTrr)rrr#try_resolve_fs_clsrr=unmake_serializable)dctr json_decoderrs r from_dictzAbstractFileSystem.from_dicts* 0,. 3i#66s; ;BC C t  D!  - -cggfb.A B ..s3  r!c|S)zW Make a version of the FS instance which will be acceptable to pyarrow rrfs r_get_pyarrow_filesystemz*AbstractFileSystem._get_pyarrow_filesystems  r!c(ddlm}||||||S)zCreate key/value store based on this file-system Makes a MutableMapping interface to the FS at the given root path. See ``fsspec.mapping.FSMap`` for further details. r )FSMap)checkcreatemissing_exceptions)mappingr)rbrrrrrs r get_mapperzAbstractFileSystem.get_mappers# #  1   r!c8|jjy)a Clear the cache of filesystem instances. Notes ----- Unless overridden by setting the ``cachable`` class attribute to False, the filesystem class stores a reference to newly created instances. This prevents Python's normal rules around garbage collection from working, since the instances refcount will not drop to zero until ``clear_instance_cache`` is called. N)r+r>rs rclear_instance_cachez'AbstractFileSystem.clear_instance_cache s r!ct)z=Return the created timestamp of a file as a datetime.datetimerdrs rcreatedzAbstractFileSystem.created!!r!ct)z>Return the modified timestamp of a file as a datetime.datetimerdrs rmodifiedzAbstractFileSystem.modified rr!c .|j|f||d|S)z'Alias of `AbstractFileSystem.cat_file`.)rr)r)rbrrrrs r read_byteszAbstractFileSystem.read_bytes'st}}TBCB6BBr!c ,|j||fi|y)z(Alias of `AbstractFileSystem.pipe_file`.N)r!)rbrrrs r write_byteszAbstractFileSystem.write_bytes+stU-f-r!c ,|j|fd|i|S)z$Alias of `AbstractFileSystem.mkdir`.r)rrs rmakedirzAbstractFileSystem.makedir/stzz$H~HHHr!c(|j||S)z'Alias of `AbstractFileSystem.makedirs`.r8)rrs rrXzAbstractFileSystem.mkdirs3s}}TH}55r!c ,|j|fd|i|S)z!Alias of `AbstractFileSystem.ls`.r)rrs rlistdirzAbstractFileSystem.listdir7stwwt5F5f55r!c *|j||fi|S)z#Alias of `AbstractFileSystem.copy`.)rnrds rcpzAbstractFileSystem.cp;styy000r!c *|j||fi|Sz!Alias of `AbstractFileSystem.mv`.rzrds rmovezAbstractFileSystem.move?twwue.v..r!c (|j|fi|S)z#Alias of `AbstractFileSystem.info`.rrs rstatzAbstractFileSystem.statCstyy(((r!c .|j|f||d|S)z!Alias of `AbstractFileSystem.du`.)rr)r)rbrrrrs r disk_usagezAbstractFileSystem.disk_usageGstwwtF58FvFFr!c *|j||fi|Srrrds rrenamezAbstractFileSystem.renameKrr!c*|j|||S)z!Alias of `AbstractFileSystem.rm`.rL)ry)rbrr3rs rdeletezAbstractFileSystem.deleteOswwty8wDDr!c .|j||fd|i|S)z"Alias of `AbstractFileSystem.put`.r3)r])rbr@r?r3rs ruploadzAbstractFileSystem.uploadStxxuD DVDDr!c .|j||fd|i|S)z"Alias of `AbstractFileSystem.get`.r3)r()rbr?r@r3rs rdownloadzAbstractFileSystem.downloadWrr!c td)aCreate a signed URL representing the given path Some implementations allow temporary URLs to be generated, as a way of delegating credentials. Parameters ---------- path : str The path on the filesystem expiration : int Number of seconds to enable the URL for (if supported) Returns ------- URL : str The signed URL Raises ------ NotImplementedError : if method is not implemented for a filesystem z+Sign is not implemented for this filesystemrd)rbr expirationrs rsignzAbstractFileSystem.sign[s,""OPPr!cy)NFrrfs r _isfilestorezAbstractFileSystem._isfilestoress r!)rr~r(r~r)TF)NTomit)NFF)TNF)NNN)NN)Nr()Fr)i)FNN)FN)rNTN)rNNN)rboolr(r~)rr~r(rQ)rrr(rV)rrVr(rQ)rUFFN)TN)d)grKrLrMrNr?rZr<rrT__annotations__r@rEr8rrrr:r'propertyrgrirkrorurw classmethodr}r staticmethodrrrrrrrrrrrrrrrrrrrrrrrrrrr!r&r0r5r rGr(r[r]r`rbrgrnr4rzr}r|ryrrrrrrrrrrrrrrrrrrrXrrrrrrrrrrrrr!rrQrQas HGI C0:H-:GJK""$"!##'R"" 'ST''$'  !! 8A" $  '"R2^$@$7L DOb! *D 21-(@D"22 9.;C D&5P/?$D! <F|/?:0! @FD  "FJ4l.` 0" &##  . IV&"A+abrr zFile mode not supportedrr)corerrrCr DEFAULT_BLOCK_SIZEr<locrrrclosedr_r`rar=rrerdetails _fetch_rangecacherBytesIObufferrforcedlocation) rbrCrr rr cache_typerrrrs rr'zAbstractBufferedFile.__init__s-L !  '15F'FD # #J $   M V  MMJ  %+JJv$6M& ! ) )%&?@ @ 4<   LL0 + + 1 1499@MDJ**,DKDKDK DMr!c|j*|jj|j|_|jSr)_detailsrCrrrfs rrzAbstractBufferedFile.detailss. ==  GGLL3DM}}r!c&||_|d|_y)Nr)r r)rbrs rrzAbstractBufferedFile.detailss &M r!cBt|j|jSr)rrrCrfs r full_namezAbstractBufferedFile.full_names DGG44r!ct|ddS)N_closedTr2rfs rrzAbstractBufferedFile.closedstY--r!c||_yr)r)rbcs rrzAbstractBufferedFile.closeds  r!crd|jvr t|Stt|jdS)Nrrm)r idrnrrrfs rrozAbstractBufferedFile.__hash__s- $)) d8Ox -r2 2r!c||uryt|t|xr9|jdk(xr(|jdk(xrt|t|k(S)zAFiles are equal if they have the same checksum, only in read modeTr)rqrrr hashrss rruzAbstractBufferedFile.__eq__sX 5= ud4j ) * T! * d" *T d5k)  r!cy)z#Move from temp to final destinationNrrfs rcommitzAbstractBufferedFile.commitr!cy)zThrow away temporary fileNrrfs rdiscardzAbstractBufferedFile.discardrr!cLd|jvr |jStd)z File information about this pathrz Info not available while writing)r rrrfs rrzAbstractBufferedFile.infos$ $)) << ?@ @r!c|jS)zCurrent file location)rrfs rrzAbstractBufferedFile.tells xxr!ct|}|jdk(sttd|dk(r|}n9|dk(r|j|z}n$|dk(r|j |z}nt d|d|dkr t d||_|jS) zSet current file location Parameters ---------- loc: int byte location whence: {0, 1, 2} from start of file, current location or end of file, resp. rz Seek only available in read moderr r{zinvalid whence (z, should be 0, 1 or 2)zSeek before start of file)rnr rrrrr)rbrwhencenlocs rrzAbstractBufferedFile.seeks#hyyD &"DE E Q;D q[88c>D q[99s?D/x7MNO O !889 9xxr!cb|jdvr td|jr td|jr td|jj |}|xj |z c_|jj|jk\r|j|S)z Write data to buffer. Buffer only sent on flush() or if buffer is greater than or equal to blocksize. Parameters ---------- data: bytes Set of bytes to be written. >rr zFile not in write modeI/O operation on closed file.z0This file has been force-flushed, can only close) r rrrrrrrr<flush)rbrErs rrzAbstractBufferedFile.write-s 99L (56 6 ;;<= = ;;OP Pkk% C ;;    / JJL r!c|jr td|r|jr td|rd|_|jdvry|s(|jj |j kry|jd|_ |j|j|durI|xj|jjdd z c_tj|_yy#d|_xYw) a{ Write buffered data to backend store. Writes the current buffer, if it is larger than the block-size, or if the file is being closed. Parameters ---------- force: bool When closing, write the last block even if it is smaller than blocks are allowed to be. Disallows further writing to this file. zFlush on closed filez+Force flush cannot be called more than onceT>rr Nr)finalFr{) rrrr rrr<r_initiate_upload _upload_chunkrrr)rbforces rr$zAbstractBufferedFile.flushEs ;;34 4 T[[JK K DK 99L ( ))+dnn<  ;; DK %%'   E  *% 7 KK4;;++Aq1 1K**,DK 8  " s C55 C?cy)zWrite one part of a multi-block file upload Parameters ========== final: bool This is the last block, so should complete file, if self.autocommit is True. Nr)rbr&s rr(z"AbstractBufferedFile._upload_chunkorr!cy)zCreate remote file/uploadNrrfs rr'z%AbstractBufferedFile._initiate_uploadzrr!ct)z*Get the specified set of bytes from remoterd)rbrrs rrz!AbstractBufferedFile._fetch_range~rr!c|dn t|}|jdk7r td|dkr|j|jz }|j r td|dk(ry|j j|j|j|z}tjd||j|j|z|j j|xjt|z c_|S)z Return data from cache, or fetch pieces as necessary Parameters ---------- length: int (-1) Number of bytes to read; if <0, all remaining bytes. rrzFile not in read moderr#r!z%s read: %i - %i %s) rnr rrrrr_fetchrwrx _log_statsr)rbrrs rrzAbstractBufferedFile.reads~3v; 99 45 5 A:YY)F ;;<= = Q;jj$((V*;< !  HH HHv  JJ ! ! #   CH r!ct|jd}|j|j}||dt |t |S)zxmirrors builtin file's readinto method https://docs.python.org/3/library/io.html#io.RawIOBase.readinto BN) memoryviewcastrnbytesr)rbrrrEs rreadintozAbstractBufferedFile.readintosD m  %yy$Kc$i4yr!cxg} |j}|j|xs |j}t|dk(rni|j |}|dkDrA|j |d|t|z|j ||zt|zn|j |dj|S)aReturn data between current position and first occurrence of char char is included in the output, except if the end of the tile is encountered first. Parameters ---------- char: bytes Thing to find blocks: None or int How much to read in each go. Defaults to file blocksize - which may mean a new read on every call. rrNr!)rrr<rrrrjoin)rbcharblocksrrpartfounds r readuntilzAbstractBufferedFile.readuntilsIIKE99V5t~~6D4yA~IIdOErz 4 3%#d)"345 %%-#d)34 JJt xx}r!c$|jdS)zRead until first occurrence of newline character Note that, because of character encoding, this is not necessarily a true line ending.  )r<rfs rreadlinezAbstractBufferedFile.readlines ~~e$$r!c6|j}|r|Str)r? StopIteration)rbrs r__next__zAbstractBufferedFile.__next__smmo Jr!c|Srrrfs r__iter__zAbstractBufferedFile.__iter__ r!c|j}|jd}|ddDcgc]}|dz }}|jdr|S||dgzScc}w)z/Return all data, split by the newline characterr>Nr)rsplitr)rbrElineslrs r readlineszAbstractBufferedFile.readliness_yy{ 5!"'*-Qq5y-- == J%)$ $ .s Ac$|j|Sr)r5)rbrs r readinto1zAbstractBufferedFile.readinto1s}}Qr!ct|ddry|jry|jdk(rd|_d|_y|js|j d|j c|j j|j|j j|j j|jd|_y)z=Close file Finalizes writes, discards cache _unclosableFNrT)r)) r3rr rrr$rCrrrrfs rr>zAbstractBufferedFile.closes 4 .  ;;  99 DJ ;;  &ww"((3(()CD r!c>|jdk(xr |j S)zWhether opened for readingrr rrfs rreadablezAbstractBufferedFile.readablesyyD 4_4r!c"|jS)z'Whether is seekable (only in read mode))rQrfs rseekablezAbstractBufferedFile.seekables}}r!c<|jdvxr |j S)zWhether opened for writing>rr rPrfs rwritablezAbstractBufferedFile.writablesyyL(<_|js|jyyr)rr>rfs r__del__zAbstractBufferedFile.__del__s{{ JJLr!cbdt|jjd|jdS)Nz)rrrCrKrrfs r__str__zAbstractBufferedFile.__str__ s*#DM$:$:#;2dii[JJr!c|Srrrfs r __enter__zAbstractBufferedFile.__enter__rEr!c$|jyr)r>)rbrs r__exit__zAbstractBufferedFile.__exit__s  r!)rrT readaheadNN)rr)r)r>N))rKrLrMrNrr r'rrsetterrrrorurrrrrrr$r(r'rrr5r<r?rBrDrJrLr>rQrSrUrWrZ__repr__r\r^rr!rrr{s1#H  O!b  ^^""55..  ]]3  2(A40('T  ">8% % *5=KHr!r)- __future__rrrloggingr,r;r_r)errnorrrhashlibrtypingrrr r callbacksr configr rr^rrrutilsrrrrrrr getLoggerrwr rrr#rQIOBaserrr!rrls"  --'&$   8 $ :d:zW7Wt0Y299Yr!