
    qi              
       ^   U d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d dlmZmZ d d	lmZmZmZmZmZmZ d d
lmZmZ d dlZd dlZd dlm Z m!Z!m"Z" d dl#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@  ej                  dej                        ZCe G d d             ZDe G d deD             ZEe G d deD             ZF eGej                        ZIeeJd<    G d deI      ZK G d d ej                  eK!      ZL G d" d#ej                  j                        ZO G d$ d%ej                  j                        ZPd&eQd'eQfd(ZRd)eQd'eQfd*ZSd+eQd,eeT   d'efd-ZUd.eLd+eQd/eQd0eVd1eQf
d2ZWd3 ZX eL       ZYy)4    N)deque)	ExitStack)deepcopy)	dataclassfield)datetime)chain)PathPurePosixPath)AnyIterableIteratorNoReturnOptionalUnion)quoteunquote)_DEFAULT_CALLBACKNoOpCallbackTqdmCallback)
isfilelike   )	constants)CommitOperationCopyCommitOperationDelete)BucketNotFoundErrorEntryNotFoundErrorHfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError)
hf_hub_urlhttp_get)
BucketFileBucketFolderHfApiLastCommitInfoRepoFile
RepoFolder)HFValidationErrorhf_raise_for_statushttp_backoffhttp_stream_backoff)md5zy
    (^refs\/convert\/\w+)     # `refs/convert/parquet` revisions
    |
    (^refs\/pr\/\d+)          # PR revisions
    c                   2    e Zd ZU dZeed<   eed<   defdZy)HfFileSystemResolvedPathz_Top level Data structure containing information about a resolved Hugging Face file system path.rootpathreturnc                 V    | j                    d| j                   j                  d      S )N/)r0   r1   rstripselfs    P/opt/pipecat/venv/lib/python3.12/site-packages/huggingface_hub/hf_file_system.py	unresolvez"HfFileSystemResolvedPath.unresolve5   s&    ))Adii[)0055    N)__name__
__module____qualname____doc__str__annotations__r9    r:   r8   r/   r/   .   s    i
I
I63 6r:   r/   c                       e Zd ZU dZeed<   eed<   eed<   eed<    ed      Zeed<    ed      Zeed	<    ed
d      Z	e
e   ed<   d Zy
)"HfFileSystemResolvedRepositoryPathzLData structure containing information about a resolved path in a repository.	repo_typerepo_idrevisionpath_in_repoFinitr0   r1   N)defaultrepr_raw_revisionc                 b   t         j                  j                  | j                  d      | j                  z   }| j
                  r| d| j
                   | _        nD| j                  t         j                  k7  r | dt        | j                         | _        n|| _        | j                  | _        y )N @)r   REPO_TYPES_URL_PREFIXESgetrD   rE   rL   r0   rF   DEFAULT_REVISIONsafe_revisionrG   r1   )r7   	repo_paths     r8   __post_init__z0HfFileSystemResolvedRepositoryPath.__post_init__G   s    5599$.."MPTP\P\\	$+Qt'9'9&:;DI]]i888$+Q}T]]'C&DEDI!DI%%	r:   )r;   r<   r=   r>   r?   r@   r   r0   r1   rL   r   rU   rA   r:   r8   rC   rC   9   sT    VNLM5!D#!5!D#! $)E#BM8C=B&r:   rC   c                   >    e Zd ZU dZeed<    ed      Zeed<   d Zy)HfFileSystemResolvedBucketPathzHData structure containing information about a resolved path in a bucket.	bucket_idFrH   r0   c                 ,    d| j                   z   | _        y )Nzbuckets/)rX   r0   r6   s    r8   rU   z,HfFileSystemResolvedBucketPath.__post_init__Y   s    /	r:   N)	r;   r<   r=   r>   r?   r@   r   r0   rU   rA   r:   r8   rW   rW   R   s    RN5!D#!0r:   rW   _cached_basec                   (     e Zd ZdZ fdZd Z xZS )_Cacheda  
    Metaclass for caching HfFileSystem instances according to the args.

    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.

    This is a slightly modified version of `fsspec.spec._Cached` to improve it.
    In particular in `_tokenize` the pid isn't taken into account for the
    `fs_token` used to identify cached instances. The `fs_token` logic is also
    robust to defaults values and the order of the args. Finally new instances
    reuse the states from sister instances in the main thread.
    c                 2    t        |   |i | i | _        y N)super__init___cache)clsargskwargs	__class__s      r8   r`   z_Cached.__init__q   s    $)&) 
r:   c                    |j                  dd      } | j                  | t        j                         g|i |} | j                  | t        j                         j
                  g|i |}|s0| j                  r$|| j                  v r|| _        | j                  |   S t        j                  | g|i |}|s\| j                  rP|| j                  v rB| j                  |   j                         }|j                         D ]  \  }}	t        |||	        ||_        ||_        ||_        | j                  r|s|| _        || j                  |<   |S )Nskip_instance_cacheF)pop	_tokenize	threading	get_identmain_threadidentcachablera   _latesttype__call___get_instance_stateitemssetattr
_fs_token_storage_argsstorage_options)
rb   rc   rd   skipfs_tokenfs_token_main_threadobjinstance_stateattrstate_values
             r8   rq   z_Cached.__call__y   s:   zz/7 3==i&9&9&;MdMfM,s}}S)2G2G2I2O2OaRVaZ`aSZZ)?"CK::h'' --5d5f5CCLL-ASZZ-O!$,@!A!U!U!W)7)=)=)? 4%D+C{34%CN#C"(C||D&'*

8$Jr:   )r;   r<   r=   r>   r`   rq   __classcell__re   s   @r8   r\   r\   a   s    r:   r\   c                       e Zd ZdZdZdZddddddee   dee	edf   dee
   d	ee	   f fd
Zede
defd       Zdededee   dee	ee   f   fdZdedee	ee   f   fdZ	 d6dedee   deeef   fdZd6dee   ddfdZ	 	 	 d7dededee
   dee   ded   f
dZd6dedee   ddfdZ	 	 	 d8dede	dee
   dee   ddf
dZ	 d9dede	de	dee   deeeeeef   f      f
d Z	 	 	 	 	 d:dede	de	dee   d	ee	   dee
   fd!Zded"ede	deeee f      fd#Z!dede"eeee   ee   f      f fd$Z#d6dedee
   dee   f fd%Z$	 	 	 	 	 d;dedee
   d&e	de	de	dee   deee   eeeeef   f   f   fd'Z%d6d(ed)edee   ddfd*Z&dede'fd+Z(d<dede	dee   deeef   fd,Z)d- Z*d. Z+d/ Z,dedefd0Z-e.dfd= fd1Z/e0d2        Z1d3 Z2d4 Z3d5 Z4 xZ5S )>HfFileSystemaz
  
    Access a remote Hugging Face Hub repository as if were a local file system.

    > [!WARNING]
    > [`HfFileSystem`] provides fsspec compatibility, which is useful for libraries that require it (e.g., reading
    >     Hugging Face datasets directly with `pandas`). However, it introduces additional overhead due to this compatibility
    >     layer. For better performance and reliability, it's recommended to use `HfApi` methods when possible.

    The file system supports paths for the `hf://` protocol, which follows those URL schemes:

    * Models, Datasets and Spaces repositories:

        ```
        hf://<repo-id>[@<revision>]/<path/in/repo>
        hf://datasets/<repo-id>[@<revision>]/<path/in/repo>
        hf://spaces/<repo-id>[@<revision>]/<path/in/repo>
        ```

    * Buckets (generic storage):

        ```
        hf://buckets/<bucket-id>/<path/in/bucket>
        ```

    Note: when using the [`HfFileSystem`] directly, passing the `hf://` protocol prefix is optional in paths.

    Args:
        endpoint (`str`, *optional*):
                Endpoint of the Hub. Defaults to <https://huggingface.co>.
        token (`bool` or `str`, *optional*):
            A valid user access token (string). Defaults to the locally saved
            token, which is the recommended method for authentication (see
            https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
            To disable authentication, pass `False`.
        block_size (`int`, *optional*):
            Block size for reading and writing files.
        expand_info (`bool`, *optional*):
            Whether to expand the information of the files.
        **storage_options (`dict`, *optional*):
            Additional options for the filesystem. See [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.__init__).

    Usage:

    ```python
    >>> from huggingface_hub import hffs

    >>> # List files
    >>> hffs.glob("my-username/my-model/*.bin")
    ['my-username/my-model/pytorch_model.bin']
    >>> hffs.ls("datasets/my-username/my-dataset", detail=False)
    ['datasets/my-username/my-dataset/.gitattributes', 'datasets/my-username/my-dataset/README.md', 'datasets/my-username/my-dataset/data.json']

    >>> # Read/write files
    >>> with hffs.open("my-username/my-model/pytorch_model.bin") as f:
    ...     data = f.read()
    >>> with hffs.open("my-username/my-model/pytorch_model.bin", "wb") as f:
    ...     f.write(data)
    ```

    Specify a token for authentication:
    ```python
    >>> from huggingface_hub import HfFileSystem
    >>> hffs = HfFileSystem(token=token)
    ```
    rN   hfN)endpointtoken
