
    7Th-                   V   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
  S SKJr  S SKJr  S SKJrJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJrJrJrJrJ r J!r!J"r"  \RF                  " S5      r$S r% " S S\&5      r' " S S\'S9r( " S S\RR                  5      r*S r+g)    )annotationsN)ESPIPE)	has_magic)sha256)AnyClassVar   )DEFAULT_CALLBACK)apply_configconf)DirCache)Transaction)_unstrip_protocolglob_translate
isfilelikeother_paths
read_blockstringify_pathtokenizefsspecc                    U " U0 UD6$ N )clsargskwargss      C/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/spec.pymake_instancer       s        c                  8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )_Cached$   a  
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.
c                   > [         TU ]  " U0 UD6  [        R                  " S5      (       a  [        R
                  " 5       U l        O0 U l        [        R                  " 5       U l	        g )Nweakref_instance_cache)
super__init__r   getweakrefWeakValueDictionary_cacheosgetpid_pid)r   r   r   	__class__s      r   r&   _Cached.__init__5   sK    $)&) 88,-- 446CJCJ99;r   c                  >^  [        T U5      n[        U 4S jT R                   5       5      n[        T T R                  [
        R                  " 5       /UQUQ70 UD6nUR                  SS5      n[        R                  " 5       T R                  :w  a4  T R                  R                  5         [        R                  " 5       T l        U(       d7  T R                  (       a&  UT R                  ;   a  UT l        T R                  U   $ [        TT ]<  " U0 UD6nXFl        Xl        X&l        UR&                  (       a  UR(                  (       a  SSKJn  U" U5        T R                  (       a  U(       d  UT l        UT R                  U'   U$ )Nc              3  >   >#    U  H  n[        TUS 5      v   M     g 7fr   getattr).0attrr   s     r   	<genexpr>#_Cached.__call__.<locals>.<genexpr>C   s!      
1OGCt$$1Os   skip_instance_cacheFr	   )mirror_sync_methods)r   tuple_extra_tokenize_attributesr   r-   	threading	get_identpopr+   r,   r*   clearcachable_latestr%   __call__
_fs_token_storage_argsstorage_options
async_implr9   asyn)	r   r   r   extra_tokenstokenskipobjr9   r.   s	   `       r   rB   _Cached.__call__A   s2   c6* 
141O1O
 
 9..0
37
:F
JP
 zz/799;#(("JJyy{CH#**)<CK::e$$'"D3F3C"N#"(~~#"9"95#C(||D#$'

5!Jr   r   )	__name__
__module____qualname____firstlineno____doc__r&   rB   __static_attributes____classcell__)r.   s   @r   r!   r!   $   s     
 r   r!   c                     \ rS rSr% SrSrSrSrSrSr	S\
S	'   S
rSrSrSr\rSrS\
S'   S\
S'   S r\S 5       r\S 5       rS rS rS rS r\S 5       rSgS jr\S 5       r\S 5       r\S 5       r S r!S r"ShS jr#SiS  jr$SjS! jr%S" r&SiS# jr'S$ r(SkS% jr)SlS& jr*SmS' jr+ShS( jr,S) r-S* r.S+ r/S, r0S- r1S. r2S/ r3S0 r4SnS1 jr5 SnS2 jr6SoS3 jr7SpS5 jr8ShS6 jr9 SqS7 jr:SrS8 jr;\<S
4S9 jr=S\<S
4S: jr>\<S44S; jr?S\<S
4S< jr@SsS= jrASsS> jrBS? rC StS@ jrDSuSA jrESuSB jrFSC rGSD rHSuSE jrI\SF 5       rJ    SvSG jrK    SwSH jrLSiSI jrMSJ rNShSK jrOSSL.SxSM jjrP\SySN j5       rQSSL.SzSO jjrR\S{SP j5       rSSQ rTS|SR jrU\SS 5       rVST rWSU rX        S}                 S~SV jjrYSoSW jrZSX r[SiSY jr\SjSZ jr]SiS[ jr^S\ r_S] r`S^ raSS_ jrbS` rcSuSa jrdSjSb jreSjSc jrfSSd jrgSe rhSfrig
)AbstractFileSystema   z
An abstract super-class for pythonic file-systems

Implementations are expected to be compatible with or, better, subclass
from here.
TFi  @ /abstractzClassVar[str | tuple[str, ...]]protocolN r   ztuple[Any, ...]rD   dict[str, Any]rE   c                V   U R                   (       a  gSU l         SU l        SU l        / U l        [	        S0 UD6U l        UR                  SS5      (       a  [        R                  " S[        5        UR                  SS5      (       a  [        R                  " S[        5        SU l
        g)	a+  Create 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
NTFadd_docsz add_docs is no longer supported.add_aliaseszadd_aliases has been removed.r   )_cached_intrans_transaction"_invalidated_caches_in_transactionr   dircacher>   warningswarnFutureWarningrC   )selfr   rE   s      r   r&   AbstractFileSystem.__init__{   s    0 << 24/ 3?3z400MM<mL}d33MM9=Ir   c                    [         e)zRPersistent filesystem id that can be used to compare filesystems
across sessions.
NotImplementedErrorrg   s    r   fsidAbstractFileSystem.fsid   s
    
 "!r   c                    U R                   $ r   )rC   rl   s    r   	_fs_tokenAbstractFileSystem._fs_token   s    r   c                    U R                   $ r   )rp   rl   s    r   __dask_tokenize__$AbstractFileSystem.__dask_tokenize__   s    ~~r   c                .    [        U R                  S5      $ )N   )intrp   rl   s    r   __hash__AbstractFileSystem.__hash__   s    4>>2&&r   c                l    [        U[        U 5      5      =(       a    U R                  UR                  :H  $ r   )
isinstancetyperp   rg   others     r   __eq__AbstractFileSystem.__eq__   s%    %d,R5??1RRr   c                R    [         [        U 5      U R                  U R                  44$ r   )r   r|   rD   rE   rl   s    r   
__reduce__AbstractFileSystem.__reduce__   s$    tDz4+<+<d>R>RSSSr   c                   [        U[        5      (       a!  U Vs/ s H  o R                  U5      PM     sn$ [        U5      n[        U R                  [
        5      (       a  U R                  4OU R                  nU H[  nUR                  US-   5      (       a  U[        U5      S-   S nM/  UR                  US-   5      (       d  MJ  U[        U5      S-   S nM]     UR                  S5      nU=(       d    U R                  $ s  snf )z}Turn path from fully-qualified to file-system-specific

May require FS-specific handling, e.g., for relative paths or links.
://   Nz::   rW   )
r{   list_strip_protocolr   rY   str
startswithlenrstriproot_marker)r   pathpprotosrY   s        r   r   "AbstractFileSystem._strip_protocol   s     dD!!489Dq''*D99d#$.s||S$A$A#,,s||Hx%/00CMA-/0D11CMA-/0	 
 {{3&s& :s   Dc                    [        U R                  [        5      (       a  U R                  4OU R                  nU H   nUR                  U S35      (       d  M  Us  $    US    SU 3$ )z6Format FS-specific path to generic, including protocolr   r   )r{   rY   r   r   )rg   namer   rY   s       r   unstrip_protocol#AbstractFileSystem.unstrip_protocol   s`    %/s%C%C$--!H(3/00  )Cv&&r   c                    0 $ )a>  If 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   )r   s    r   _get_kwargs_from_urls(AbstractFileSystem._get_kwargs_from_urls   s	     	r   c                v    U R                   U R                  ;   a  U R                  U R                      $ U " 5       $ )zqReturn the most recently instantiated FileSystem

If no instance has been created, then create one with defaults
)rA   r*   r   s    r   currentAbstractFileSystem.current   s.     ;;#**$::ckk**ur   c                `    U R                   c  U R                  U 5      U l         U R                   $ )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.
)ra   transaction_typerl   s    r   transactionAbstractFileSystem.transaction   s/     $ $ 5 5d ;D   r   c                T    SU l         U R                  U 5      U l        U R                  $ )z@Begin write transaction for deferring files, non-context versionT)r`   r   ra   r   rl   s    r   start_transaction$AbstractFileSystem.start_transaction   s(     11$7r   c                    U R                   R                  5         SU l        U R                   H  nU R	                  U5        M     U R                  R                  5         g)z-Finish write transaction, non-context versionN)r   completera   rb   invalidate_cacher?   rg   r   s     r   end_transaction"AbstractFileSystem.end_transaction   sL    !!# ;;D!!$' <//557r   c                ^    U R                   (       a  U R                  R                  U5        gg)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`   rb   appendr   s     r   r   #AbstractFileSystem.invalidate_cache  s$     ==33::4@ r   c                    g)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.
Nr   rg   r   create_parentsr   s       r   mkdirAbstractFileSystem.mkdir  s      	r   c                    g)a2  Recursively 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
Nr   rg   r   exist_oks      r   makedirsAbstractFileSystem.makedirs*  s     	r   c                    g)zRemove a directory, if emptyNr   r   s     r   rmdirAbstractFileSystem.rmdir:      r   c                    [         e)a  List 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.
rj   rg   r   detailr   s       r   lsAbstractFileSystem.ls>  s    N "!r   c                   U R                  U5      n U R                  UR                  S5         $ ! [         a     Of = f U R                  U    Vs/ s H3  nUS   U:X  d%  US   UR                  S5      :X  d  M&  US   S:X  d  M1  UPM5     Os  snf nn[	        U5      S:X  a  [        U5      eU$ ! [         a     gf = f)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.
rW   r   r|   	directoryr   N)_parentrc   r   KeyErrorr   FileNotFoundError)rg   r   parentffiless        r   _ls_from_cache!AbstractFileSystem._ls_from_cacheg  s     d#	==S!122 			 v..AV9$fIS!11  78i;6N .E  5zQ'--L 		s6   1 
>>B1 %B<BB#B1 1
B>=B>c              +    #    Ub  US:  a  [        S5      eU R                  U5      n0 n0 n0 nUR                  SS5      n	 U R                  " U4SS0UD6n
U
 HS  nUS   R                  S	5      nUR                  S	S5      S
   nUS   S:X  a  X:w  a
  XU'   XU'   MD  X:X  a  XS'   MO  XU'   MU     U	(       d  [        U5      n[        U5      nU(       a  XU4v   Ub  US-  nUS:  a  U(       d  XU4v   gU H$  nU R                  " Xo   4UU	US.UD6 Sh  vN   M&     U(       d  XU4v   gg! [        [
        4 a)  nUS:X  a  e [        U5      (       a  U" U5         SnAgSnAff = f NS7f)a  Return all files under the given 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 callable
    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 1r   FTraiser   rW   r|   r   rZ   )maxdepthr   topdown)
ValueErrorr   r>   r   r   OSErrorcallabler   rsplitr   walk)rg   r   r   r   on_errorr   	full_dirsdirsr   r   listingeinfopathnamer   ds                   r   r   AbstractFileSystem.walk  s    B HqL:;;##D)	He,	ggd:4:6:G D F|**3/H??3*2.DF|{*x/?"*$!T
! b	"d  :DKEe##MH!|e++Ayy!	
     e## ] "7+ 	7"!!	Ls<   >E,D. C E,E*E,.E'>E"E,"E''E,c           	        U R                  U5      n0 nU(       a/  US:w  a)  U R                  U5      (       a  U R                  U5      Xa'   U R                  " X4SS0UD6 HV  u  pxn	U(       a  U	R	                  U5        UR	                  U	R                  5        V
Vs0 s H  u  pUS   U_M     snn
5        MX     U(       d  U R                  U5      (       a  0 Xa'   [        U5      nU(       d  U$ U V
s0 s H  oXj   _M	     sn
$ s  snn
f s  sn
f )ae  List all files below path.

Like posix ``find`` command without conditions

Parameters
----------
path : str
maxdepth: int or None
    If not None, the maximum number of levels to descend
withdirs: bool
    Whether to include directory paths in the output. This is True
    when used by glob, but users usually only want files.
kwargs are passed to ``ls``.
rZ   r   Tr   )r   isdirr   r   updateitemsisfilesorted)rg   r   r   withdirsr   r   out_r   r   r   r   namess                r   findAbstractFileSystem.find  s      ##D) 
tzz$'7'7		$CI"iiNtNvNNAUT"JJU[[]K]ztVd*]KL O t{{4(( CIsL056#)O66 L 7s   D2D	c                (   0 nU(       a1  U R                  U5      (       a  U R                  U5      nUS   XgS   '   U R                  " U4X4S.UD6 H  nU R                  U5      nUS   XgS   '   M      U(       a  [        UR	                  5       5      $ U$ )a  Space used by files and optionally directories within a path

Directory size does not include the size of its contents.

Parameters
----------
path: str
total: bool
    Whether to sum all the file sizes
maxdepth: int or None
    Maximum number of directory levels to descend, None for unlimited.
withdirs: bool
    Whether to include directory paths in the output.
kwargs: passed to ``find``

Returns
-------
Dict of {path: size} if total=False, or int otherwise, where numbers
refer to bytes used.
sizer   )r   r   )r   r   r   sumvalues)	rg   r   totalr   r   r   sizesr   r   s	            r   duAbstractFileSystem.du  s    * 

4((99T?D"&v,Ev,4P(PPA99Q<D"&v,Ev, Q u||~&&Lr   c                <   Ub  US:  a  [        S5      eSSKn[        R                  R                  (       a4  [        R                  R
                  [        R                  R                  4O[        R                  R
                  4nUR                  U5      nU R                  U5      nU=(       d!    UR                  [        S U 5       5      5      nUR                  S5      S:  a  UR                  S5      O
[        U5      nUR                  S5      S:  a  UR                  S5      O
[        U5      n	UR                  S5      S:  a  UR                  S5      O
[        U5      n
[        XU
5      nUR                  S	S
5      n[        U5      (       dA  U R                  " U40 UD6(       a  U(       d  U/$ XR                  " U40 UD60$ U(       d  / $ 0 $ SUSU ;   a6  USU R!                  S5      nUSUS-    nXS-   S R#                  S5      S-   nOSnXS-   S R#                  S5      S-   nSU;   a5  Ub0  UR                  S5      nXS R#                  S5      S-   nUU-
  U-   nOSnU R                  " U4USSS.UD6n[%        X(       a  SOS-   5      nUR'                  U5      n[)        UR+                  5       5       VVs0 s H6  u  nnUR-                  U(       a  US   S:X  a  US-   OU5      (       d  M3  UU_M8     nnnU(       a  U$ [/        U5      $ s  snnf )a  Find files by glob-matching.

Pattern matching capabilities for finding files that match the given pattern.

Parameters
----------
path: str
    The glob pattern to match against
maxdepth: int or None
    Maximum depth for '**' patterns. Applied on the first '**' found.
    Must be at least 1 if provided.
**kwargs:
    Additional arguments passed to ``find`` (e.g., detail=True)

Returns
-------
List of matched paths, or dict of paths and their info if detail=True

Notes
-----
Supported patterns:
- '*': Matches any sequence of characters within a single directory level
- '**': Matches any number of directory levels (must be an entire path component)
- '?': Matches exactly one character
- '[abc]': Matches any character in the set
- '[a-z]': Matches any character in the range
- '[!abc]': Matches any character NOT in the set

Special behaviors:
- If the path ends with '/', only folders are returned
- Consecutive '*' characters are compressed into a single '*'
- Empty brackets '[]' never match anything
- Negated empty brackets '[!]' match any single character
- Special characters in character classes are escaped properly

Limitations:
- '**' must be a complete path component (e.g., 'a/**/b', not 'a**b')
- No brace expansion ('{a,b}.txt')
- No extended glob patterns ('+(pattern)', '!(pattern)')
Nr	   r   r   c              3  *   #    U  H	  oS -   v   M     g7f)**Nr   )r4   seps     r   r6   *AbstractFileSystem.glob.<locals>.<genexpr>X  s     -*s   *?[r   FrW   rZ   r   Tr   r   r   r|   r   )r   rer+   r   altsepr   endswithr   r:   r   r   minr>   r   existsr   rindexcountr   compiler   r   matchr   )rg   r   r   r   r   sepsends_with_sepappend_slash_to_dirnameidx_star	idx_qmark	idx_bracemin_idxr   rootdepthidx_double_starsdepth_double_starsallpathspatternr   r   r   s                         r   globAbstractFileSystem.glob&  s   R HqL:;;02RWW^^,RWW[[Nd+##D)"/ #
4==---4
 &*YYs^q%8499S>c$i&*iin&9DIIcNs4y	&*iin&9DIIcNs4y	h95He,{{4*6* 6M ))D";F";<<IID'N"8Gn++C0G'A+&D1'--c2Q6ED1'--c2Q6E4<##'99T? %)*;%<%B%B3%G!%K" 22X=99TXEDXQWX 2!FG**W% "(.."23
34}}*tF|{/J C AtG3 	 
 J9
s   2L:Lc                :     U R                   " U40 UD6  g!    g= f)z!Is there a file at the given pathTFr   rg   r   r   s      r   r   AbstractFileSystem.exists  s%    	IId%f%	s    c                $    U R                  U5      $ )z=If there is a file at the given path (including
broken links))r   r  s      r   lexistsAbstractFileSystem.lexists  s     {{4  r   c                (   U R                  U5      nU R                  " U R                  U5      4SS0UD6nU Vs/ s H  oDS   R                  S5      U:X  d  M  UPM      nnU(       a  US   $ U R                  " U4SS0UD6nUR                  S5      nU Vs/ s H  oDS   R                  S5      U:X  d  M  UPM      nn[	        U5      S:X  a  SUS   ;  a  SUS   S'   US   $ [	        U5      S:  d  U(       a  USS	S
.$ [        U5      es  snf s  snf )a  Give details of entry at path

Returns a single dictionary, with exactly the same information as ``ls``
would with ``detail=True``.

The default implementation 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.
r   Tr   rW   r   r	   r   Nr   )r   r   r|   )r   r   r   r   r   r   )rg   r   r   r   oout1s         r   r   AbstractFileSystem.info  s   " ##D)ggdll4(@@@?#Q6!1!1#!6$!>q#?q6Mggd24262{{3@3aF)"2"23"74"?3@t9>T!W$"&Q7NY]c ![AA#D)) @
 As   D
D
D6Dc                J    [        [        U R                  U5      5      S5      $ )ar  Unique 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)
rv   )rw   r   r   r   s     r   checksumAbstractFileSystem.checksum  s     8DIIdO,b11r   c                D    U R                  U5      R                  SS5      $ )zSize in bytes of filer   N)r   r'   r   s     r   r   AbstractFileSystem.size  s    yy""6400r   c                N    U Vs/ s H  o R                  U5      PM     sn$ s  snf )z-Size in bytes of each file in a list of paths)r   )rg   pathsr   s      r   r   AbstractFileSystem.sizes  s     &+,e		!e,,,s   "c                R     U R                  U5      S   S:H  $ ! [         a     gf = f)zIs this entry directory-like?r|   r   F)r   r   r   s     r   r   AbstractFileSystem.isdir  s1    	99T?6*k99 		s    
&&c                @     U R                  U5      S   S:H  $ !    g= f)zIs this entry file-like?r|   fileFr  r   s     r   r   AbstractFileSystem.isfile  s)    	99T?6*f44	s    c                    U R                   " U4SUUUS.UD6 nUR                  5       sSSS5        $ ! , (       d  f       g= f)zGet the contents of the file as a string.

Parameters
----------
path: str
    URL of file on this filesystems
encoding, errors, newline: same as `open`.
rmodeencodingerrorsnewlineNopenread)rg   r   r0  r1  r2  r   r   s          r   	read_textAbstractFileSystem.read_text  sL     YY

 
 668
 
 
s	   3
Ac                    U R                   " U4SUUUS.UD6 nUR                  U5      sSSS5        $ ! , (       d  f       g= f)zWrite 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`.
wr.  N)r4  write)rg   r   valuer0  r1  r2  r   r   s           r   
write_textAbstractFileSystem.write_text  sN     YY

 
 775>
 
 
s	   4
Ac                   U R                   " US40 UD6 nUb@  US:  a  UR                  U5        O(UR                  [        SUR                  U-   5      5        Ub?  US:  a  UR                  U-   nUR	                  X5R                  5       -
  5      sSSS5        $ UR	                  5       sSSS5        $ ! , (       d  f       g= f)a   Get 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   )r4  seekmaxr   r5  tell)rg   r   startendr   r   s         r   cat_fileAbstractFileSystem.cat_file  s     YYtT,V, A:FF5MFF3q!&&5.127&&3,CvvcFFHn- -, 668 -,,s   A<B4B44
C	overwritec                    US:X  a  U R                  U5      (       a  [        eU R                  " US40 UD6 nUR                  U5        SSS5        g! , (       d  f       g= f)zSet the bytes of given filecreatewbN)r   FileExistsErrorr4  r:  )rg   r   r;  r/  r   r   s         r   	pipe_fileAbstractFileSystem.pipe_file)  sL    8D 1 1 "!YYtT,V,GGEN -,,s   A
A c                .   [        U[        5      (       a$  U R                  " U R                  U5      U40 UD6  g[        U[        5      (       a=  UR                  5        H(  u  pEU R                  " U R                  U5      U40 UD6  M*     g[        S5      e)aO  Put 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
zpath must be str or dictN)r{   r   rL  r   dictr   r   )rg   r   r;  r   kvs         r   pipeAbstractFileSystem.pipe2  sz     dC  NN4//5uGGd##

t33A6DVD % 788r   c                   Ub  [         e[        U[        5      (       d  [        e[        U[        5      (       d  U/[	        U5      -  n[        U[        5      (       d  U/[	        U5      -  n[	        U5      [	        U5      :w  d  [	        U5      [	        U5      :w  a  [
        e/ n[        XU5       H(  u  pn
 UR                  U R                  XU
5      5        M*     U$ ! [         a#  n
US:X  a  UR                  U
5         Sn
A
MU  e Sn
A
ff = f)a  Get 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.
Nreturn)
rk   r{   r   	TypeErrorr   r   zipr   rE  	Exception)rg   r%  startsendsmax_gapr   r   r   r   sr   s              r   
cat_rangesAbstractFileSystem.cat_rangesH  s     %%%&&O&$''XE
*F$%%6CJ&Dv;#e*$D	SZ(?5$/GA!

4==q12 0 
  x'JJqMM	s   8!C
D)DDDc                h   U R                  XS9n[        U5      S:  d-  [        U[        5      (       d  US   U R	                  U5      :w  a#  0 nU H  n U R
                  " U40 UD6Xa'   M     U$ U R
                  " US   40 UD6$ ! [         a"  nUS:X  a  e US:X  a
  XvU'    SnAMV   SnAM\  SnAff = f)a  Fetch (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	   r   r   rU  N)expand_pathr   r{   r   r   rE  rX  )rg   r   ra  r   r   r%  r   r   s           r   catAbstractFileSystem.catj  s    *    ;JN$%%Qx4//55C& $d =f =CI  J==q4V44 ! &7*8+$%D	 ,&s   B
B1B,,B1c                   SSK Jn  [        U5      (       a  UnO,U R                  U5      (       a  [        R
                  " USS9  gU" SS9nUR                  UR                  U5      SS9  U R                  " US40 UD6 nUc  [        US5      n UR                  [        US	S5      5        Sn	U	(       aT  UR                  U R                  5      n	UR                  U	5      n
U
c  [        U	5      n
UR                  U
5        U	(       a  MT  [        U5      (       d  UR                  5         SSS5        g! [        U5      (       d  UR                  5         f f = f! , (       d  f       g= f)
z Copy single remote file to localr	   )LocalFileSystemTr   N)
auto_mkdirr?  rJ  r   )implementations.localrf  r   r   r+   r   r   r4  set_sizer3   r5  	blocksizer:  r   relative_updateclose)rg   rpathlpathcallbackoutfiler   rf  fsf1datasegment_lens              r   get_fileAbstractFileSystem.get_file  s*   :eGZZKK--
BJJu%5YYud-f-ud+$!!'"fd";<774>>2D")--"5K"*&)$i,,[9 d "%((MMO .- "%((MMO ) .-s%   ?EA7D2	 E2#EE
E&c                   [        U[        5      (       a  [        U[        5      (       a  UnUnGODSSKJn	Jn
Jn  [        U[        5      nU R                  XUS9nU(       aJ  U(       a  Ub@  U Vs/ s H+  o" U5      (       a  M  U R                  U5      (       a  M)  UPM-     nnU(       d  g[        U[        5      (       a  U
" U5      n[        U5      S:H  n[        U[        5      =(       a%    U" U5      =(       d    U	" 5       R                  U5      nU=(       aH    [        U5      =(       a    U=(       d-    [        U5      (       + =(       a    U=(       a    U" U5      (       + n[        UUUU(       + S9nUR                  [        U5      5        UR                  [        X5      5       H4  u  p!UR                  X5       nU R                   " X4SU0UD6  SSS5        M6     gs  snf ! , (       d  f       MM  = f)a$  Copy 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	   rf  make_path_posixtrailing_sepra  r   Nr   flattenrp  )r{   r   ri  rf  rz  r{  r   rb  r   r   r   r   rj  wraprW  branchedrv  )rg   rn  ro  ra  rp  r   r   rpathslpathsrf  rz  r{  source_is_strr   source_is_filedest_is_dirr   childs                     r   r'   AbstractFileSystem.get  s   $ eT""z%'>'> FF  'uc2M%%e8%TFi83G%+VVLO!tzzRS}!VV%%%'. [A-N$UC0 U#E'8'>'>u'E  # 5!4n V!%((T[TeAT=T  !))	F 	#f+&$MM#f*=>LE""50EeEUEfE 10 ?1 W2 10s   0G"G"G"?G''
G6	c                   US:X  a  U R                  U5      (       a  [        e[        R                  R	                  U5      (       a  U R                  USS9  g[        US5       nUR                  SS5      nUR                  U5        UR                  S5        U R                  U R                  [        R                  " U5      5      SS9  U R                  " US40 UD6 nUR                  5       U:  aa  UR                  U R                  5      n	UR                  U	5      n
U
c  [!        U	5      n
UR#                  U
5        UR                  5       U:  a  Ma  SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)	zCopy single file to remoterI  Trg  Nr?  r   r   rJ  )r   rK  r+   r   r   r   r4  r@  rj  mkdirsr   fspathrB  r5  rk  r:  r   rl  )rg   ro  rn  rp  r/  r   rs  r   f2rt  ru  s              r   put_fileAbstractFileSystem.put_file  s*    8E 2 2!!77==MM%$M/%"771a=Dd#GGAJKKRYYu%56KF5$1&1Rggi$&774>>2D"$((4.K"*&)$i,,[9 ggi$& 2  21 s&   $A<E8 A4E'E8'
E5	1E88
Fc                r   [        U[        5      (       a  [        U[        5      (       a  UnUnGOSSKJn	Jn
Jn  [        U[        5      nU(       a  U
" U5      nU	" 5       nUR                  XUS9nU(       aJ  U(       a  Ub@  U Vs/ s H+  o" U5      (       a  M  UR                  U5      (       a  M)  UPM-     nnU(       d  g[        U5      S:H  n[        U[        5      =(       a     U" U5      =(       d    U R                  U5      n[        U[        5      (       a  U R                  U5      O U Vs/ s H  oR                  U5      PM     snnU=(       aH    [        U5      =(       a    U=(       d-    [        U5      (       + =(       a    U=(       a    U" U5      (       + n[        UUUU(       + S9nUR                  [        U5      5        UR                  [        X5      5       H4  u  pUR!                  X5       nU R"                  " X4SU0UD6  SSS5        M6     gs  snf s  snf ! , (       d  f       MR  = f)zCopy 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	   ry  r|  Nr}  rp  )r{   r   ri  rf  rz  r{  r   rb  r   r   r   r   r   rj  r  rW  r  r  )rg   ro  rn  ra  rp  r   r   r  r  rf  rz  r{  r  rr  r   r  r  r   r  s                      r   putAbstractFileSystem.put  s   " eT""z%'>'> FF  'uc2M'. "B^^E^RFi83G%+TVLO!rxxPQ{!VT [A-N$UC0 U#8tzz%'8  eS)) $$U+7<=u!**1-u= 
 # 5!4n V!%((T[TeAT=T  !))	F 	#f+&$MM#f*=>LE""50EeEUEfE 10 ?5 U > 10s$   HH2H1H":H''
H6	c                ~    U R                  US5       nUR                  U5      sSSS5        $ ! , (       d  f       g= f)z&Get the first ``size`` bytes from filer?  Nr3  rg   r   r   r   s       r   headAbstractFileSystem.headH  s)    YYtT"a66$< #""s   .
<c                    U R                  US5       nUR                  [        U* UR                  * 5      S5        UR	                  5       sSSS5        $ ! , (       d  f       g= f)z%Get the last ``size`` bytes from filer?  r   N)r4  r@  rA  r   r5  r  s       r   tailAbstractFileSystem.tailM  sD    YYtT"aFF3uqvvg&*668 #""s   8A
A#c                    [         er   rj   rg   path1path2r   s       r   cp_fileAbstractFileSystem.cp_fileS  s    !!r   c                R   Uc
  U(       a  SnOUc  Sn[        U[        5      (       a  [        U[        5      (       a  UnUnGOSSKJn	  [        U[        5      n
U R                  XUS9nU
(       aJ  U(       a  Ub@  U Vs/ s H+  o" U5      (       a  M  U R                  U5      (       a  M)  UPM-     nnU(       d  g[        U5      S:H  n[        U[        5      =(       a     U	" U5      =(       d    U R                  U5      nU
=(       aH    [        U5      =(       a    U=(       d-    [        U5      (       + =(       a    U=(       a    U	" U5      (       + n[        UUUU
(       + S9n[        Xx5       H  u  nn U R                  " UU40 UD6  M     gs  snf ! [         a    US:X  a  e  M9  f = f)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
Nignorer   r	   )r{  r|  r}  )r{   r   ri  r{  r   rb  r   r   r   r   rW  r  r   )rg   r  r  ra  r   r   r   paths1paths2r{  r  r   r  r  r   p1p2s                    r   copyAbstractFileSystem.copyV  s    	HHeT""z%'>'> FF;&uc2M%%e8%TFi83G%+VVLO!tzzRS}!VV [A-N$UC0 U#8tzz%'8  # 5!4n V!%((T[TeAT=T  !))	F &)FBR.v. *) W. % w& 's$   >FF*F3FF&%F&c           
        Ub  US:  a  [        S5      e[        U[        [        R                  45      (       a  U R                  U/X#5      nGO[        5       nU Vs/ s H  o`R                  U5      PM     nnU H  n[        U5      (       ai  [        U R                  " U4SU0UD65      nXW-  nU(       a>  Ub  US::  a  MG  U[        U R
                  " [        U5      4UUb  US-
  OSS.UD65      -  nM|  U(       a$  [        U R                  " U4USSS.UD65      nXX-  nXe;  d  M  USL d  U R                  U5      (       d  M  UR                  U5        M     U(       d  [        U5      e[        U5      $ s  snf )	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	   r   r   r|  TFr   )r   r{   r   r+   PathLikerb  setr   r   r  r   r   r   addr   r   )	rg   r   ra  r   r   r   r   bitrecs	            r   rb  AbstractFileSystem.expand_path  s}    HqL:;;dS"++.//""D69?C%C59:T((+TD:Q<<diiGHGGHCJC  $/HM$s ,, $S	*39A9MASW #)	   		(04QWC
 JC<Y%%74;;q>>GGAJ9 : #D))c{A ;s   E8c                |    X:X  a  [         R                  SU 5        gU R                  XX4SS9  U R                  XS9  g)z)Move file(s) from one location to anotherz6%s mv: The paths are the same, so no files were moved.r   )ra  r   onerrorr`  N)loggerdebugr  rm)rg   r  r  ra  r   r   s         r   mvAbstractFileSystem.mv  sA    >LLQSWX II	g   GGEG/r   c                &    U R                  U5        g)zDelete a fileN)_rmr   s     r   rm_fileAbstractFileSystem.rm_file  s    r   c                    [         e)zDelete one filerj   r   s     r   r  AbstractFileSystem._rm  s
     "!r   c                j    U R                  XUS9n[        U5       H  nU R                  U5        M     g)as  Delete 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.
r|  N)rb  reversedr  )rg   r   ra  r   r   s        r   r  AbstractFileSystem.rm  s2     HM$ALLO  r   c                    U R                  U5      nSU;   a=  UR                  SS5      S   R                  U R                  5      nU R                  U-   $ U R                  $ )NrW   r	   r   )r   r   lstripr   )r   r   r   s      r   r   AbstractFileSystem._parent  sV    ""4($;[[a(+223??CF??V++??"r   c                &    [        U UUUU4SU0UD6$ )z4Return raw bytes-mode file-like from the file-systemcache_options)AbstractBufferedFile)rg   r   r/  
block_size
autocommitr  r   s          r   _openAbstractFileSystem._open  s4     $
 (
 
 	
r   c           	     0   SSK nU R                  U5      nSU;  af  UR                  SS5      S-   nS Vs0 s H  nX;   d  M
  XR                  U5      _M     n	nUR                  " U R
                  " UU4UUUS.UD640 U	D6$ UR                  SU R                  (       + 5      n
U R                  " U4UUU
US	.UD6nUb!  SS
KJ	n  SSK
Jn  U" X5      nX   nU" XS   S9nU
(       d+  SU;  a%  U R                  R                  R                  U5        U$ s  snf )a[  
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()``
    Mode "x" (exclusive write) may be implemented by the backend. Even if
    it is, whether  it is checked up front or on commit, and whether it is
    atomic is implementation-dependent.
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
r   NbtrZ   )r0  r1  r2  )r  r  compressionr  )r/  r  r  r  )compr)get_compression)r/  r-  )ior   replacer>   TextIOWrapperr4  r`   r  fsspec.compressionr  fsspec.corer  r   r   r   )rg   r   r/  r  r  r  r   r  rP  text_kwargsacr   r  r  compresss                  r   r4  AbstractFileSystem.open   sT   D 	##D)d?<<R(3.D ;:A; !::a= :  
 ##		  *"/ + 
 
 
 Ldmm*;<B

%+ A &47-d@ -Q!W-#T/  &&--a0HIs   	DDc                    U(       d  U R                  U5      (       d  U R                  " US40 UD6    SSS5        g[        e! , (       d  f       g= f)zCreate empty file, or update timestamp

Parameters
----------
path: str
    file location
truncate: bool
    If True, always set file size to 0; if False, update timestamp and
    leave file unchanged, if backend allows this
rJ  N)r   r4  rk   )rg   r   truncater   s       r   touchAbstractFileSystem.touchN  sD     4;;t,,400 10 &% 10s   A
Ac                    [        [        U R                  U5      5      R                  5       5      R	                  5       $ )z2Hash of file properties, to tell if it has changed)r   r   r   encode	hexdigestr   s     r   ukeyAbstractFileSystem.ukey_  s,    c$))D/*1134>>@@r   c                    U R                  US5       nUR                  nUc  UnUb  X#-   U:  a  Xb-
  n[        XRX45      sSSS5        $ ! , (       d  f       g= f)a2  Read 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`
r?  N)r4  r   r   )rg   fnoffsetlength	delimiterr   r   s          r   r   AbstractFileSystem.read_blockc  sT    J YYr4 A66D~FOd$:a; !  s   ,A		
A)include_passwordc          	     T    SSK Jn  [         R                  " U [        SU4SU05      S9$ )az  
JSON representation of this filesystem instance.

Parameters
----------
include_password: bool, default True
    Whether to include the password (if any) in the output.

Returns
-------
JSON string with keys ``cls`` (the python location of this class),
protocol (text name of this class's protocol, first one in case of
multiple), ``args`` (positional args, usually empty), and all other
keyword arguments as their own keys.

Warnings
--------
Serialized filesystems may contain sensitive information which have been
passed to the constructor, such as passwords and tokens. Make sure you
store and send them in a secure environment!
r	   FilesystemJSONEncoder_FilesystemJSONEncoderr  r   )jsonr  dumpsr|   )rg   r  r  s      r   to_jsonAbstractFileSystem.to_json  s5    , 	0zz(&(#%56
 	
r   c                6    SSK Jn  [         R                  " XS9$ )a  
Recreate a filesystem instance from JSON representation.

See ``.to_json()`` for the expected structure of the input.

Parameters
----------
blob: str

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	   FilesystemJSONDecoderr   )r  r  loads)blobr  s     r   	from_jsonAbstractFileSystem.from_json  s    * 	0zz$::r   c          	        SSK Jn  U" 5       n[        U 5      nU R                  n[	        U R
                  5      nU(       d  UR                  SS5        [	        SUR                   SUR                   3[        U[        [        45      (       a  US   OUUR                  U R                  5      S.UR                  U5      D6$ )	a  
JSON-serializable dictionary representation of this filesystem instance.

Parameters
----------
include_password: bool, default True
    Whether to include the password (if any) in the output.

Returns
-------
Dictionary with keys ``cls`` (the python location of this class),
protocol (text name of this class's protocol, first one in case of
multiple), ``args`` (positional args, usually empty), and all other
keyword arguments as their own keys.

Warnings
--------
Serialized filesystems may contain sensitive information which have been
passed to the constructor, such as passwords and tokens. Make sure you
store and send them in a secure environment!
r	   r  passwordN:r   )r   rY   r   r   )r  r  r|   rY   rO  rE   r>   rN   rM   r{   r:   r   make_serializablerD   )rg   r  r  json_encoderr   protorE   s          r   to_dictAbstractFileSystem.to_dict  s    , 	0,.4jt334
D1 
>>"!CLL>2!+EE4=!A!AU1Xu//0A0AB
 ,,_=	
 	
r   c                $   SSK Jn  U" 5       n[        U 5      n UR                  U 5      nUc  [	        S5      eU R                  SS5        U R                  SS5        U" UR                  U R                  SS5      5      0 UR                  U 5      D6$ )	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	   r  Nz#Not a serialized AbstractFileSystemr   rY   r   r   )r  r  rO  try_resolve_fs_clsr   r>   unmake_serializable)dctr  json_decoderr   s       r   	from_dictAbstractFileSystem.from_dict  s    * 	0,.3i#66s;;BCCt
D!--cggfb.AB
..s3
 	
r   c                    U $ )zG
Make a version of the FS instance which will be acceptable to pyarrow
r   rl   s    r   _get_pyarrow_filesystem*AbstractFileSystem._get_pyarrow_filesystem  s	    
 r   c                "    SSK Jn  U" UU UUUS9$ )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)checkrI  missing_exceptions)mappingr  )rg   r  r	  rI  r
  r  s         r   
get_mapperAbstractFileSystem.get_mapper   s#     	#1
 	
r   c                8    U R                   R                  5         g)al  
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?   r   s    r   clear_instance_cache'AbstractFileSystem.clear_instance_cache0  s     	

r   c                    [         e)z=Return the created timestamp of a file as a datetime.datetimerj   r   s     r   createdAbstractFileSystem.created?      !!r   c                    [         e)z>Return the modified timestamp of a file as a datetime.datetimerj   r   s     r   modifiedAbstractFileSystem.modifiedC  r  r   c	                   S#S jn	/ n
U(       a  U
R                  U5        U(       Ga  SU-  nU R                  USS9nUR                  S S9  Ub#  [        U5      U:  a  USU n[        U5      U-
  nOUnSn[	        U5       GH  u  nnU[        U5      S	-
  :H  =(       a    US:H  nU(       a  S
SUS-
  -  -   O
SSUS-
  -  -   nUS-  nUU(       a  UO
SSUS	-
  -  -   -   n[
        R                  R                  UR                  SS5      5      nU(       a  UR                  S5      S:X  a  U R                  UR                  SS5      SS9n[        S U 5       5      n[        S U 5       5      nUS:X  a	  US:X  a  SnOUS:X  a  SU SUS	:  a  SOS S3nOsUS:X  a  SU SUS	:  a  SOS S3nO[SU SUS	:  a  SOS SU SUS	:  a  SOS S3	nO;U(       a2  UR                  S5      S:X  a  SU	" UR                  SS5      5       S3nOSnU
R                  U U U U 35        UR                  S5      S:X  d  GM  US:  d  GM  U
R                  U R                  UR                  SS5      US	-
  UUUUSUS95        GM     US:  a&  U S 3nU
R                  U S
SUS-
  -  -    SU 35        S!R                  S" U
 5       5      $ )$ai  
Return a tree-like structure of the filesystem starting from the given path as a string.

Parameters
----------
    path: Root path to start traversal from
    recursion_limit: Maximum depth of directory traversal
    max_display: Maximum number of items to display per directory
    display_size: Whether to display file sizes
    prefix: Current line prefix for visual tree structure
    is_last: Whether current item is last in its level
    first: Whether this is the first call (displays root path)
    indent_size: Number of spaces by indent

Returns
-------
    str: A string representing the tree structure.

Example
-------
    >>> from fsspec import filesystem

    >>> fs = filesystem('ftp', host='test.rebex.net', user='demo', password='password')
    >>> tree = fs.tree(display_size=True, recursion_limit=3, indent_size=8, max_display=10)
    >>> print(tree)
c                N    S H  u  pU SU-  :  d  M  X-  S SU S3s  $    U  S3$ )zFormat bytes as text.))Pl           )Tl        )Gi   @)Mi   )rP     g?z.2f r  Br   )nprefixrP  s      r   format_bytes-AbstractFileSystem.tree.<locals>.format_bytesm  sA    	 a<eC[&33 S7Nr   r  T)r   c                N    U R                  S5      S:g  U R                  SS5      4$ )Nr|   r   r   rZ   r'   )xs    r   <lambda>)AbstractFileSystem.tree.<locals>.<lambda>  s!    quuV};QUU62=NOr   )keyNr   r	   u   └u   ─r   u   ├u   │r   rZ   r|   r   c              3  R   #    U  H  oR                  S 5      S:X  d  M  Sv   M     g7f)r|   r*  r	   Nr&  r4   sub_items     r   r6   *AbstractFileSystem.tree.<locals>.<genexpr>  s$      $*6h,,v:NRX:X,s   '	'c              3  T   #    U  H  nUR                  S 5      S:X  d  M  Sv   M      g7f)r|   r   r	   Nr&  r,  s     r   r6   r.    s*      &(4H#<</;> (4s   (	(z (empty folder)z (z
 subfolderr\  )z file, r*  r   F)r   recursion_limitmax_displaydisplay_sizer"  is_lastfirstindent_sizez more item(s) not displayed.
c              3  6   #    U  H  o(       d  M  Uv   M     g 7fr   r   )r4   r   s     r   r6   r.    s     0FqaFs   
	)r!  rw   rU  r   )r   r   sortr   	enumerater+   r   basenamer'   r   treejoin)rg   r   r2  r3  r4  r"  r5  r6  r7  r#  resultindentcontentsdisplayed_contentsremaining_countiitemis_last_itembranch
new_prefixr   sub_contents	num_filesnum_foldersr   more_messages                             r   r=  AbstractFileSystem.treeG  s`   L	 MM$;&FwwtDw1HMMO   &3x=;+F%-l{%;""%h-+"=%-""#$%784 !S);%<q%@ @  #q(  $ UkAo67%;?";< 
 ##*F{Q8O0O
 ww''(<=DHHV$4$C#'77488FB+?7#ML # $*6$ !I #& &(4& #K !A~+*:0"a!#K=
+PQ/3WY:ZZ[\$)!#I;e9q=Cb3QQRS!#I;e9q=Cb3QQST_S``jr}  AB  sBkn  HJ  kK  KL   M!dhhv&6&&@TXXfa-@ AB!DDDtf=>88F#{27JMM		!%&"!5,;a,?(3)5#-$0"'(3 " 	Y 9r ""1!22NOhuq(ABC1\NS yy0F000r   c                ,    U R                   " U4X#S.UD6$ )z'Alias of `AbstractFileSystem.cat_file`.rC  rD  )rE  )rg   r   rC  rD  r   s        r   
read_bytesAbstractFileSystem.read_bytes  s    }}TBB6BBr   c                *    U R                   " X40 UD6  g)z(Alias of `AbstractFileSystem.pipe_file`.N)rL  )rg   r   r;  r   s       r   write_bytesAbstractFileSystem.write_bytes  s    t-f-r   c                ,    U R                   " U4SU0UD6$ )z$Alias of `AbstractFileSystem.mkdir`.r   )r   r   s       r   makedirAbstractFileSystem.makedir  s    zz$H~HHHr   c                     U R                  XS9$ )z'Alias of `AbstractFileSystem.makedirs`.rg  )r   r   s      r   r  AbstractFileSystem.mkdirs  s    }}T}55r   c                ,    U R                   " U4SU0UD6$ )z!Alias of `AbstractFileSystem.ls`.r   )r   r   s       r   listdirAbstractFileSystem.listdir  s    wwt5F5f55r   c                (    U R                   " X40 UD6$ )z#Alias of `AbstractFileSystem.copy`.)r  r  s       r   cpAbstractFileSystem.cp  s    yy000r   c                (    U R                   " X40 UD6$ z!Alias of `AbstractFileSystem.mv`.r  r  s       r   moveAbstractFileSystem.move      wwu.v..r   c                (    U R                   " U40 UD6$ )z#Alias of `AbstractFileSystem.info`.r  r  s      r   statAbstractFileSystem.stat  s    yy(((r   c                ,    U R                   " U4X#S.UD6$ )z!Alias of `AbstractFileSystem.du`.)r   r   )r   )rg   r   r   r   r   s        r   
disk_usageAbstractFileSystem.disk_usage  s    wwtF5FvFFr   c                (    U R                   " X40 UD6$ ra  rb  r  s       r   renameAbstractFileSystem.rename  re  r   c                "    U R                  XUS9$ )z!Alias of `AbstractFileSystem.rm`.r|  )r  )rg   r   ra  r   s       r   deleteAbstractFileSystem.delete  s    wwt8wDDr   c                ,    U R                   " X4SU0UD6$ )z"Alias of `AbstractFileSystem.put`.ra  )r  )rg   ro  rn  ra  r   s        r   uploadAbstractFileSystem.upload      xxD	DVDDr   c                ,    U R                   " X4SU0UD6$ )z"Alias of `AbstractFileSystem.get`.ra  r&  )rg   rn  ro  ra  r   s        r   downloadAbstractFileSystem.download  ru  r   c                    [        S5      e)a  Create 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 filesystemrj   )rg   r   
expirationr   s       r   signAbstractFileSystem.sign  s    , ""OPPr   c                    g)NFr   rl   s    r   _isfilestoreAbstractFileSystem._isfilestore  s    
 r   )r_   rC   r`   rb   ra   rc   )r   r   rU  r   r   )TF)NTomit)NFF)TNF)NNN)NN)rG  )NrU  )Fr   )r  )FNN)FN)r?  NTN)r?  NNN)r  boolrU  r   )r  r   rU  rU   )r  r  rU  r[   )r   r[   rU  rU   )rZ   FFN)rW   r      FrZ   TT   )r   r   r2  rw   r3  rw   r4  r  r"  r   r5  r  r6  r  r7  rw   rU  r   )TN)d   )jrM   rN   rO   rP   rQ   r@   r_   rk  r   rY   __annotations__rA   rF   r9   r   r   r   r;   r&   propertyrm   rp   rs   rx   r   r   classmethodr   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r   r   r   r   r   r   r6  r<  rE  rL  rR  r]  rc  r
   rv  r'   r  r  r  r  r  r  rb  r  r  r  r  r   r  r4  r  r  r   r  r  r  r  r  r  r  r  r  r=  rP  rS  rV  r  r[  r^  rc  rg  rj  rm  rp  rs  rw  r{  r~  rR   r   r   r   rU   rU   a   s    HGI
C0:H-:GJK" "$ "!##'R " "  'ST ' '$' 
 
   ! ! 8A"$ '"R2\$|$7L DiV!
 *D21-( @D"229. ;C D&5P /? $D !<F~ &6K:8 !@FD 
" FJ4l.`	0"
& # # 
. L\&"A+<Z 37 
B ; ;0 37 &
P $
 $
L
   ""  "E1E1 E1 	E1
 E1 E1 E1 E1 E1 
E1TC.I661/)G/EEEQ0r   rU   )	metaclassc                  t   \ rS rSrSrSrSr      S)S jr\S 5       r	\	R                  S 5       r	\S 5       r\S	 5       r\R                  S
 5       rS rS rS rS rS rS rS*S jrS rS+S jrS+S jrS rS rS,S jrS rS-S jrS rS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S% r'\'r(S& r)S' r*S(r+g).r  i%  a+  Convenient class to derive from to provide buffering

In the case that the backend does not provide a pythonic file-like object
already, this class contains much of the logic to build one. The only
methods that need to be overridden are ``_upload_chunk``,
``_initiate_upload`` and ``_fetch_range``.
i  P Nc	                T   SSK Jn
  X l        Xl        X0l        US;   a  U R
                  OUU l        SU l        XPl        SU l	        SU l
        SU l        Uc  0 nSU	;   a/  [        R                  " S[        5        U	R                  S5      US'   Xl        US	;  a  [#        S
5      eUS:X  aO  Ub  Xl        OU R&                  S   U l        X   " U R                  U R(                  U R$                  40 UD6U l        g[,        R.                  " 5       U l        SU l        SU l        SU l        g)a_  
Template for files with buffered reading and writing

Parameters
----------
fs: instance of FileSystem
path: str
    location in file-system
mode: str
    Normal file modes. Currently only 'wb', 'ab' or 'rb'. Some file
    systems may be read-only, and some may not support append.
block_size: int
    Buffer size for reading or writing, 'default' for class default
autocommit: bool
    Whether to write to final destination; may only impact what
    happens when file is being closed.
cache_type: {"readahead", "none", "mmap", "bytes"}, default "readahead"
    Caching policy in read mode. See the definitions in ``core``.
cache_options : dict
    Additional options passed to the constructor for the cache specified
    by `cache_type`.
size: int
    If given and in read mode, suppressed having to look up the file size
kwargs:
    Gets stored as self.kwargs
r	   )caches)defaultNr   NFtrimzyPassing 'trim' to control the cache behavior has been deprecated. Specify it within the 'cache_options' argument instead.>   abr?  rJ  xbzFile mode not supportedr?  r   )corer  r   rr  r/  DEFAULT_BLOCK_SIZErk  locr  rD  rC  closedrd   re   rf   r>   r   rk   r   details_fetch_rangecacher  BytesIObufferr  forcedlocation)rg   rr  r   r/  r  r  
cache_typer  r   r   r  s              r   r&   AbstractBufferedFile.__init__1  s   L 	!		'15F'FD##J 	 $
 MVMMJ
 %+JJv$6M&!//%&?@@4< 	 LL0	+ 1 1499@MDJ **,DKDKDK DMr   c                    U R                   c*  U R                  R                  U R                  5      U l         U R                   $ r   )_detailsrr  r   r   rl   s    r   r  AbstractBufferedFile.details  s.    ==  GGLL3DM}}r   c                $    Xl         US   U l        g )Nr   )r  r   )rg   r;  s     r   r  r    s    &M	r   c                B    [        U R                  U R                  5      $ r   )r   r   rr  rl   s    r   	full_nameAbstractBufferedFile.full_name  s     DGG44r   c                    [        U SS5      $ )N_closedTr2   rl   s    r   r  AbstractBufferedFile.closed  s     tY--r   c                    Xl         g r   )r  )rg   cs     r   r  r    s    r   c                v    SU R                   ;   a  [        U 5      $ [        [        U R                  5      S5      $ )Nr9  rv   )r/  idrw   r   r  rl   s    r   rx   AbstractBufferedFile.__hash__  s-    $))d8Ox-r22r   c                    XL a  g[        U[        U 5      5      =(       aC    U R                  S:H  =(       a-    UR                  S:H  =(       a    [        U 5      [        U5      :H  $ )zAFiles are equal if they have the same checksum, only in read modeTr?  )r{   r|   r/  hashr}   s     r   r   AbstractBufferedFile.__eq__  sV    =ud4j) *		T!*

d"* T
d5k)		
r   c                    g)z#Move from temp to final destinationNr   rl   s    r   commitAbstractBufferedFile.commit      r   c                    g)zThrow away temporary fileNr   rl   s    r   discardAbstractBufferedFile.discard  r  r   c                Z    U R                  5       (       a  U R                  $ [        S5      e)z File information about this pathz Info not available while writing)readabler  r   rl   s    r   r   AbstractBufferedFile.info  s#    ==??<<?@@r   c                    U R                   $ )zCurrent file location)r  rl   s    r   rB  AbstractBufferedFile.tell  s    xxr   c                &   [        U5      nU R                  S:X  d  [        [        S5      eUS:X  a  UnO;US:X  a  U R                  U-   nO%US:X  a  U R
                  U-   nO[        SU S35      eUS:  a  [        S5      eX0l        U R                  $ )	zSet current file location

Parameters
----------
loc: int
    byte location
whence: {0, 1, 2}
    from start of file, current location or end of file, resp.
r?  z Seek only available in read moder   r	   r   zinvalid whence (z, should be 0, 1 or 2)zSeek before start of file)rw   r/  r   r   r  r   r   )rg   r  whencenlocs       r   r@  AbstractBufferedFile.seek  s     #hyyD &"DEEQ;Dq[88c>Dq[99s?D/x7MNOO!8899xxr   c                   U R                  5       (       d  [        S5      eU R                  (       a  [        S5      eU R                  (       a  [        S5      eU R                  R                  U5      nU =R                  U-  sl        U R                  R                  5       U R                  :  a  U R                  5         U$ )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.
zFile not in write modeI/O operation on closed file.z0This file has been force-flushed, can only close)
writabler   r  r  r  r:  r  rB  rk  flush)rg   rt  r   s      r   r:  AbstractBufferedFile.write  s     }}566;;<==;;OPPkk%C;;/JJL
r   c                F   U R                   (       a  [        S5      eU(       a  U R                  (       a  [        S5      eU(       a  SU l        U R                  5       (       a  gU(       d)  U R                  R                  5       U R                  :  a  gU R                  c  SU l         U R                  5         U R                  US9SLaJ  U =R                  U R                  R                  SS5      -  sl        [        R                  " 5       U l        gg!   SU l         e = f)	a3  
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.
zFlush on closed filez+Force flush cannot be called more than onceTNr   )finalFr   )r  r   r  r  r  rB  rk  r  _initiate_upload_upload_chunkr@  r  r  )rg   forces     r   r  AbstractBufferedFile.flush  s     ;;344T[[JKKDK==??))+dnn<;;DK%%'
 E*%7KK4;;++Aq11K**,DK 8	"s   )D 
D c                    g)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   )rg   r  s     r   r  "AbstractBufferedFile._upload_chunk  r  r   c                    g)zCreate remote file/uploadNr   rl   s    r   r  %AbstractBufferedFile._initiate_upload$  r   r   c                J    U R                   R                  U R                  XS9$ )z*Get the specified set of bytes from remoterO  )rr  rE  r   )rg   rC  rD  s      r   r  !AbstractBufferedFile._fetch_range(  s     ww		@@r   c                   Uc  SO
[        U5      nU R                  S:w  a  [        S5      eUS:  a  U R                  U R                  -
  nU R
                  (       a  [        S5      eUS:X  a  gU R                  R                  U R                  U R                  U-   5      n[        R                  SU U R                  U R                  U-   U R                  R                  5       5        U =R                  [        U5      -  sl        U$ )z
Return data from cache, or fetch pieces as necessary

Parameters
----------
length: int (-1)
    Number of bytes to read; if <0, all remaining bytes.
r   r?  zFile not in read moder   r  r   z%s read: %i - %i %s)rw   r/  r   r   r  r  r  _fetchr  r  
_log_statsr   )rg   r  r   s      r   r5  AbstractBufferedFile.read,  s     ~3v;99455A:YY)F;;<==Q;jj$((V*;<!HHHHvJJ!!#	
 	CH
r   c                    [        U5      R                  S5      nU R                  UR                  5      nX2S[	        U5      & [	        U5      $ )zhmirrors builtin file's readinto method

https://docs.python.org/3/library/io.html#io.RawIOBase.readinto
r   N)
memoryviewcastr5  nbytesr   )rg   r  r   rt  s       r   readintoAbstractBufferedFile.readintoK  sB    
 m  %yy$Kc$i4yr   c                   / n U R                  5       nU R                  U=(       d    U R                  5      n[        U5      S:X  a  OjUR	                  U5      nUS:  a@  UR                  USU[        U5      -    5        U R                  XF-   [        U5      -   5        OUR                  U5        M  SR                  U5      $ )aK  Return 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.
r   r   Nr   )rB  r5  rk  r   r   r   r@  r>  )rg   charblocksr   rC  partfounds          r   	readuntilAbstractBufferedFile.readuntilU  s     IIKE99V5t~~6D4yA~IIdOErz

4 3%#d)"345		%-#d)34JJt  xx}r   c                $    U R                  S5      $ )zRead until and including the first occurrence of newline character

Note that, because of character encoding, this is not necessarily a
true line ending.
   
)r  rl   s    r   readlineAbstractBufferedFile.readlineq  s     ~~e$$r   c                @    U R                  5       nU(       a  U$ [        er   )r  StopIteration)rg   r   s     r   __next__AbstractBufferedFile.__next__y  s    mmoJr   c                    U $ r   r   rl   s    r   __iter__AbstractBufferedFile.__iter__      r   c                    U R                  5       nUR                  S5      nUSS  Vs/ s H  o3S-   PM	     nnUR                  S5      (       a  U$ XBS   /-   $ s  snf )zPReturn all data, split by the newline character, including the newline characterr  Nr   )r5  splitr   )rg   rt  lineslr   s        r   	readlinesAbstractBufferedFile.readlines  s_    yy{

5!"'*-*Q5y*-==J)$$	 .s   Ac                $    U R                  U5      $ r   )r  )rg   r  s     r   	readinto1AbstractBufferedFile.readinto1  s    }}Qr   c                   [        U SS5      (       a  gU R                  (       a  g U R                  S:X  a  SU l        OU R                  (       d  U R                  SS9  U R                  bc  U R                  R                  U R                  5        U R                  R                  U R                  R                  U R                  5      5        SU l        g! SU l        f = f)z-Close file

Finalizes writes, discards cache
_unclosableFNr?  T)r  )
r3   r  r/  r  r  r  rr  r   r   r   rl   s    r   rm  AbstractBufferedFile.close  s    
 4..;;	yyD !
{{JJTJ*77&GG,,TYY7GG,,TWW__TYY-GHDK$DKs   B(C 	C c                P    SU R                   ;   =(       a    U R                  (       + $ )zWhether opened for readingr-  r/  r  rl   s    r   r  AbstractBufferedFile.readable  s    dii3O3r   c                "    U R                  5       $ )z'Whether is seekable (only in read mode))r  rl   s    r   seekableAbstractBufferedFile.seekable  s    }}r   c                P    U R                   S;   =(       a    U R                  (       + $ )zWhether opened for writing>   r  rJ  r  r  rl   s    r   r  AbstractBufferedFile.writable  s    yy..Bt{{?Br   c           
     H   U R                   S:w  a  [        S5      e[        U R                  U R                  U R                   U R
                  U R                  U R                  U R                  U R                  (       a  U R                  R                  OSU R                  4	4$ )Nr?  z*Pickling a writeable file is not supportednone)r/  RuntimeErrorreopenrr  r   rk  r  r   r  r  r   r   rl   s    r   r   AbstractBufferedFile.__reduce__  sw    99KLLGGIIIINNHHIIOO#zzDJJOOvKK

 

 
	
r   c                H    U R                   (       d  U R                  5         g g r   )r  rm  rl   s    r   __del__AbstractBufferedFile.__del__  s    {{JJL r   c                b    S[        U R                  5      R                   SU R                   S3$ )Nz<File-like object r1  >)r|   rr  rM   r   rl   s    r   __str__AbstractBufferedFile.__str__  s*    #DM$:$:#;2dii[JJr   c                    U $ r   r   rl   s    r   	__enter__AbstractBufferedFile.__enter__  r  r   c                $    U R                  5         g r   )rm  )rg   r   s     r   __exit__AbstractBufferedFile.__exit__  s    

r   )r  r  r  rk  r  r  r  rD  r  rr  r   r  r  r/  r  r   r   rC  )r?  r  T	readaheadNN)r   r  )r   )r  N),rM   rN   rO   rP   rQ   r  r  r&   r  r  setterr  r  rx   r   r  r  r   rB  r@  r:  r  r  r  r  r5  r  r  r  r  r  r  r  rm  r  r  r  r   r	  r  __repr__r  r  rR   r   r   r   r  r  %  s8    #H O!b  
 ^^" " 5 5 . .
 ]] 3	
2(A40('TA>8%% ,4C
 K Hr   r  c	           	     f    U R                   " U4UUUUUS.UD6n	US:  a  U	R                  U5        U	$ )N)r/  r  r  r  r   r   )r4  r@  )
rr  r   r/  rk  r  r   r  r  r   r*  s
             r   r  r    sJ    77 D Qw		#Kr   ),
__future__r   r  r  loggingr+   r<   rd   r(   errnor   r  r   hashlibr   typingr   r   	callbacksr
   configr   r   rc   r   r   r   utilsr   r   r   r   r   r   r   	getLoggerr  r   r|   r!   rU   IOBaser  r  r   r   r   <module>r#     s    " 	   	         ' &  $   
		8	$ :d :zA7 AH6j299 jZr   