
    Y jj              
       2   % S SK r S SKrS SK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  S SKJr  S SKJr  S S	KJrJr  S S
KJrJrJr  S SKJrJr  S SKrS SKrS SKJrJ r J!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,J-r-J.r.J/r/J0r0  SSK1J2r2J3r3  SSK4J5r5J6r6J7r7J8r8J9r9J:r:J;r;  SSK<J=r=J>r>J?r?J@r@  SSKAJBrB  \ " S S5      5       rC\ " S S\C5      5       rD\ " S S\C5      5       rE\F" \R                  5      rH\\IS'    " S S\H5      rJ " S  S!\R                  \JS"9rK " S# S$\R                  R                  5      rN " S% S&\R                  R                  5      rOS'\PS(\P4S) jrQS*\PS(\P4S+ jrRS,\PS-\SS-  S(\4S. jrTS/\KS,\PS0\PS1\US2\P4
S3 jrVS4 rW\K" 5       rXg)5    N)deque)IterableIterator)	ExitStack)deepcopy)	dataclassfield)datetime)chain)PathPurePosixPath)AnyNoReturnUnion)quoteunquote)_DEFAULT_CALLBACKNoOpCallbackTqdmCallback)apply_config)
isfilelike   )	constants)CommitOperationCopyCommitOperationDelete)BucketNotFoundErrorEntryNotFoundErrorHfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError)
hf_hub_urlhttp_get)SPECIAL_REFS_REVISION_REGEX
BucketFileBucketFolderHfApiLastCommitInfoRepoFile
RepoFolder)HFValidationErrorhf_raise_for_statushttp_backoffhttp_stream_backoff)md5c                   <    \ rS rSr% Sr\\S'   \\S'   S\4S jrSrg)	HfFileSystemResolvedPath$   z_Top level Data structure containing information about a resolved Hugging Face file system path.rootpathreturnc                 V    U R                    SU R                   3R                  S5      $ )N/)r2   r3   rstripselfs    o/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/huggingface_hub/hf_file_system.py	unresolve"HfFileSystemResolvedPath.unresolve+   s&    ))Adii[)0055     N)	__name__
__module____qualname____firstlineno____doc__str__annotations__r;   __static_attributes__r>   r=   r:   r0   r0   $   s    i
I
I63 6r=   r0   c                       \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \" SS9r\\S	'   \" SS9r	\\S
'   \" SSS9r
\S-  \S'   S rSrg)"HfFileSystemResolvedRepositoryPath/   zLData structure containing information about a resolved path in a repository.	repo_typerepo_idrevisionpath_in_repoFinitr2   r3   N)defaultrepr_raw_revisionc                 l   [         R                  R                  U R                  S5      U R                  -   nU R
                  (       a  U SU R
                   3U l        ODU R                  [         R                  :w  a   U S[        U R                  5       3U l        OXl        U R                  U l        g )N @)r   REPO_TYPES_URL_PREFIXESgetrJ   rK   rR   r2   rL   DEFAULT_REVISIONsafe_revisionrM   r3   )r9   	repo_paths     r:   __post_init__0HfFileSystemResolvedRepositoryPath.__post_init__=   s    5599$.."MPTP\P\\	$+Qt'9'9&:;DI]]i888$+Q}T]]'C&DEDI!I%%	r=   )r3   r2   )r?   r@   rA   rB   rC   rD   rE   r	   r2   r3   rR   r[   rF   r>   r=   r:   rH   rH   /   sT    VNLM5!D#!5!D#! !&d ?M3:?&r=   rH   c                   @    \ rS rSr% Sr\\S'   \" SS9r\\S'   S r	Sr
g	)
HfFileSystemResolvedBucketPathH   zHData structure containing information about a resolved path in a bucket.	bucket_idFrN   r2   c                 ,    SU R                   -   U l        g )Nzbuckets/)r`   r2   r8   s    r:   r[   ,HfFileSystemResolvedBucketPath.__post_init__O   s    /	r=   )r2   N)r?   r@   rA   rB   rC   rD   rE   r	   r2   r[   rF   r>   r=   r:   r^   r^   H   s    RN5!D#!0r=   r^   _cached_basec                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )_CachedW   a  
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                 4   > [         TU ]  " U0 UD6  0 U l        g N)super__init___cache)clsargskwargs	__class__s      r:   rj   _Cached.__init__g   s    $)&) 
r=   c                    [        X5      nUR                  SS5      nU R                  " U [        R                  " 5       /UQ70 UD6nU R                  " U [        R
                  " 5       R                  /UQ70 UD6nU(       d5  U R                  (       a$  X@R                  ;   a  X@l	        U R                  U   $ [        R                  " U /UQ70 UD6nU(       db  U R                  (       aQ  XPR                  ;   aB  U R                  U   R                  5       nUR                  5        H  u  p[        XhU	5        M     XFl        Xl        X&l        U R                  (       a  U(       d  X@l	        X`R                  U'   U$ )Nskip_instance_cacheF)r   pop	_tokenize	threading	get_identmain_threadidentcachablerk   _latesttype__call___get_instance_stateitemssetattr