block_sizeexpand_infor   r   r   r   c                    t        |   |i | |xs t        j                  | _        || _        t        ||      | _        || _        || _	        i | _
        i | _        i | _        y )N)r   r   )r_   r`   r   ENDPOINTr   r   r%   _apir   r   _repo_and_revision_exists_cache_bucket_exists_cachedircache)r7   r   r   r   r   rc   rw   re   s          r8   r`   zHfFileSystem.__init__   so     	$2/2 6I$6$6
859	$&  	, RT! :<r:   threading_identr2   c                 (   |j                  d      xs t        j                  |d<   |j                  d      |d<   t        |      D ci c]  }|||   
 }}| |||f}t	        t        |      j                               }|j                         S c c}w )zDeterministic token for cachingr   r   )rQ   r   r   sortedr-   r?   encode	hexdigest)rb   r   rc   rd   keytokenize_argshs          r8   ri   zHfFileSystem._tokenize   s     $ZZ
3Iy7I7Iz **W-w.4Vn=s#vc{"==otV<M"))+,{{}	 >s   BrD   rE   rF   c                    |||f| j                   vrR	 | j                  j                  |||t        j                         d| j                   |||f<   d| j                   ||d f<   | j                   |||f   S # t
        t        f$ r2}d|f| j                   |||f<   d|f| j                   ||d f<   Y d }~Nd }~wt        $ r0}d|f| j                   |||f<   d| j                   ||d f<   Y d }~d }~ww xY w)N)rF   rD   timeoutTNF)r   r   	repo_infor   HF_HUB_ETAG_TIMEOUTr   r)   r    )r7   rD   rE   rF   es        r8   _repo_and_revision_existz%HfFileSystem._repo_and_revision_exist   s!    w)1U1UU^		##h)YMjMj $  Xb44i(5STS]44i$5OP33Y4RSS ,->? \W\^_W_44i(5STSXZ[S[44i$5OP( ^W\^_W_44i(5STS]44i$5OP^s#   -A6 6C.(B22C.>&C))C.rX   c                     || j                   vr+	 | j                  j                  |       d| j                   |<   | j                   |   S # t        $ r}d|f| j                   |<   Y d }~.d }~ww xY w)Nr   F)r   r   bucket_infor   )r7   rX   r   s      r8   _bucket_existszHfFileSystem._bucket_exists  st    D555B		%%i0 8B)))4((33	 ' @7<ax)))4@s   A	 		A-A((A-r1   c                 p   dt         t           dt         t           dt         t           fd}| j                  |      }|st        d      |j	                  d      d   dk(  rudj                  |j	                  d      d	d
       }dj                  |j	                  d      d
d       }| j                  |      \  }}|st        ||       t        ||      S |j	                  d      d   dz   t        j                  j                         v r8d|vrt        d      |j	                  dd	      \  }}t        j                  |   }nt        j                  }|j                  d      dkD  rddj                  |j	                  d      dd       v r|j	                  dd	      \  }}	d|	v rwt        j!                  |	      }
|
J|d|
j#                         fv r6t        j%                  d|	      j'                  d      }|
j#                         }	n|	j	                  dd	      \  }	}nd} |t)        |	      |      }| j+                  |||      \  }}|sJt        ||       n<d}	dj                  |j	                  d      dd       }dj                  |j	                  d      dd       }|j	                  d      d   }dj                  |j	                  d      d	d       }|}|}| j+                  |||      \  }}|st-        |t.        t0        f      r)|}|}| j+                  |||      \  }}|sot        ||       nbt        ||       nU|}d}d|v r(|j	                  dd	      \  }}	 |t)        |	      |      }nd}	| j+                  |||      \  }}|st        d      ||nt        j2                  }t5        |||||	      S )a  
        Resolve a Hugging Face file system path into its components.

        Args:
            path (`str`):
                Path to resolve.
            revision (`str`, *optional*):
                The revision of the repo to resolve. Defaults to the revision specified in the path.

        Returns:
            [`HfFileSystemResolvedPath`]: Resolved path information containing `repo_type`, `repo_id`, `revision` and `path_in_repo`.

        Raises:
            `ValueError`:
                If path contains conflicting revision information.
            `NotImplementedError`:
                If trying to list repositories.
        revision_in_pathrF   r2   c                 D    || | |k7  rt        d|  d| d      |S | }|S )NzRevision specified in path ("z ") and in `revision` argument ("z") are not the same.)