_fs_token_storage_argsstorage_options)
rl   rm   rn   skipfs_tokenfs_token_main_threadobjinstance_stateattrstate_values
             r:   r|   _Cached.__call__o   s*    c*zz/7==i&9&9&;MdMfM"}}S)2G2G2I2O2OaRVaZ`aZZ)?"K::h'' --5d5f5CCLL-AZZ-O!$,@!A!U!U!W)7)=)=)?%DC{3 *@%N#"(||D&'*

8$Jr=   r>   )	r?   r@   rA   rB   rC   rj   r|   rF   __classcell__ro   s   @r:   re   re   W   s     r=   re   c                     ^  \ rS rSrSrSrSrSSSSS.S\S-  S\\-  S-  S	\	S-  S
\S-  4U 4S jjjr
\S\	S\4S j5       rS\S\S\S-  S\\\S-  4   4S jrS\S\\\S-  4   4S jr S8S\S\S-  S\\-  4S jjrS8S\S-  SS4S jjr   S9S\S\S	\	S-  S\S-  S\S   4
S jjrS8S\S\S-  SS4S jjr   S:S\S\S\	S-  S\S-  SS4
S jjr S;S\S\S \S\S-  S\\\\\4   -     4
S! jjr     S<S\S\S \S\S-  S
\S-  S\	S-  4S" jjrS\S#\S\S\\\ -     4S$ jr!S\S\"\\\\   \\   4      4U 4S% jjr#S8S\S\	S-  S\\   4U 4S& jjjr$     S=S\S\	S-  S'\S\S \S\S-  S\\   \\\\\4   4   -  4S( jjr%S8S)\S*\S\S-  SS4S+ jjr&S\S\'4S, jr(S>S\S \S\S-  S\\\4   4S- jjr)S. r*S/ r+S0 r,S\S\4S1 jr-\.S4S?U 4S2 jjjr/\0S3 5       r1S4 r2S5 r3S6 r4S7r5U =r6$ )@HfFileSystem   a	  
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)
```
rT   hfN)endpointtoken
block_sizeexpand_infor   r   r   r   c                   > [         TU ]  " U0 UD6  U=(       d    [        R                  U l        X l        [        XS9U l        X0l        X@l	        0 U l
        0 U l        0 U l        g )N)r   r   )ri   rj   r   ENDPOINTr   r   r&   _apir   r   _repo_and_revision_exists_cache_bucket_exists_cachedircache)r9   r   r   r   r   rm   r   ro   s          r:   rj   HfFileSystem.__init__   sb     	$2/2 6I$6$6
89	$& rt,NP! :<r=   threading_identr4   c                 0   UR                  S5      =(       d    [        R                  US'   UR                  S5      US'   [        U5       Vs0 s H  oDX4   _M	     nnXX#4n[	        [        U5      R                  5       5      nUR                  5       $ s  snf )zDeterministic token for cachingr   r   )rW   r   r   sortedr.   rD   encode	hexdigest)rl   r   rm   rn   keytokenize_argshs          r:   rt   HfFileSystem._tokenize   s     $ZZ
3Iy7I7Iz **W-w.4Vn=nsv{"n=t<M"))+,{{}	 >s   BrJ   rK   rL   c                    XU4U R                   ;  aL   U R                  R                  X#U[        R                  S9  SU R                   XU4'   SU R                   XS 4'   U R                   XU4   $ ! [
        [        4 a0  nSU4U R                   XU4'   SU4U R                   XS 4'    S nANLS nAf[         a.  nSU4U R                   XU4'   SU R                   XS 4'    S nANS nAff = f)N)rL   rJ   timeoutTNF)r   r   	repo_infor   HF_HUB_ETAG_TIMEOUTr   r*   r    )r9   rJ   rK   rL   es        r:   _repo_and_revision_exist%HfFileSystem._repo_and_revision_exist   s    )1U1UU^		##)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#   )A0 0C& &B++C&8$C!!C&r`   c                     XR                   ;  a+   U R                  R                  U5        SU R                   U'   U R                   U   $ ! [         a  nSU4U R                   U'    S nAN/S nAff = f)Nr   F)r   r   bucket_infor   )r9   r`   r   s      r:   _bucket_existsHfFileSystem._bucket_exists
  sr    555B		%%i0 8B)))4((33	 ' @7<ax)))4@s   A
 

A/A**A/r3   c                    S[         S-  S[         S-  S[         S-  4S jnU R                  U5      nU(       d  [        S5      eUR                  S5      S   S	:X  at  SR	                  UR                  S5      S
S 5      nSR	                  UR                  S5      SS 5      nU R                  U5      u  pVU(       d  [        X5        [        XAS9$ UR                  S5      S   S-   [        R                  R                  5       ;   a9  SU;  a  [        S5      eUR                  SS
5      u  pq[        R                  U   nO[        R                  nUR                  S5      S:  Ga  SSR	                  UR                  S5      SS 5      ;   a  UR                  SS
5      u  pSU	;   a{  [        R                  " U	5      n
U
bM  USU
R!                  5       4;   a7  [        R"                  " SU	5      R%                  S5      nU
R!                  5       n	OU	R                  SS
5      u  pOSnU" ['        U	5      U5      nU R)                  XxU5      u  pU(       d  [        X5        GOKSn	SR	                  UR                  S5      SS 5      nSR	                  UR                  S5      SS 5      nUR                  S5      S   nSR	                  UR                  S5      S
S 5      nUnUnU R)                  XxU5      u  pU(       dR  [+        U[,        [.        45      (       a,  UnUnU R)                  XxU5      u  nnU(       d  [        X5        Of[        X5        OZUnSnSU;   a'  UR                  SS
5      u  pU" ['        U	5      U5      nOSn	U R)                  XxU5      u  nnU(       d  [        S5      eUb  UO[        R0                  n[3        XxX+U	S9$ )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_pathNrL   r4   c                 H    Ub  U b  X:w  a  [        SU  SU S35      eU$ U nU$ )NzRevision specified in path ("z ") and in `revision` argument ("z") are not the same.)
ValueError)r   rL   s     r:   %_align_revision_in_path_with_revisionHHfFileSystem.resolve_path.<locals>._align_revision_in_path_with_revision*  sQ    ##/4D4P$78H7IIijris t- -  O ,Or=   z<Access to buckets and repositories lists is not implemented.r6   r   bucketsr      )r`   r3   z0Access to repositories lists is not implemented.rU      rT   )rR   )rD   _strip_protocolNotImplementedErrorsplitjoinr   _raise_file_not_foundr^   r   rV   valuesREPO_TYPES_MAPPINGREPO_TYPE_MODELcountr#   searchgroupsublstripr   r   
isinstancer   r*   rX   rH   )r9   r3   rL   r   r`   bucket_existserrrJ   rK   r   matchrM   repo_and_revision_existrepo_id_with_namespacepath_in_repo_with_namespacerepo_id_without_namespacepath_in_repo_without_namespace_s                     r:   resolve_pathHfFileSystem.resolve_path  s   ,		C$J 		Z]`dZd 		ilosis 		 ##D)%&deeZZ_Q9,C1!56I88DJJsOAB/0D!%!4!4Y!?M %d01IQQZZ_Q#%)J)J)Q)Q)SS$)*\]]"jja0OI!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/LYai/j,'.)$4#' ),$**S/"12E)F&.1hhtzz#qr7J.K+,0JJsOA,>)14$**S/!":M1N.0:/3/L/LYai/j,'.!#(?AR'STT";'E595R5RS\go5p2/61$<-d8GLd{,0JJsA,>)@IYAZ\de#' )-)F)Fy[c)d&#Q*)*\]]'389S9S1FV
 	