ValueError)r   rF   s     r8   %_align_revision_in_path_with_revisionzHHfFileSystem.resolve_path.<locals>._align_revision_in_path_with_revision3  sU     ##/4D4P$78H7IIijris t- -  O ,Or:   z<Access to buckets and repositories lists is not implemented.r4   r   bucketsr      N)rX   r1   z0Access to repositories lists is not implemented.rO      rN   )rL   )r   r?   _strip_protocolNotImplementedErrorsplitjoinr   _raise_file_not_foundrW   r   rP   valuesREPO_TYPES_MAPPINGREPO_TYPE_MODELcountSPECIAL_REFS_REVISION_REGEXsearchgroupsublstripr   r   
isinstancer   r)   rR   rC   )r7   r1   rF   r   rX   bucket_existserrrD   rE   r   matchrG   repo_and_revision_existrepo_id_with_namespacepath_in_repo_with_namespacerepo_id_without_namespacepath_in_repo_without_namespace_s                     r8   resolve_pathzHfFileSystem.resolve_path  s   ,	&sm	7?}	c]	 ##D)%&deeZZ_Q9,C1!56I88DJJsOAB/0D!%!4!4Y!?M3 %dC01IDQQZZ_Q#%)J)J)Q)Q)SS$)*\]]"jja0OIt!44Y?I!11I::c?Qchhtzz#r233,0JJsA,>))**7>>?OPE(X$9N-N'B'F'FrK['\'c'cdg'h+0;;=(9I9O9OPSUV9W6(,#%L@IYAZ\de/3/L/LYX_ai/j,'.)$4#' ),$**S/"12E)F&.1hhtzz#qr7J.K+,0JJsOA,>)14$**S/!":M1N.0:/3/L/LYX_ai/j,'.!#(?AR'ST";'E595R5RS\^ego5p2/61$<-dC8GLd{,0JJsA,>))@IYAZ\de#' )-)F)FyRY[c)d&#Q*)*\]]'389S9S1w,FV
 	
r:   c                    |s5| j                   j                          | j                  j                          y| j                  |      }|j	                         }|r0| j                   j                  |d       | j                  |      }|r0|j                  st        |t              rq| j                  j                  |j                  |j                  dfd       | j                  j                  |j                  |j                  |j                  fd       y| j                  j                  |j                  d       yy)ac  
        Clear the cache for a given path.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.invalidate_cache).

        Args:
            path (`str`, *optional*):
                Path to clear from cache. If not provided, clear the entire cache.

        N)r   clearr   r   r9   rh   _parentr1   r   rC   rD   rE   rF   r   rX   )r7   r1   resolved_paths      r8   invalidate_cachezHfFileSystem.invalidate_cache  s    MM!00668 --d3M **,D!!$-||D) 
 !%%m-OP88<<&00-2G2GNPT 88<<&00-2G2GI_I_`bf --11-2I2I4P &r:   mode)HfFileSystemFileHfFileSystemStreamFilec                     ||n| j                   }|||d<   d|v rt        d      |dk(  rt        | |f||d|S t        | |f||d|S )Nr   az/Appending to remote files is not yet supported.r   )r   rF   )r   r   r   r   )r7   r1   r   r   rF   rd   s         r8   _openzHfFileSystem._open  sr     $.#9Zt
!#-F< $;%&WXX?)$]4(]V\]]#D$WTHWPVWWr:   c                    | j                  ||      }t        |t              r3| j                  j	                  |j
                  |j                  g       nr| j                  j                  |j                  |j                  | j                  |j                  |j                  |j                  d      |j                  d             | j                  |j                                y )NrF   deletecommit_messagecommit_description)rG   rE   r   rD   rF   r   r   r1   )r   r   rW   r   batch_bucket_filesrX   r1   delete_filerG   rE   r   rD   rF   rQ   r   r9   )r7   r1   rF   rd   r   s        r8   _rmzHfFileSystem._rm  s    ))$)Bm%CDII(()@)@-J\J\I](^II!!*77%--jj'11&//%zz*:;#)::.B#C "  	=#:#:#<=r:   	recursivemaxdepthc                 F   | j                  ||      }| j                  ||||      }t        |t              rb|D cg c]/  }| j	                  |      r| j                  |      j
                  1 }}| j                  j                  |j                  |       n|D cg c]/  }| j	                  |      r| j                  |      j
                  1 }	}|	D 
cg c]  }
t        |
       }}
d d}||rdndz  }||d
| dndz  }| j                  j                  |j                  |j                  | j                  ||j                  |j                  d|      |j                  d             | j!                  |j#                                y	c c}w c c}w c c}
w )a  
        Delete files from a repository.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.rm).

        > [!WARNING]
        > Note: When possible, use `HfApi.delete_file()` for better performance.

        Args:
            path (`str`):
                Path to delete.
            recursive (`bool`, *optional*):
                If True, delete directory and all its contents. Defaults to False.
            maxdepth (`int`, *optional*):
                Maximum number of subdirectories to visit when deleting recursively.
            revision (`str`, *optional*):
                The git revision to delete from.

        r   )r   r   rF   r   )rG   zDelete  zrecursively rN   Nzup to depth r   r   )rE   rD   r   
operationsrF   r   r   r   )r   expand_pathr   rW   isdirr1   r   r   rX   r   create_commitrE   rD   r   rF   rQ   r   r9   )r7   r1   r   r   rF   rd   r   pathsr   paths_in_reporG   r   r   s                r8   rmzHfFileSystem.rm  s   6 ))$)B  XX` am%CD?D]tDJJW[L\d''-22]F]II(()@)@(PFKddSWS]S]^bScT..t499dMd_lm|/\JmJm&tfA.N	nrANH<PXJa8VXXNII##%--'11jj%&//%zz*:NK#)::.B#C $  	=#:#:#<=% ^ ems   FFF6FFdetailrefreshc                    | j                  ||      }|j                         }	  | j                  |f||d|}|r|S |D cg c]  }|d   	 c}S # t        $ rx |j                  st        |d        | j                  | j                  |      f||d|}|D cg c]  }|d   |k(  s| nc c}w }}t        |      dk(  rt        |d       Y w xY wc c}w )a  
        List the contents of a directory.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.ls).

        > [!WARNING]
        > Note: When possible, use `HfApi.list_repo_tree()` for better performance.

        Args:
            path (`str`):
                Path to the directory.
            detail (`bool`, *optional*):
                If True, returns a list of dictionaries containing file information. If False,
                returns a list of file paths. Defaults to True.
            refresh (`bool`, *optional*):
                If True, bypass the cache and fetch the latest data. Defaults to False.
            revision (`str`, *optional*):
                The git revision to list from.

        Returns:
            `list[Union[str, dict[str, Any]]]`: List of file paths (if detail=False) or list of file information
            dictionaries (if detail=True).
        r   )r   rF   Nnamer   )r   r9   _ls_treer   r1   r   r   len)	r7   r1   r   r   rF   rd   r   outos	            r8   lszHfFileSystem.ls  s    4 ))$)B&&(		2$--SgSFSC s:c":1V9":: " 	2 %%%dD1$--T 2aGhaZ`aC!7QvY$%6177C73x1}%dD1	2 #;s*   A CA
CB/*B/."CCc           
      	   ||n| j                   | j                   nd}| j                  ||      }|j                         }|j                  }|r|nd}g }	|| j                  v rh|se| j                  |   }
|	j                  |
       g }|rd}t        |
D cg c]  }|d   dk(  s||f c}      }|r|j                         \  }}|||k  ru|d   | j                  vr|j                  |d          nO| j                  |d      }
|	j                  |
       |j                  |
D cg c]  }|d   dk(  r|dz   |f c}       |rg }|r7t        |t              r'|	D cg c]  }|d   	| j                  |d          }}|r|s|rC|r@t        j                  j                  ||z         }|j                  d	      s||k(  s|t!        ||      v r|j#                  d	      n| j                  |      }|"|t%        |      d  j'                  d	      }||z  }|	D cg c]  }|d   j)                  |d	z         r| }	}t+        | j                        D ]3  }|j)                  |d	z         s| j                  j-                  |d        5 | j                  j-                  |d        |	j                  | j/                  ||d
|||             |	S t        |t0              r)| j3                  |j4                  |j                  |      }nI| j6                  j9                  |j:                  |j                  |||j<                  |j>                        }|D ]c  }|d	z   |j                  z   }t        |t@              rH||jB                  d|jD                  |jF                  |jH                  |jJ                  |jL                  d}nt        |tN              r2||jB                  d|jH                  |jP                  |jR                  d}n>t        |tT              r|dd|jV                  |jJ                  d}n|dd|jR                  d}| j                  |d         }| j                  jY                  |g       j                  |       |t%        |      d  j'                  d	      }|||k  sS|	j                  |       f |	S c c}w c c}w c c}w c c}w )NFr   r   r   rp   	directoryr   last_commitr4   T)r   r   rF   r   r   )prefixr   )r   expandrF   rD   filer   sizerp   blob_idlfsxet_hashr   security)r   r   rp   r   mtimeuploaded_atr   r   r   rp   tree_idr   )r   r   rp   r   )-r   r   r9   r0   r   extendr   popleftappendr   rC   r   osr1   commonprefixendswithr	   r5   r   r   
startswithlistrh   r   rW   _list_bucket_tree_with_foldersrX   r   list_repo_treerE   rF   rD   r'   r   r   r   r   r   r   r#   r   r   r(   r   
setdefault)r7   r1   r   r   rF   r   r   r   	root_pathr   cached_path_infosdirs_not_in_dircachedepth	path_infodirs_to_visitdir_infodirs_not_expandedr   common_prefixcommon_pathcommon_path_depthcached_pathtree
cache_pathcache_path_infoparent_paths                             r8   r   zHfFileSystem._ls_tree$  s    '2KTM]M]Mi9I9Iot 	 ))$)B&&(!&&	(8a4==  $d 3JJ()#%   %9JoIiX^N_cnNneY'o! $&3&;&;&=OE8'5H+<#F+4==@0778HI04hv>N0O-JJ'89)00 6G!"(1'0'8K'G &+QY	$:!" $  !#z-9[\FI$fQ}M]MeT\\!F)%<$f!$f2HY !# 4 45IL]5] ^ %--c2$	1$.BDU(VV "((- m4  '(3CIK(@(F(Fs(K% 11H"%UQQvY-A-A+PSBS-TqUU#'#6 =K"--kC.?@))+t<= !!+t4

MM#"+ $!)$/!) " 	J 
s -)GH::!++(--' ;  yy//!))!&&'&*33+55 0  " )0	&_y~~=
i2 * ) &#,#4#4(}}$-$6$6'0'<'<$-$6$6	'O  	:6 * ) &$-$6$6!*'0'<'<'O  	:6 * ! +#,#4#4'0'<'<'O !+ ! +'0'<'<	'O #ll?6+BC((b9@@Q"3t9;/55c:#u'8JJ/S)0T 
a p!" %g" Vs*   R:%R:&R?
S)SS	8S	r   c                    | j                   j                  |||      }i }|rd|j                  d      z   nd}g }|D ]  }|j                  |       |st	        t        |j                        j                        d| dz
   D ]  }	t        dt        |	      |j                        }
|
j                  |vr!|j                  |
       |
||
j                  <   S|
j                  `||
j                     }|j                  |j                  |
j                  k  s|
j                  |_
          |st        d| d	| d
      |S )z<Same as `HfApi.list_bucket_tree` but always includes folders)r   r   r4   r   Nr   )rp   r1   r   zFile not found in bucket 'z': '')r   list_bucket_treer   r   r  r   r1   parentsr$   r?   r   r   )r7   rX   r   r   bucket_filesbucket_folders	min_depthr   bucket_entryparent_bucket_folder_strparent_bucket_folderbucket_folders               r8   r  z+HfFileSystem._list_bucket_tree_with_folders  sg    yy11)Vy1Y24-3AS))	57( 	ULJJ|$  -1|?P?P1Q1Y1Y,Z[k^g]gjk]k,l U('3$3/G+HVbVnVn($
 (,,NBJJ34@TN#7#<#<= (33?$23G3L3L$MM$008%114H4T4TT4H4T4T1#U	U6 $'A)DQWPXXY%Z[[
r:   c              /      K   | j                  ||j                  d            j                         }t        |   |g|i |E d{    y7 w)a  
        Return all files below the given path.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.walk).

        Args:
            path (`str`):
                Root path to list files from.

        Returns:
            `Iterator[tuple[str, list[str], list[str]]]`: An iterator of (path, list of directory names, list of file names) tuples.
        rF   r   N)r   rQ   r9   r_   walk)r7   r1   rc   rd   re   s       r8   r!  zHfFileSystem.walk  sL        

:0F GQQS7<6t6v666s   AA
AAc                     | j                  ||j                  d            j                         }t        |   |fd|i|S )ah  
        Find files by glob-matching.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.glob).

        Args:
            path (`str`):
                Path pattern to match.

        Returns:
            `list[str]`: List of paths matching the pattern.
        rF   r   r   )r   rQ   r9   r_   glob)r7   r1   r   rd   re   s       r8   r#  zHfFileSystem.glob  sE       

:0F GQQSw|D>8>v>>r:   withdirsc                 *   ||dk  rt        d      | j                  ||      }|j                         }	  | j                  |fd||d|}	|s|	D 
cg c]  }
|
d   dk7  s|
 }	}
n# | j                  |fi |}|d   dk(  r|g|	z   n|	}	|	D 
ci c]  }
|
d   |

 }	}
t        |	      }|s|S |D ci c]  }||	|   
 c}S c c}
w c c}
w # t
        $ r8 	  | j                  |fd	|i|d   d
k(  r|i i}	ni }	n# t        $ r i }	Y nw xY wY mw xY wc c}w )a  
        List all files below path.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.find).

        Args:
            path (`str`):
                Root path to list files from.
            maxdepth (`int`, *optional*):
                Maximum depth to descend into subdirectories.
            withdirs (`bool`, *optional*):
                Include directory paths in the output. Defaults to False.
            detail (`bool`, *optional*):
                If True, returns a dict mapping paths to file information. Defaults to False.
            refresh (`bool`, *optional*):
                If True, bypass the cache and fetch the latest data. Defaults to False.
            revision (`str`, *optional*):
                The git revision to list from.

        Returns:
            `Union[list[str], dict[str, dict[str, Any]]]`: List of paths or dict of file information.
        r   zmaxdepth must be at least 1r   T)r   r   r   rp   r   r   rF   r   )r   r   r9   r   infor   FileNotFoundErrorr   )r7   r1   r   r$  r   r   rF   rd   r   r   r   r	  namesr   s                 r8   findzHfFileSystem.find  sh   @ HqL:;;))$)B&&(	.$--cgPXc\bcC "%BQ6k)AqBB &DIId5f5	+4V+<+KykC'QT),-A1V9a<-C-sL056D#d)O66 C
 .! " 	499T?H??G6Q*CC$ 	* 7sM   C C"CC2D	D"C98D9DDDDDpath1path2c                 6   | j                  ||      }| j                  ||      }t        |t              st        |t              rt        d      |j                  |j                  k(  xr |j
                  |j
                  k(  }|rd| d| }| j                  j                  |j
                  |j                  |j                  |j                  d|      |j                  dd      t        |j                  |j                  |j                        g	       n| j                  |d
|j                        5 }	|	j                         }
ddd       d| d| }| j                  j                  
|j                  |j
                  | j                  |j                  |j                  |j                  d|      |j                  d             | j!                  |j#                                | j!                  |j#                                y# 1 sw Y   xY w)a  
        Copy a file within or between repositories.

        > [!WARNING]
        > Note: When possible, use `HfApi.upload_file()` for better performance.

        Args:
            path1 (`str`):
                Source path to copy from.
            path2 (`str`):
                Destination path to copy to.
            revision (`str`, *optional*):
                The git revision to copy from.

        r   z)Copy from/to buckets is not available yetzCopy z to r   r   rN   )src_path_in_reporG   src_revision)rE   rD   rF   r   r   r   rbNpath_or_fileobjrG   rE   r   rD   rF   r   r   r   )r   r   rW   r   rD   rE   r   r   rF   rQ   r   rG   openreadupload_filer   r   r9   )r7   r*  r+  rF   rd   resolved_path1resolved_path2	same_repor   fcontents              r8   cp_filezHfFileSystem.cp_file6  s     **58*D**58*Dn&DE:J
 &&QRR $$(@(@@u^E[E[_m_u_uEu 	 $UG4w7NII##&..(22'00%zz*:NK#)::.BB#G')7)D)D%3%@%@%3%<%< $  5$1H1HI #Q&&(#$UG4w7NII!! '+88&..jj(22'00%zz*:NK#)::.B#C " 	 	>#;#;#=>>#;#;#=># #s   9HHc                      | j                   |fi i |ddi}d|v r#|d   t        d| d      |d   j                  S d|v r
|d   r|d   S d|v r
|d   r|d   S t        d| d	| d
      )ak  
        Get the last modified time of a file.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.modified).

        Args:
            path (`str`):
                Path to the file.

        Returns:
            `datetime`: Last modified time of the file.
        r   Tr   z9'modified' is not implemented for repository paths like 'r  r   r   z'Cannot determined 'modified' for path 'z	' (info: ))r&  r   date)r7   r1   rd   r&  s       r8   modifiedzHfFileSystem.modifiedr  s     tyyA!@F!@M4!@AD M"*),efjekkl*mnn&+++_g= d"tM':&&%(OPTvU^_c^dde&fggr:   c           	         | j                  ||      }|j                         }|j                  d| j                  | j                  nd      }|j                  s|ddd}t        |t              rd|d<   t        |t              r|r| j                  j                  |j                  |j                  |j                  	      d
   }i |dt        |j                  |j                  |j                        d}nBt        |t               r^| j#                  |      }	| j%                  |	|       | j&                  |	   D 
cg c]  }
|
d   |k(  s|
 }}
|st)        |d       |d   }nd}| j#                  |      }	|s|	| j&                  vr| j%                  |	       |	| j&                  v r8| j&                  |	   D 
cg c]  }
|
d   |k(  s|
 }}
|st)        |d       |d   }|s||rS|rP|d   J| j                  j+                  |j                  |j,                  ||j                  |j                        }|st)        |d       |d   }t        |j                  |j                  |j                  d|j.                        j                         }t        |t0              rX|dz   |j                  z   |j2                  d|j4                  |j6                  |j8                  |j:                  |j<                  d}n,|dz   |j                  z   dd|j>                  |j:                  d}|sdD ci c]  }|||   
 }}|J |S c c}
w c c}
w c c}w )aS  
        Get information about a file or directory.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.info).

        > [!WARNING]
        > Note: When possible, use `HfApi.get_paths_info()` or `HfApi.repo_info()`  for better performance
        > (or `HfApi.get_bucket_paths_info()` or `HfApi.bucket_info()` for buckets)

        Args:
            path (`str`):
                Path to get info for.
            refresh (`bool`, *optional*):
                If True, bypass the cache and fetch the latest data. Defaults to False.
            revision (`str`, *optional*):
                The git revision to get info from.

        Returns:
            `dict[str, Any]`: Dictionary containing file information (type, size, commit info, etc.).

        r   r   NFr   r   )r   r   rp   r   )rD   rF   )oidtitler=  )r   r   )r   r   )r   rF   rD   rN   )rG   rL   r4   r   r   r   ) r   r9   rQ   r   r1   r   rC   r   list_repo_commitsrE   rD   rF   r&   	commit_idrB  
created_atrW   r   r   r   r   get_paths_inforG   rL   r'   r   r   r   r   r   r   r   )r7   r1   r   rF   rd   r   r   r   r   r  r   out1
paths_infor	  r  ks                   r8   r&  zHfFileSystem.info  sX   , ))$)B&&(jjt/?/?/K4++QV
 !! #C
 -)KL%)M"-)KLQ\"ii99!))]5L5LWdWmWm : ##1'119J9JQ\QgQg$ 'EF,,t,KGGKG1#}}[9O!QvY$=NAODO%dD1q'CC,,t,K;dmm#C$dmm+#'==#=Sa6dARSS)$51g#++##mBTB\!YY55!))!..&*33+55 6 
 ")$5&qM	>!++!))!**!#"/"="= )+  i2 )C).. @ ) &#,#4#4(}}$-$6$6'0'<'<$-$6$6	C !*C).. @ ! +#,#4#4'0'<'<C #.FG1c!f9GCG
q P TT Hs   MM>M
M
0Mc                     	 |j                  dd      r| j                  |        | j                  |fi | y#  Y yxY w)a  
        Check if a file exists.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.exists).

        > [!WARNING]
        > Note: When possible, use `HfApi.file_exists()` for better performance.

        Args:
            path (`str`):
                Path to check.

        Returns:
            `bool`: True if file exists, False otherwise.
        r   FT)rQ   r   r&  )r7   r1   rd   s      r8   existszHfFileSystem.exists  sC     	zz)U+%%d+DIId%f%	s   69 =c                 P    	 | j                  |      d   dk(  S # t        $ r Y yw xY w)ai  
        Check if a path is a directory.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.isdir).

        Args:
            path (`str`):
                Path to check.

        Returns:
            `bool`: True if path is a directory, False otherwise.
        rp   r   F)r&  OSErrorr7   r1   s     r8   r   zHfFileSystem.isdir  s1    	99T?6*k99 		s    	%%c                 @    	 | j                  |      d   dk(  S #  Y yxY w)a`  
        Check if a path is a file.

        For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.isfile).

        Args:
            path (`str`):
                Path to check.

        Returns:
            `bool`: True if path is a file, False otherwise.
        rp   r   F)r&  rN  s     r8   isfilezHfFileSystem.isfile$  s)    	99T?6*f44	s    c                 x   | j                  |      }t        |t              r2| j                   d|j                   dt        |j                         }nBt        |j                  |j                  |j                  |j                  | j                        }| j                  |      r|j                  ddd      }|S )z
        Get the HTTP URL of the given path.

        Args:
            path (`str`):
                Path to get URL for.

        Returns:
            `str`: HTTP URL to access the file or directory on the Hub.
        z	/buckets/z	/resolve/)rD   rF   r   z/tree/r   )r   r   rW   r   rX   r   r1   r!   rE   rG   rD   rF   r   replace)r7   r1   r   urls       r8   rS  zHfFileSystem.url6  s     ))$/m%CD]]O9]-D-D,EYuUbUgUgOhNijC%%**'11&//C ::d++k8Q7C
r:   c                    |j                  d      }t        |j                               dhz
  }t        |t        t
        f      rt        |      dkD  rt        |    ||f||d|S t        |      r|}n)| j                  |      rt        j                  |d       yt        |t        t        f      r4t        j                  t        j                  j!                  |      d       d}|t#        |d      }d}|j%                         }	| j'                  ||	      }
| j)                  ||	      d
   }|j+                  |       	 t-        | j/                  |
j1                               |||d| j2                  j5                         t        |t
              r|j6                  nd       |j9                  |	       |r|j;                          yy# |r|j;                          w w xY w)ad  
        Copy single remote file to local.

        > [!WARNING]
        > Note: When possible, use `HfApi.hf_hub_download()` or `HfApi.download_bucket_files` for better performance.

        Args:
            rpath (`str`):
                Remote path to download from.
            lpath (`str`):
                Local path to download to.
            callback (`Callback`, *optional*):
                Optional callback to track download progress. Defaults to no callback.
            outfile (`IO`, *optional*):
                Optional file-like object to write to. If provided, `lpath` is ignored.

        rF   r   )callbackoutfileT)exist_okNFwbr   r   )rS  	temp_filedisplayed_filenameexpected_sizeresume_sizeheaders	_tqdm_bar)rQ   setkeysr   r   r   r   r_   get_filer   r   r   makedirsr?   r
   r1   dirnamer2  tellr   r&  set_sizer"   rS  r9   r   _build_hf_headerstqdmseekclose)r7   rpathlpathrU  rV  rd   rF   unhandled_kwargs
close_fileinitial_posresolve_remote_pathr[  re   s               r8   ra  zHfFileSystem.get_fileP  s   $ ::j)v{{}-<(\<$@ASIYEZ]^E^ 7#E5_8W_X^__ eGZZKK-ec4[)KK.> 
?5$'GJlln #///I		%(	;FC-(	 HH0::<=!#(+		335+5h+M(--SW LL%  z s   A4G G#c                     t        d      )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.
        (Transactional commits are not supported.r   r6   s    r8   transactionzHfFileSystem.transaction  s     ""LMMr:   c                     t        d      )z@Begin write transaction for deferring files, non-context versionrq  rr  r6   s    r8   start_transactionzHfFileSystem.start_transaction  s     ""LMMr:   c                 p    t         t        |       | j                  | j                  | j	                         ffS r^   )make_instancerp   rv   rw   rr   r6   s    r8   
__reduce__zHfFileSystem.__reduce__  s9    J  $$&	
 
 	
r:   c                     t        | j                        t        | j                        t        | j                        dS )N)r   r   r   )r   r   r   r   r6   s    r8   rr   z HfFileSystem._get_instance_state  s4     //78\8\/]$,T-F-F$G
 	
r:   r^   )r/  NN)FNN)TFN)FFNNN)NFFFN)FNr2   N)6r;   r<   r=   r>   root_markerprotocolr   r?   r   boolintr`   classmethodri   tuple	Exceptionr   r   rC   rW   r   r   r   r   r   r  dictr   r   r   r   r#   r$   r  r   r!  r#  r)  r:  r   r>  r&  rK  r   rP  rS  r   ra  propertyrs  ru  rx  rr   r   r   s   @r8   r   r      s   @D KH
 #'(,$(&*< 3-< T3_%	<
 SM< d^<6 	 	 	 	TT'*T6>smT	tXi((	)T&4 4dHY<O6O0P 4 48h
h
#+C=h
	13QQ	Rh
TQXc] Qd QH $("&XX X SM	X
 3-X 
;	<X$> >x} >$ >&  "&"&0>0> 0> 3-	0>
 3-0> 
0>f `d&;&;!%&;7;&;OWX[}&;	eCc3h'(	)&;V  "&&*"&KK K 	K
 3-K d^K 3-KZ&&&)&6:&	%
L01	2&P7 7(5d3iQUVYQZAZ;[2\ 7 ? ? ?4PS9 ?& #'"&;7;7 3-;7 	;7
 ;7 ;7 3-;7 
tCy$sDcN233	4;7z:?S :? :? :?[_ :?xhS hx h2l lt lx} lbfgjlogobp l\2$$  4 /@ < | N NN

r:   r   )	metaclassc                        e Zd Zddededee   f fdZ fdZdeded	e	fd
Z
ddZdded	dfdZd fd	Zd	efdZ xZS )r   Nfsr1   rF   c                     	 |j                  ||      | _        t	        |   || j                  j                         fi | |  y # t        $ r)}d|j                  dd      v rt        | d      | d }~ww xY w)Nr   wr   rN   B.
Make sure the repository and revision exist before writing data.)r   r   r'  rQ   r_   r`   r9   )r7   r  r1   rF   rd   r   re   s         r8   r`   zHfFileSystemFile.__init__  s    	!#!ID 	T//99;FvF ! 	fjj,,'c\] 	s   A 	A9$A44A9c                 :    t        | d      sy t        | 	         S Nr   )hasattrr_   __del__r7   re   s    r8   r  zHfFileSystemFile.__del__  s    t_-w  r:   startendr2   c                     dd| d|dz
   i| j                   j                  j                         }| j                         }t	        d||t
        j                        }t        |       |j                  S )Nrangebytes=-r   GETr]  r   )	r  r   rf  rS  r+   r   HF_HUB_DOWNLOAD_TIMEOUTr*   r9  )r7   r  r  r]  rS  rs         r8   _fetch_rangezHfFileSystemFile._fetch_range  sm    veWAcAgY/
ggll,,.
 hhjWi>_>_`Ayyr:   c                 <    t        j                  dd      | _        y )Nzhffs-F)r   r   )tempfileNamedTemporaryFilerY  r6   s    r8   _initiate_uploadz!HfFileSystemFile._initiate_upload  s    !44GERr:   finalc                 J   | j                   j                  d       | j                   j                         }| j                  j	                  |       |r| j                  j                          t        | j                  t              rg| j                  j                  j                  | j                  j                  | j                  j                  | j                  j                  fg       n| j                  j                  j                  | j                  j                  | j                  j                   | j                  j"                  | j                  j$                  | j                  j&                  | j                  j(                  | j*                  j-                  d      | j*                  j-                  d             t/        j0                  | j                  j                         | j                  j3                  | j                  j5                                y y )Nr   )addr   r   r0  r   )bufferrh  r3  rY  writeri  r   r   rW   r  r   r   rX   r   r1   r4  rG   rE   r   rD   rF   rd   rQ   r   remover   r9   )r7   r  blocks      r8   _upload_chunkzHfFileSystemFile._upload_chunk  s     "U#NN  "$,,.LM//&&008K8KTM_M_MdMd7e6f 0  (($(NN$7$7!%!3!3!@!@ ..66''--"00::!//88#';;??3C#D'+{{7K'L ) 	 IIdnn))*GG$$''113 % % r:   c                 H   | j                   dk(  rx||dk(  rq| j                  dk(  rb| j                  j                  | j                  dd      5 }|j                         }| xj                  t        |      z  c_        |cddd       S t        |   |      S # 1 sw Y   xY w)zRead remote file.

        If `length` is not provided or is -1, the entire file is downloaded and read. On POSIX systems the file is
        loaded in memory directly. Otherwise, the file is downloaded to a temporary file and read from there.
        r/  Nr@  r   )r   )r   locr  r2  r1   r3  r   r_   )r7   lengthr8  r   re   s       r8   r3  zHfFileSystemFile.read  s     99&.FbLdhhRSmdii!< ffhCH$  w|F##	 s   0BB!c                 L    | j                   j                  | j                        S r^   r  rS  r1   r6   s    r8   rS  zHfFileSystemFile.url      ww{{499%%r:   r^   rz  )Fr@  )r;   r<   r=   r   r?   r   r`   r  r~  bytesr  r  r}  r  r3  rS  r   r   s   @r8   r   r     sj    
< 
s 
hsm 
!# C E S4 D 4$&S &r:   r   c                        e Zd Z	 	 	 	 ddedededee   dedef fdZdded	efd
ZddefdZ	dde
e   dedefdZdefdZ fdZd Zd Z xZS )r   r  r1   r   rF   r   
cache_typec                    |dk7  rt        d|       |dk7  rt        d|       d|v rt        d| d      	 |j                  ||      | _        | j                  j                         d d| _        t        	|    || j                  j                         f|||d| d | _	        |  t               | _        d | _        t               | _        y # t        $ r-}d|j	                  d	d
      v rt        | d      |Y d }~d }~ww xY w)Nr   z:HfFileSystemStreamFile only supports block_size=0 but got nonez?HfFileSystemStreamFile only supports cache_type='none' but got r  z;HfFileSystemStreamFile only supports reading but got mode='r  r   r   rN   r  )r   r   r   r   r  )r   r   r   r'  rQ   r9   detailsr_   r`   responser   _exit_stack_stream_iterator	bytearray_stream_buffer)
r7   r  r1   r   rF   r   r  rd   r   re   s
            r8   r`   zHfFileSystemStreamFile.__init__  s7    ?YZdYefgg^_i^jkll$;Z[_Z``abcc	!#!ID !% 2 2 < < >M"",,.	
59j]g	
kq	
 37$;;?'k ! 	fjj,,'c\] -	s   C 	D#DDr  whencec                 X    |dk(  r|dk(  ry || j                   k(  r|dk(  ry t        d      )Nr   r   zCannot seek streaming HF file)r  r   )r7   r  r  s      r8   rh  zHfFileSystemStreamFile.seek  s2    !8!$((?v{899r:   r  c                    | j                   | j                          d}	 	 | j                   | j                  y| j                  | j                  |      }| xj                  t        |      z  c_        |S # t        $ r> | j                   | j                   j                          |r | j                          d}Y nw xY w)zRead the remote file.

        If the file is already open, we reuse the connection.
        Otherwise, open a new connection and read from it.

        If reading the stream fails, we retry with a new connection.
        FTr:   )r  _open_connectionr  _read_from_streamr  r   r  ri  )r7   r  retried_oncer   s       r8   r3  zHfFileSystemStreamFile.read&  s     == !!#$==(D,A,A,I,,T-B-BFKCH$
 $==,MM'')%%'#$ s   A6 ;A6 6AB=<B=iteratorr2   c                    |dk(  ry|dk  rRt        | j                        }| j                  j                          |D ]  }|j                  |        t	        |      S |t        | j                        k  r)t	        | j                  d|       }| j                  d|= |S t        | j                        }| j                  j                          |D ]m  }|t        |      z
  }|t        |      kD  r|j                  |       1|j                  |d|        | j                  j                  ||d         t	        |      S  t	        |      S )zRead up to `length` bytes from stream buffer and stream.

        If length < 0, read until EOF.

        If EOF is reached before length, fewer bytes may be returned.
        r   r:   N)r  r  r   r   r  r   )r7   r  r  bufchunkresultneeds          r8   r  z(HfFileSystemStreamFile._read_from_streamB  s9    Q;A:D//0C%%'! "

5!":S,,--4..w78F##GVG,M++,!!# 	ECH$Dc%j 

5!

5$<(##**5<8Sz	 Szr:   c                 L    | j                   j                  | j                        S r^   r  r6   s    r8   rS  zHfFileSystemStreamFile.urld  r  r:   c                 n    t        | d      sy | j                  j                          t        |          S r  )r  r  ri  r_   r  r  s    r8   r  zHfFileSystemStreamFile.__del__g  s/    t_- w  r:   c                     t         | j                  | j                  | j                  | j                  | j
                  j                  ffS r^   )reopenr  r1   r   	blocksizecacher   r6   s    r8   rx  z!HfFileSystemStreamFile.__reduce__n  s0    DIIt~~tzzWWWr:   c                 @   | j                   j                          d| _        | j                         }| j                  j
                  j                         }| j                  dkD  rd| j                   d|d<   | j                  j                  t        d||t        j                              | _        	 t        | j                         | j                  j#                         | _        y# t        $ r+}|j                  j                   dk(  rd| _        Y d}~y d}~ww xY w)	z%Open a connection to the remote file.Nr   r  r  Ranger  r  i  )r  r   r  rS  r  r   rf  r  r  enter_contextr,   r   r  r  r*   r   status_code
iter_bytes)r7   rS  r]  r   s       r8   r  z'HfFileSystemStreamFile._open_connectionq  s     	!!# $hhj'',,00288a<!'z3GG((66!99	
	. !% 8 8 :  	zz%%, $	s   4C) )	D2 DDD)r/  Nr   r  )r   r  )r;   r<   r=   r   r?   r   r~  r`   rh  r3  r   r  r  rS  r  rx  r  r   r   s   @r8   r   r     s    
 "& !*!* !* 	!*
 3-!* !* !*F: :S :$3 $8 (5/  3  PU  D&S &!X;r:   r   rF   r2   c                 F    t         j                  |       r| S t        |       S r^   )r   r   
safe_quoter   s    r8   rS   rS     s     288B8\
S[H\\r:   sc                     t        | d      S )NrN   )safe)r   )r  s    r8   r  r    s    r:   r1   r   c                     | }t        |t              r|  d}n+t        |t              r|  d}nt        |t              r|  d}t	        |      |)Nz (repository not found)z (revision not found)z (invalid repository id))r   r   r    r)   r'  )r1   r   msgs      r8   r   r     s\    
C#./-.	C.	/+,	C*	+./
C
 c)r:   r  r   r   r  c                 ,    | j                  ||||      S )Nr  )r2  )r  r1   r   r   r  s        r8   r  r    s    774dzj7QQr:   c                 `     | |i |}|j                         D ]  \  }}t        |||        |S r^   )rs   rt   )rb   rc   rd   r|   r  r}   r~   s          r8   rw  rw    s?    	d	f	B+113 'kD+&'Ir:   )Zr   rer  rj   collectionsr   
contextlibr   copyr   dataclassesr   r   r   	itertoolsr	   pathlibr
   r   typingr   r   r   r   r   r   urllib.parser   r   fsspechttpxfsspec.callbacksr   r   r   fsspec.utilsr   rN   r   _commit_apir   r   errorsr   r   r   r   r    file_downloadr!   r"   hf_apir#   r$   r%   r&   r'   r(   utilsr)   r*   r+   r,   utils.insecure_hashlibr-   compileVERBOSEr   r/   rC   rW   rp   AbstractFileSystemrZ   r@   r\   r   specAbstractBufferedFiler   r   r?   rS   r  r  r   r~  r  rw  hffsrA   r:   r8   <module>r     s   	 	       (   ' E E '   J J #  C  0 Y Y \ \ ' )bjj
 JJ  6 6 6 &)A & &0 0%= 0 0 223c 3/l /dZ
6,, Z
z H&v{{77 H&VR;V[[== R;j]C ]C ]# # * *(9*= *( *R| R3 Rc Rs RPS R ~r:   