r=   c                    U(       d5  U R                   R                  5         U R                  R                  5         gU R                  U5      nUR	                  5       nU(       a6  U R                   R                  US5        U R                  U5      nU(       a  M6  UR                  (       d  [        U[        5      (       aq  U R                  R                  UR                  UR                  S4S5        U R                  R                  UR                  UR                  UR                  4S5        gU R                  R                  UR                  S5        gg)a3  
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   r;   rs   _parentr3   r   rH   rJ   rK   rL   r   r`   )r9   r3   resolved_paths      r:   invalidate_cacheHfFileSystem.invalidate_cache|  s    MM!00668 --d3M **,D!!$-||D) $
 !%%m-OPP88<<&00-2G2GNPT 88<<&00-2G2GI_I_`bf --11-2I2I4P &r=   mode)HfFileSystemFileHfFileSystemStreamFilec                     Ub  UOU R                   nUb  X5S'   SU;   a  [        S5      eUS:X  a  [        X4X$S.UD6$ [        X4X$S.UD6$ )Nr   az/Appending to remote files is not yet supported.r   )r   rL   )r   r   r   r   )r9   r3   r   r   rL   rn   s         r:   _openHfFileSystem._open  sh     $.#9Zt
!#-< $;%&WXX?)$]4]V\]]#DWTWPVWWr=   c                    U R                  XS9n[        U[        5      (       a0  U R                  R	                  UR
                  UR                  /S9  OoU R                  R                  UR                  UR                  U R                  UR                  UR                  UR                  S5      UR                  S5      S9  U R                  UR                  5       S9  g )NrL   deletecommit_messagecommit_description)rM   rK   r   rJ   rL   r   r   r3   )r   r   r^   r   batch_bucket_filesr`   r3   delete_filerM   rK   r   rJ   rL   rW   r   r;   )r9   r3   rL   rn   r   s        r:   _rmHfFileSystem._rm  s    ))$)Bm%CDDII(()@)@-J\J\I](^II!!*77%--jj'11&//%zz*:;#)::.B#C "  	=#:#:#<=r=   	recursivemaxdepthc                 T   U R                  XS9nU R                  XX4S9n[        U[        5      (       ag  U Vs/ s H5  oR	                  U5      (       a  M  U R                  U5      R
                  PM7     nnU R                  R                  UR                  US9  OU Vs/ s H5  oR	                  U5      (       a  M  U R                  U5      R
                  PM7     n	nU	 V
s/ s H  n
[        U
S9PM     nn
SW S3nX(       a  SOS-  nXb  S
U S3OS-  nU R                  R                  UR                  UR                  U R                  UUR                  UR                  SU5      UR                  S5      S9  U R!                  UR#                  5       S9  g	s  snf s  snf s  sn
f )ad  
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   rL   r   )rM   zDelete  zrecursively rT   Nzup to depth r   r   )rK   rJ   r   
operationsrL   r   r   r   )r   expand_pathr   r^   isdirr3   r   r   r`   r   create_commitrK   rJ   r   rL   rW   r   r;   )r9   r3   r   r   rL   rn   r   pathsr   paths_in_reporM   r   r   s                r:   rmHfFileSystem.rm  s   6 ))$)B  X am%CDD?D]utJJW[L\2d''-22uF]II(()@)@(PFKdedS]S]^bSc9T..t499eMd_lm_l|/\J_lJm&tfA.N	nrAN<PXJa8VXXNII##%--'11jj%&//%zz*:NK#)::.B#C $  	=#:#:#<=% ^ ems   FF F =F "F%detailrefreshc                    U R                  XS9nUR                  5       n U R                  " U4X4S.UD6nU(       a  U$ U Vs/ s H  oS   PM	     sn$ ! [         a    UR                  (       d  [        US5         U R                  " U R                  U5      4X4S.UD6nO! [         a    / n Of = fU Vs/ s H  oS   U:X  d  M  UPM     Os  snf nn[        U5      S:X  a  [        US5         Nf = fs  snf )aG  
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   rL   Nnamer   )r   r;   _ls_treer   r3   r   r   len)	r9   r3   r   r   rL   rn   r   outos	            r:   lsHfFileSystem.ls  s    4 ))$)B&&(	2--SgSFSC s:c":cV9c":: " 
	2 %%%dD1mmDLL$6ee^de% !7cvY$%61c7C73x1}%dD1
	2 #;sM   A C6'C3<$B! C3!B0-C3/B00C37CC#C32C3c                 |
   Ub  UOU R                   b  U R                   OSnU R                  XS9nUR                  5       nUR                  nU(       a  UOSn/ n	XR                  ;   Ga  U(       Gd  U R                  U   n
U	R                  U
5        / nU(       a  Sn[        U
 Vs/ s H  oS   S:X  d  M  X4PM     sn5      nU(       a  UR                  5       u  pUb  X::  a}  US   U R                  ;  a  UR                  US   5        OUU R                  US      n
U	R                  U
5        UR                  U
 Vs/ s H  nUS   S:X  d  M  US-   U4PM     sn5        U(       a  M  / nU(       aA  [        U[        5      (       a,  U	 Vs/ s H  nUS   b  M  U R                  US   5      PM!     nnU(       a  U(       d  U(       Ga_  U(       GaW  [        R                  R                  UU-   5      nUR                  S	5      (       d  UU:X  d  U[!        UU5      ;   a  UR#                  S	5      OU R                  U5      nUb"  U[%        U5      S  R'                  S	5      nUU-  nU	 Vs/ s H#  nUS   R)                  US	-   5      (       a  M!  UPM%     n	n[+        U R                  5       H:  nUR)                  US	-   5      (       d  M  U R                  R-                  US 5        M<     U R                  R-                  US 5        U	R                  U R/                  UUS
UUUS95        U	$ [        U[0        5      (       a&  U R3                  UR4                  UR                  US9nOFU R6                  R9                  UR:                  UR                  UUUR<                  UR>                  S9nU GHu  nUS	-   UR                  -   n[        U[@        5      (       aH  UURB                  SURD                  URF                  URH                  URJ                  URL                  S.nO[        U[N        5      (       a2  UURB                  SURH                  URP                  URR                  S.nOC[        U[T        5      (       a  USSURV                  URJ                  S.nOUSSURR                  S.nU R                  US   5      nU R                  RY                  U/ 5      R                  U5        U[%        U5      S  R'                  S	5      nUb  X::  d  GMd  U	R                  U5        GMx     U	$ s  snf s  snf s  snf s  snf )NFr   r   r   r{   	directoryr   last_commitr6   T)r   r   rL   r   r   )prefixr   )r   expandrL   rJ   filer   sizer{   blob_idlfsxet_hashr  security)r   r  r{   r  mtimeuploaded_atr   r   r  r{   tree_idr  )r   r  r{   r  )-r   r   r;   r2   r   extendr   popleftappendr   rH   r   osr3   commonprefixendswithr   r7   r   r   
startswithlistrs   r   r^   _list_bucket_tree_with_foldersr`   r   list_repo_treerK   rL   rJ   r(   r  r	  r
  r  r  r  r$   r  r  r)   r  
setdefault)r9   r3   r   r   rL   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                             r:   r   HfFileSystem._ls_tree  s    '2KTM]M]Mi9I9Iot 	 ))$)B&&(!&&	(8a==  $d 3JJ()#%   %9Jo9JIX^N_cnNn'e'9Jo! $&3&;&;&=OE'5+<#F+4==@0778HI04hv>N0O-JJ'89)00 6G!"5F	'0'8K'G %;UQY	$:5F!" $m  !#z-9[\\FI$fcQ}M]%<T\\!F)%<c!$f2HY !# 4 45IL]5] ^ %--c22$	1$.BDU(VV "((- m4  '(3CIK(@(F(Fs(K% 11H"%U#QQvY-A-A+PSBS-Tq#U#'#6K"--kC.?@@))+t< $7 !!+t4

MM#"+ $!)$/!) " 	J 
s -)GHH::!++(--' ;  yy//!))!&&'&*33+55 0  "	&_y~~=
i22 * ) &#,#4#4(}}$-$6$6'0'<'<$-$6$6	'O  	:66 * ) &$-$6$6!*'0'<'<'O  	:66 * ! +#,#4#4'0'<'<'O !+ ! +'0'<'<	'O #ll?6+BC((b9@@Q"3t9;/55c:#u'8JJ/S "T 
a p!" %g" Vs0   %T*5T*>T/T/
T4T4+ T9T9r  c                    U R                   R                  XUS9n0 nU(       a  SUR                  S5      -   OSn/ nU H  nUR                  U5        U(       d  M  [	        [        UR                  5      R                  5      SU* S-
    H  n	[        S[        U	5      UR                  S9n
U
R                  U;  a!  UR                  U
5        XU
R                  '   MR  U
R                  c  Ma  XZR                     nUR                  b  UR                  U
R                  :  d  M  U
R                  Ul
        M     M     U(       d  [        SU S	U S
35      eU$ )z<Same as `HfApi.list_bucket_tree` but always includes folders)r   r   r6   r   Nr  )r{   r3   r  zFile not found in bucket 'z': '')r   list_bucket_treer   r  r  r   r3   parentsr%   rD   r  r   )r9   r`   r  r   bucket_filesbucket_folders	min_depthr   bucket_entryparent_bucket_folder_strparent_bucket_folderbucket_folders               r:   r  +HfFileSystem._list_bucket_tree_with_folders  sS    yy11)y1Y24-3AS))	/1(LJJ|$  -1|?P?P1Q1Y1Y,Z[k^g]gjk]k,l('3$3/G+HVbVnVn($
 (,,NBJJ34@T#7#<#<= (33?$23L3L$MM$008%114H4T4TT4H4T4T1# -m )6 $'A)DQWPXXY%Z[[
r=   c              /      >#    U R                  XR                  S5      S9R                  5       n[        TU ]  " U/UQ70 UD6 Sh  vN   g N7f)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.
rL   r   N)r   rW   r;   ri   walk)r9   r3   rm   rn   ro   s       r:   r:  HfFileSystem.walk  sI        

:0F GQQS7<6t6v666s   AAAAc                    > U R                  XR                  S5      S9R                  5       n[        TU ]  " U4SU0UD6$ )a(  
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.
rL   r   r   )r   rW   r;   ri   glob)r9   r3   r   rn   ro   s       r:   r=  HfFileSystem.glob  sC       

:0F GQQSw|D>8>v>>r=   withdirsc                 P   Ub  US:  a  [        S5      eU R                  XS9nUR                  5       n U R                  " U4SXRS.UD6n	U(       d  U	 V
s/ s H  oS   S:w  d  M  U
PM     n	n
O$U R                  " U40 UD6nUS   S:X  a  U/U	-   OU	n	U	 V
s0 s H  oS   U
_M
     n	n
[        U	5      nU(       d  U$ U Vs0 s H  oX   _M	     sn$ s  sn
f s  sn
f ! [
         a;     U R                  " U4S	U0UD6S   S
:X  a  U0 0n	 N`0 n	 Nd! [         a    0 n	  Nsf = ff = fs  snf )aE  
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   r{   r  r   rL   r  )r   r   r;   r   infor   FileNotFoundErrorr   )r9   r3   r   r?  r   r   rL   rn   r   r   r   r   namesr   s                 r:   findHfFileSystem.find  s]   @ HqL:;;))$)B&&(	.--cgc\bcC "%B#Q6k)Aq#B !IId5f5	+4V+<+KykC'QT),-AV9a<C-sL056#)O66 C
 .! " 	99T?H??G6Q*CC$ 	* 7sG   C C&CC D#
D & DDDD DD path1path2c                 4   U R                  XS9nU R                  X#S9n[        U[        5      (       d  [        U[        5      (       a  [        S5      eUR                  UR                  :H  =(       a    UR
                  UR
                  :H  nU(       a  SU SU 3nU R                  R                  UR
                  UR                  UR                  UR                  SU5      UR                  SS5      [        UR                  UR                  UR                  S9/S	9  OU R                  US
UR                  S9 n	U	R                  5       n
SSS5        SU SU 3nU R                  R                  W
UR                  UR
                  U R                  UR                  UR                  UR                  SU5      UR                  S5      S9  U R!                  UR#                  5       S9  U R!                  UR#                  5       S9  g! , (       d  f       N= f)aB  
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   rT   )src_path_in_reporM   src_revision)rK   rJ   rL   r   r   r   rbNpath_or_fileobjrM   rK   r   rJ   rL   r   r   r   )r   r   r^   r   rJ   rK   r   r   rL   rW   r   rM   openreadupload_filer   r   r;   )r9   rF  rG  rL   rn   resolved_path1resolved_path2	same_repor   fcontents              r:   cp_fileHfFileSystem.cp_file.  s     **5*D**5*Dn&DEE:J
 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IQ&&( J$UG4w7NII!! '+88&..jj(22'00%zz*:NK#)::.B#C " 	 	>#;#;#=>>#;#;#=> JIs   <H		
Hc                     U R                   " U40 0 UESS0ED6nSU;   a$  US   c  [        SU S35      eUS   R                  $ SU;   a  US   (       a  US   $ SU;   a  US   (       a  US   $ [        SU S	U S
35      e)a+  
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: ))rA  r   date)r9   r3   rn   rA  s       r:   modifiedHfFileSystem.modifiedj  s     yyA!@F!@M4!@AD M"*),efjekkl*mnn&+++_g= d"tM':&&%(OPTvU^_c^dde&fggr=   c           	      &   U R                  XS9nUR                  5       nUR                  SU R                  b  U R                  OS5      nUR                  (       d  USSS.n[        U[        5      (       a  SUS'   [        U[        5      (       as  U(       al  U R                  R                  UR                  UR                  UR                  S	9S
   n0 UES[        UR                  UR                  UR                  S9S.EnGOw[        U[         5      (       ac  U R#                  U5      n	U R%                  XS9  U R&                  U	    V
s/ s H  oS   U:X  d  M  U
PM     nn
U(       d  [)        US5        US   nGOSnU R#                  U5      n	U(       d   XR&                  ;  a  U R%                  U	5        XR&                  ;   aA  U R&                  U	    V
s/ s H  oS   U:X  d  M  U
PM     nn
U(       d  [)        US5        US   nU(       d  Ub  U(       Gac  U(       Ga[  US   GcT  U R                  R+                  UR                  UR,                  UUR                  UR                  S9nU(       d  [)        US5        US   n[        UR                  UR                  UR                  SUR.                  S9R                  5       n[        U[0        5      (       aX  US-   UR                  -   UR2                  SUR4                  UR6                  UR8                  UR:                  UR<                  S.nO,US-   UR                  -   SSUR>                  UR:                  S.nU(       d  S Vs0 s H  oX   _M	     nnUc   eU$ s  sn
f s  sn
f s  snf )a  
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  r{   r  )rJ   rL   )oidtitlerZ  )r  r  )r   r   )r  rL   rJ   rT   )rM   rR   r6   r  r  r  ) r   r;   rW   r   r3   r   rH   r   list_repo_commitsrK   rJ   rL   r'   	commit_idr`  
created_atr^   r   r   r   r   get_paths_inforM   rR   r(   r  r	  r
  r  r  r  r  )r9   r3   r   rL   rn   r   r   r   r  r+  r   out1
paths_infor   r  ks                   r:   rA  HfFileSystem.info  s^   , ))$)B&&(jjt/?/?/K4++QV
 !! #C
 -)KLL%)M"-)KLLQ\"ii99!))]5L5LWdWmWm : ##1'119J9JQ\QgQg$ 'EFF,,t,KGGKG1#}}[9O9!vY$=NA9DO%dD1q'CC,,t,K;mm#C$mm+#'==#=S#=a6dAR#=S)$51g#++##mBTB\!YY55!))!..&*33+55 6 
 ")$5&qM	>!++!))!**!#"/"="= )+  i22 )C).. @ ) &#,#4#4(}}$-$6$6'0'<'<$-$6$6	C !*C).. @ ! +#,#4#4'0'<'<C #.FG.Fcf9.FCG
q P TT Hs   NNN	(N	-Nc                      UR                  SS5      (       a  U R                  U5        U R                  " U40 UD6  g! [         a     gf = f)aq  
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)rW   r   rA  OSError)r9   r3   rn   s      r:   existsHfFileSystem.exists  sL     	zz)U++%%d+IId%f% 		s   ;> 
A
Ac                 R     U R                  U5      S   S:H  $ ! [         a     gf = f)a)  
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.
r{   r  FrA  rj  r9   r3   s     r:   r   HfFileSystem.isdir
  s1    	99T?6*k99 		    
&&c                 R     U R                  U5      S   S:H  $ ! [         a     gf = f)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.
r{   r  Frn  ro  s     r:   isfileHfFileSystem.isfile  s1    	99T?6*f44 		rq  c                    U R                  U5      n[        U[        5      (       a2  U R                   SUR                   S[        UR                  5       3nO?[        UR                  UR                  UR                  UR                  U R                  S9nU R                  U5      (       a  UR                  SSS5      nU$ )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/)rJ   rL   r   z/tree/r   )r   r   r^   r   r`   r   r3   r!   rK   rM   rJ   rL   r   replace)r9   r3   r   urls       r:   rw  HfFileSystem.url.  s     ))$/m%CDD]]O9]-D-D,EYuUbUgUgOhNijC%%**'11&//C ::d++k8Q7C
r=   c                   > UR                  S5      n[        UR                  5       5      S1-
  n[        U[        [
        45      (       a  [        U5      S:  a  [        TU ]   " X4X4S.UD6$ [        U5      (       a  UnO,U R                  U5      (       a  [        R                  " USS9  g[        U[        [        45      (       a2  [        R                  " [        R                  R!                  U5      SS9  SnUc  [#        US5      nSnUR%                  5       n	U R'                  XS	9n
U R)                  XS	9S
   nUR+                  U5         [-        U R/                  U
R1                  5       5      UUUSU R2                  R5                  5       [        U[
        5      (       a  UR6                  OSS9  UR9                  U	5        U(       a  UR;                  5         gg! U(       a  UR;                  5         f f = f)a  
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.

rL   r   )callbackoutfileT)exist_okNFwbr   r  )rw  	temp_filedisplayed_filenameexpected_sizeresume_sizeheaders	_tqdm_bar)rW   setkeysr   r   r   r   ri   get_filer   r   r  makedirsrD   r   r3   dirnamerN  tellr   rA  set_sizer"   rw  r;   r   _build_hf_headerstqdmseekclose)r9   rpathlpathrz  r{  rn   rL   unhandled_kwargs
close_fileinitial_posresolve_remote_pathr  ro   s               r:   r  HfFileSystem.get_fileH  s   $ ::j)v{{}-<(\<$@AASIYEZ]^E^ 7#E_8_X^__ eGZZKK-ec4[))KK.> 
?5$'GJlln #///I		%	;FC-(	 HH0::<=!#(+		335+5h+M+M(--SW LL%  z s   A6G G8c                     [        S5      e)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   r8   s    r:   transactionHfFileSystem.transaction  s     ""LMMr=   c                     [        S5      e)z@Begin write transaction for deferring files, non-context versionr  r  r8   s    r:   start_transactionHfFileSystem.start_transaction  s     ""LMMr=   c                 p    [         [        U 5      U R                  U R                  U R	                  5       44$ rh   )make_instancer{   r   r   r}   r8   s    r:   
__reduce__HfFileSystem.__reduce__  s9    J  $$&	
 
 	
r=   c                     [        U R                  5      [        U R                  5      [        U R                  5      S.$ )N)r   r   r   )r   r   r   r   r8   s    r:   r}    HfFileSystem._get_instance_state  s4     //78\8\/]$,T-F-F$G
 	
r=   )r   r   r   r   r   r   r   r   rh   )rK  NN)FNN)TFN)FFNNN)NFFFN)FNr4   N)7r?   r@   rA   rB   rC   root_markerprotocolrD   boolintrj   classmethodrt   tuple	Exceptionr   r   rH   r^   r   r   r   r   r   r   r  dictr   r   r   r   r$   r%   r  r   r:  r=  rD  rV  r
   r[  rA  rk  r   rs  rw  r   r  propertyr  r  r  r}   rF   r   r   s   @r:   r   r      s|   @D KH
  $#'!%#'< *< czD 	<
 $J< D[< <2 	 	 	 	TT'*T69DjT	tY%%	&T&4 4dI<L6L0M 4 15f
f
#&:f
	+.L	Lf
PQS4Z Q4 QH !%#XX X $J	X
 *X 
;	<X$> >sTz >t >&  ##0>0> 0> *	0>
 *0> 
0>f ]a););!%);7;);ORUYz);	cDcN"	#);\  ##'#KK K 	K
 *K D[K *KZ&&&)&6:&	*|+	,&P7 7(5d3iQUVYQZAZ;[2\ 7 ? ?d
 ?S	 ? ?&  $#;7;7 *;7 	;7
 ;7 ;7 *;7 
cT#tCH~-.	.;7z:?S :? :?d
 :?X\ :?xhS hx h2l lt lsTz l_cdgildl_m l\2$$  4 /@ <  < | N NN

 
r=   r   )	metaclassc                      ^  \ rS rSrSS\S\S\S-  4U 4S jjjrU 4S jrS\S	\S
\	4S jr
SS jrSS\S
S4S jjrSU 4S jjrS
\4S jrSrU =r$ )r   i  Nfsr3   rL   c                    >  UR                  X#S9U l        [        TU ]  " XR                  R                  5       40 UD6  U   g ! [         a+  nSUR                  SS5      ;   a  [        U S35      Uee S nAff = f)Nr   wr   rT   B.
Make sure the repository and revision exist before writing data.)r   r   rB  rW   ri   rj   r;   )r9   r  r3   rL   rn   r   ro   s         r:   rj   HfFileSystemFile.__init__  s    	!#!ID 	//99;FvF ! 	fjj,,'c\] 	s   A 
A8&A33A8c                 D   > [        U S5      (       d  g [        TU ]	  5       $ Nr   )hasattrri   __del__r9   ro   s    r:   r  HfFileSystemFile.__del__  s     t_--w  r=   startendr4   c                     SSU SUS-
   30U R                   R                  R                  5       EnU R                  5       n[	        SXC[
        R                  S9n[        U5        UR                  $ )Nrangebytes=-r   GETr  r   )	r  r   r  rw  r,   r   HF_HUB_DOWNLOAD_TIMEOUTr+   rU  )r9   r  r  r  rw  rs         r:   _fetch_rangeHfFileSystemFile._fetch_range  sk    veWAcAgY/
ggll,,.
 hhji>_>_`Ayyr=   c                 8    [         R                  " SSS9U l        g )Nzhffs-F)r  r   )tempfileNamedTemporaryFiler~  r8   s    r:   _initiate_upload!HfFileSystemFile._initiate_upload  s    !44GERr=   finalc                 N   U R                   R                  S5        U R                   R                  5       nU R                  R	                  U5        U(       Ga  U R                  R                  5         [        U R                  [        5      (       ad  U R                  R                  R                  U R                  R                  U R                  R                  U R                  R                  4/S9  OU R                  R                  R                  U R                  R                  U R                  R                   U R                  R"                  U R                  R$                  U R                  R&                  U R                  R(                  U R*                  R-                  S5      U R*                  R-                  S5      S9  [.        R0                  " U R                  R                  5        U R                  R3                  U R                  R5                  5       S9  g g )Nr   )addr   r   rL  r   )bufferr  rO  r~  writer  r   r   r^   r  r   r   r`   r   r3   rP  rM   rK   r   rJ   rL   rn   rW   r  remover   r;   )r9   r  blocks      r:   _upload_chunkHfFileSystemFile._upload_chunk  s     "U#NN  "$,,.LM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                 T  > U R                   S:X  ax  Ub  US:X  ao  U R                  S:X  a_  U R                  R                  U R                  SSS9 nUR                  5       nU =R                  [        U5      -  sl        UsSSS5        $ [        TU ]  U5      $ ! , (       d  f       N= f)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.
rK  Nr^  r   )r   )r   locr  rN  r3   rO  r   ri   )r9   lengthrT  r   ro   s       r:   rO  HfFileSystemFile.read  s     99&.FbLdhhRSmdii!<ffhCH$ =< w|F##	 =<s   0B
B'c                 L    U R                   R                  U R                  5      $ rh   r  rw  r3   r8   s    r:   rw  HfFileSystemFile.url      ww{{499%%r=   )r   r~  rh   r  )Fr^  )r?   r@   rA   rB   r   rD   rj   r  r  bytesr  r  r  r  rO  rw  rF   r   r   s   @r:   r   r     st    
< 
s 
cDj 
 
!# C E S4 D 4$&S & &r=   r   c                      ^  \ rS rSr    SS\S\S\S\S-  S\S\4U 4S	 jjjrSS
\S\4S jjrSS\4S jjr	SS\
\   S\S\4S jjrS\4S jrU 4S jrS rS rSrU =r$ )r   i  Nr  r3   r   rL   r   
cache_typec                   > US:w  a  [        SU 35      eUS:w  a  [        SU 35      eSU;   a  [        SU S35      e UR                  X$S9U l        U R                  R                  5       S S.U l        [        T	U ]   " XR                  R                  5       4X5US.UD6  S U l	        U   [        5       U l        S U l        [        5       U l        g ! [         a/  nSUR	                  S	S
5      ;   a  [        U S35      Ue S nANS nAff = f)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   rT   r  )r   r  r   r   r  )r   r   r   rB  rW   r;   detailsri   rj   responser   _exit_stack_stream_iterator	bytearray_stream_buffer)
r9   r  r3   r   rL   r   r  rn   r   ro   s
            r:   rj   HfFileSystemStreamFile.__init__  s1    ?YZdYefgg^_i^jkll$;Z[_Z``abcc	!#!ID !% 2 2 < < >M"",,.	
59]g	
kq	
 04$;8<'k ! 	fjj,,'c\] -	s    C 
D
%DD
r  whencec                 ^    US:X  a  US:X  a  g XR                   :X  a  US:X  a  g [        S5      e)Nr   r   zCannot seek streaming HF file)r  r   )r9   r  r  s      r:   r  HfFileSystemStreamFile.seek  s0    !8!((?v{899r=   r  c                    U R                   c  U R                  5         Sn  U R                   b  U R                  c  gU R                  U R                  U5      nU =R                  [        U5      -  sl        U$ ! [         aD    U R                   b  U R                   R                  5         U(       a  e U R                  5         Sn Of = fM  )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  r  )r9   r  retried_oncer   s       r:   rO  HfFileSystemStreamFile.read  s     == !!#$==(D,A,A,I,,T-B-BFKCH$
 $==,MM'')%%'#$ s   A9 ;A9 9ACCiteratorr4   c                    US:X  a  gUS:  aT  [        U R                  5      nU R                  R                  5         U H  nUR                  U5        M     [	        U5      $ U[        U R                  5      ::  a)  [	        U R                  SU 5      nU R                  SU2	 U$ [        U R                  5      nU R                  R                  5         U Hd  nU[        U5      -
  nU[        U5      :  a  UR                  U5        M3  UR                  USU 5        U R                  R                  XFS 5          O   [	        U5      $ )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   )r9   r  r  bufchunkresultneeds          r:   r  (HfFileSystemStreamFile._read_from_stream:  s#    Q;A:D//0C%%'!

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

5!

5$<(##**5<8  Szr=   c                 L    U R                   R                  U R                  5      $ rh   r  r8   s    r:   rw  HfFileSystemStreamFile.url\  r  r=   c                 x   > [        U S5      (       d  g U R                  R                  5         [        TU ]  5       $ r  )r  r  r  ri   r  r  s    r:   r  HfFileSystemStreamFile.__del___  s2    t_-- w  r=   c                     [         U R                  U R                  U R                  U R                  U R
                  R                  44$ rh   )reopenr  r3   r   	blocksizecacher   r8   s    r:   r  !HfFileSystemStreamFile.__reduce__f  s0    DIIt~~tzzWWWr=   c           	      @   U R                   R                  5         SU l        U R                  5       nU R                  R
                  R                  5       nU R                  S:  a  SU R                   S3US'   U R                  R                  [        SUU[        R                  S95      U l         [        U R                  5        U R                  R#                  5       U l        g! [         a,  nUR                  R                   S:X  a  SU l         SnAge SnAff = f)	z%Open a connection to the remote file.Nr   r  r  Ranger  r  i  )r  r   r  rw  r  r   r  r  r  enter_contextr-   r   r  r  r+   r   status_code
iter_bytes)r9   rw  r  r   s       r:   r  'HfFileSystemStreamFile._open_connectioni  s     	!!# $hhj'',,00288a<!'z3GG((66!99	
	. !% 8 8 :  	zz%%, $	s   2C' '
D1!DDD)r  r  r  r  r   r  )rK  Nr   r  )r   r  )r?   r@   rA   rB   r   rD   r  rj   r  rO  r   r  r  rw  r  r  r  rF   r   r   s   @r:   r   r     s    
 # !*!* !* 	!*
 *!* !* !* !*F: :S :$3 $8 (5/  3  PU  D&S &!X; ;r=   r   rL   r4   c                 R    [         R                  " U 5      (       a  U $ [        U 5      $ rh   )r#   r   
safe_quoter   s    r:   rY   rY     s#    288BB8\
S[H\\r=   sc                     [        U SS9$ )NrT   )safe)r   )r  s    r:   r
  r
    s    r=   r3   r   c                     U n[        U[        5      (       a  U  S3nO5[        U[        5      (       a  U  S3nO[        U[        5      (       a  U  S3n[	        U5      Ue)Nz (repository not found)z (revision not found)z (invalid repository id))r   r   r    r*   rB  )r3   r   msgs      r:   r   r     se    
C#.//-.	C.	/	/+,	C*	+	+./
C
 c)r=   r  r   r   r  c                 "    U R                  XX4S9$ )Nr  )rN  )r  r3   r   r   r  s        r:   r  r    s    774z7QQr=   c                 `    U " U0 UD6nUR                  5        H  u  pV[        XEU5        M     U$ rh   )r~   r   )rl   rm   rn   r   r  r   r   s          r:   r  r    s6    	d	f	B+113+& 4Ir=   )Yr  r  ru   collectionsr   collections.abcr   r   
contextlibr   copyr   dataclassesr   r	   r
   	itertoolsr   pathlibr   r   typingr   r   r   urllib.parser   r   fsspechttpxfsspec.callbacksr   r   r   fsspec.configr   fsspec.utilsr   rT   r   _commit_apir   r   errorsr   r   r   r   r    file_downloadr!   r"   hf_apir#   r$   r%   r&   r'   r(   r)   utilsr*   r+   r,   r-   utils.insecure_hashlibr.   r0   rH   r^   r{   AbstractFileSystemrc   rE   re   r   specAbstractBufferedFiler   r   rD   rY   r
  r  r   r  r  r  hffsr>   r=   r:   <module>r*     s   	    .    (   ' ' ' '   J J & #  C  0 v v v \ \ ' 6 6 6 &)A & &0 0%= 0 0 223c 32l 2jY
6,, Y
x H&v{{77 H&VR;V[[== R;j]C ]C ]# # * *)d*: *x *R| R3 Rc Rs RPS R ~r=   