
    Ցi              
       `   % S SK r S SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	  S SK
JrJr  S SKJr  S SKJr  S SKJrJr  S S	KJrJrJr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(J)r)  SSK*J+r+J,r,J-r-J.r.J/r/  SSK0J1r1J2r2  SSK3J4r4J5r5J6r6J7r7J8r8J9r9  SSK:J;r;J<r<J=r=J>r>  SSK?J@r@  \R                  " S\R                  5      rC\ " S S5      5       rD\ " S S\D5      5       rE\ " S S\D5      5       rF\G" \R                  5      rI\\JS'    " S S\I5      rK " S S \R                  \KS!9rL " S" S#\R                  R                  5      rO " S$ S%\R                  R                  5      rPS&\QS'\Q4S( jrRS)\QS'\Q4S* jrSS+\QS,\\T   S'\4S- jrUS.\LS+\QS/\QS0\VS1\Q4
S2 jrWS3 rX\L" 5       rYg)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                   <    \ 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/)r1   r2   rstripselfs    ^/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/huggingface_hub/hf_file_system.py	unresolve"HfFileSystemResolvedPath.unresolve5   s&    ))Adii[)0055     N)	__name__
__module____qualname____firstlineno____doc__str__annotations__r:   __static_attributes__r=   r<   r9   r/   r/   .   s    i
I
I63 6r<   r/   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 rSrg)"HfFileSystemResolvedRepositoryPath9   zLData structure containing information about a resolved path in a repository.	repo_typerepo_idrevisionpath_in_repoFinitr1   r2   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getrI   rJ   rQ   r1   rK   DEFAULT_REVISIONsafe_revisionrL   r2   )r8   	repo_paths     r9   __post_init__0HfFileSystemResolvedRepositoryPath.__post_init__G   s    5599$.."MPTP\P\\	$+Qt'9'9&:;DI]]i888$+Q}T]]'C&DEDI!I%%	r<   )r2   r1   )r>   r?   r@   rA   rB   rC   rD   r   r1   r2   rQ   r   rZ   rE   r=   r<   r9   rG   rG   9   sT    VNLM5!D#!5!D#! $)E#BM8C=B&r<   rG   c                   @    \ rS rSr% Sr\\S'   \" SS9r\\S'   S r	Sr
g	)
HfFileSystemResolvedBucketPathR   zHData structure containing information about a resolved path in a bucket.	bucket_idFrM   r1   c                 ,    SU R                   -   U l        g )Nzbuckets/)r_   r1   r7   s    r9   rZ   ,HfFileSystemResolvedBucketPath.__post_init__Y   s    /	r<   )r1   N)r>   r?   r@   rA   rB   rC   rD   r   r1   rZ   rE   r=   r<   r9   r]   r]   R   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$ )_Cacheda   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      r9   ri   _Cached.__init__q   s    $)&) 
r<   c                    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)pop	_tokenize	threading	get_identmain_threadidentcachablerj   _latesttype__call___get_instance_stateitemssetattr
_fs_token_storage_argsstorage_options)
rk   rl   rm   skipfs_tokenfs_token_main_threadobjinstance_stateattrstate_values
             r9   r{   _Cached.__call__y   s   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?   r@   rA   rB   ri   r{   rE   __classcell__rn   s   @r9   rd   rd   a   s     r<   rd   c                     ^  \ rS rSrSrSrSrSSSSS.S\\   S\	\
\S4   S	\\   S
\\
   4U 4S jjjr\S\S\4S j5       rS\S\S\\   S\\
\\   4   4S jrS\S\\
\\   4   4S jr S8S\S\\   S\	\\4   4S jjrS8S\\   SS4S jjr   S9S\S\S	\\   S\\   S\	S   4
S jjrS8S\S\\   SS4S jjr   S:S\S\
S\\   S\\   SS4
S jjr S;S\S\
S \
S\\   S\\	\\\\4   4      4
S! jjr     S<S\S\
S \
S\\   S
\\
   S\\   4S" jjrS\S#\S\
S\\	\ \!4      4S$ jr"S\S\#\\\\   \\   4      4U 4S% jjr$S8S\S\\   S\\   4U 4S& jjjr%     S=S\S\\   S'\
S\
S \
S\\   S\	\\   \\\\\4   4   4   4S( jjr&S8S)\S*\S\\   SS4S+ jjr'S\S\(4S, jr)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r0\1S3 5       r2S4 r3S5 r4S6 r5S7r6U =r7$ )@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)
```
rS   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   )rh   ri   r   ENDPOINTr   r   r%   _apir   r   _repo_and_revision_exists_cache_bucket_exists_cachedircache)r8   r   r   r   r   rl   r   rn   s          r9   ri   HfFileSystem.__init__   sg     	$2/2 6I$6$6
89	$&  	, RT! :<r<   threading_identr3   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   )rV   r   r   sortedr-   rC   encode	hexdigest)rk   r   rl   rm   keytokenize_argshs          r9   rs   HfFileSystem._tokenize   s     $ZZ
3Iy7I7Iz **W-w.4Vn=nsv{"n=t<M"))+,{{}	 >s   BrI   rJ   rK   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)rK   rI   timeoutTNF)r   r   	repo_infor   HF_HUB_ETAG_TIMEOUTr   r)   r    )r8   rI   rJ   rK   es        r9   _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   )r8   r_   r   s      r9   _bucket_existsHfFileSystem._bucket_exists  sr    555B		%%i0 8B)))4((33	 ' @7<ax)))4@s   A
 

A/A**A/r2   c                    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	;   ay  [        R!                  U	5      n
U
bL  USU
R#                  5       4;   a6  [        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[.        [0        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[        R2                  n[5        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_pathrK   r3   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   rK   s     r9   %_align_revision_in_path_with_revisionHHfFileSystem.resolve_path.<locals>._align_revision_in_path_with_revision3  sS     ##/4D4P$78H7IIijris t- -  O ,Or<   z<Access to buckets and repositories lists is not implemented.r5   r   bucketsr      N)r_   r2   z0Access to repositories lists is not implemented.rT      rS   )rQ   )r   rC   _strip_protocolNotImplementedErrorsplitjoinr   _raise_file_not_foundr]   r   rU   valuesREPO_TYPES_MAPPINGREPO_TYPE_MODELcountSPECIAL_REFS_REVISION_REGEXsearchgroupsublstripr   r   
isinstancer   r)   rW   rG   )r8   r2   rK   r   r_   bucket_existserrrI   rJ   r   matchrL   repo_and_revision_existrepo_id_with_namespacepath_in_repo_with_namespacerepo_id_without_namespacepath_in_repo_without_namespace_s                     r9   resolve_pathHfFileSystem.resolve_path  s   ,	&sm	7?}	c]	 ##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:   rr   _parentr2   r   rG   rI   rJ   rK   r   r_   )r8   r2   resolved_paths      r9   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   rK   )r   r   r   r   )r8   r2   r   r   rK   rm   s         r9   _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rK   deletecommit_messagecommit_description)rL   rJ   r   rI   rK   r   r   r2   )r   r   r]   r   batch_bucket_filesr_   r2   delete_filerL   rJ   r   rI   rK   rV   r   r:   )r8   r2   rK   rm   r   s        r9   _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   rK   r   )rL   zDelete  zrecursively rS   Nzup to depth r   r   )rJ   rI   r   
operationsrK   r   r   r   )r   expand_pathr   r]   isdirr2   r   r   r_   r   create_commitrJ   rI   r   rK   rV   r   r:   )r8   r2   r   r   rK   rm   r   pathsr   paths_in_reporL   r   r   s                r9   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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   rK   Nnamer   )r   r:   _ls_treer   r2   r   r   len)	r8   r2   r   r   rK   rm   r   outos	            r9   lsHfFileSystem.ls  s    4 ))$)B&&(		2--SgSFSC s:c":cV9c":: " 	2 %%%dD1--T 2aGaZ`aC!7cvY$%61c7C73x1}%dD1	2 #;s*   A C"AC#B:3B:9#CC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   rz   	directoryr   last_commitr5   T)r   r   rK   r   r   )prefixr   )r   expandrK   rI   filer   sizerz   blob_idlfsxet_hashr  security)r   r  rz   r  mtimeuploaded_atr   r   r  rz   tree_idr  )r   r  rz   r  )-r   r   r:   r1   r   extendr   popleftappendr   rG   r   osr2   commonprefixendswithr	   r6   r   r   
startswithlistrr   r   r]   _list_bucket_tree_with_foldersr_   r   list_repo_treerJ   rK   rI   r'   r  r	  r
  r  r  r  r#   r  r  r(   r  
setdefault)r8   r2   r   r   rK   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                             r9   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   r5   r   Nr  )rz   r2   r  zFile not found in bucket 'z': '')r   list_bucket_treer   r  r  r   r2   parentsr$   rC   r  r   )r8   r_   r  r   bucket_filesbucket_folders	min_depthr   bucket_entryparent_bucket_folder_strparent_bucket_folderbucket_folders               r9   r  +HfFileSystem._list_bucket_tree_with_folders  sS    yy11)y1Y24-3AS))	57(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.
rK   r   N)r   rV   r:   rh   walk)r8   r2   rl   rm   rn   s       r9   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.
rK   r   r   )r   rV   r:   rh   glob)r8   r2   r   rm   rn   s       r9   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   rz   r  r   rK   r  )r   r   r:   r   infor   FileNotFoundErrorr   )r8   r2   r   r?  r   r   rK   rm   r   r   r   r   namesr   s                 r9   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   rS   )src_path_in_reporL   src_revision)rJ   rI   rK   r   r   r   rbNpath_or_fileobjrL   rJ   r   rI   rK   r   r   r   )r   r   r]   r   rI   rJ   r   r   rK   rV   r   rL   openreadupload_filer   r   r:   )r8   rF  rG  rK   rm   resolved_path1resolved_path2	same_repor   fcontents              r9   cp_fileHfFileSystem.cp_file6  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)r8   r2   rm   rA  s       r9   modifiedHfFileSystem.modifiedr  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  rz   r  )rI   rK   )oidtitlerZ  )r  r  )r   r   )r  rK   rI   rS   )rL   rQ   r5   r  r  r  ) r   r:   rV   r   r2   r   rG   r   list_repo_commitsrJ   rI   rK   r&   	commit_idr`  
created_atr]   r   r   r   r   get_paths_inforL   rQ   r'   r  r	  r
  r  r  r  r  )r8   r2   r   rK   rm   r   r   r   r  r+  r   out1
paths_infor   r  ks                   r9   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!    g= 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)rV   r   rA  )r8   r2   rm   s      r9   existsHfFileSystem.exists  sD     	zz)U++%%d+IId%f%	s	   ;> 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.
rz   r  F)rA  OSErrorr8   r2   s     r9   r   HfFileSystem.isdir  s1    	99T?6*k99 		s    
&&c                 @     U R                  U5      S   S:H  $ !    g= 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.
rz   r  F)rA  rn  s     r9   isfileHfFileSystem.isfile$  s)    	99T?6*f44	s    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/)rI   rK   r   z/tree/r   )r   r   r]   r   r_   r   r2   r!   rJ   rL   rI   rK   r   replace)r8   r2   r   urls       r9   ru  HfFileSystem.url6  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.

rK   r   )callbackoutfileT)exist_okNFwbr   r  )ru  	temp_filedisplayed_filenameexpected_sizeresume_sizeheaders	_tqdm_bar)rV   setkeysr   r   r   r   rh   get_filer   r   r  makedirsrC   r
   r2   dirnamerN  tellr   rA  set_sizer"   ru  r:   r   _build_hf_headerstqdmseekclose)r8   rpathlpathrx  ry  rm   rK   unhandled_kwargs
close_fileinitial_posresolve_remote_pathr~  rn   s               r9   r  HfFileSystem.get_fileP  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   r7   s    r9   transactionHfFileSystem.transaction  s     ""LMMr<   c                     [        S5      e)z@Begin write transaction for deferring files, non-context versionr  r  r7   s    r9   start_transactionHfFileSystem.start_transaction  s     ""LMMr<   c                 p    [         [        U 5      U R                  U R                  U R	                  5       44$ rg   )make_instancerz   r   r   r|   r7   s    r9   
__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   r7   s    r9   r|    HfFileSystem._get_instance_state  s4     //78\8\/]$,T-F-F$G
 	
r<   )r   r   r   r   r   r   r   r   rg   )rK  NN)FNN)TFN)FFNNN)NFFFN)FNr3   N)8r>   r?   r@   rA   rB   root_markerprotocolr   rC   r   boolintri   classmethodrs   tuple	Exceptionr   r   rG   r]   r   r   r   r   r   r  dictr   r   r   r   r#   r$   r  r   r:  r=  rD  rV  r   r[  rA  rj  r   rq  ru  r   r  propertyr  r  r  r|   rE   r   r   s   @r9   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                      ^  \ rS rSr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fsr2   rK   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   rS   B.
Make sure the repository and revision exist before writing data.)r   r   rB  rV   rh   ri   r:   )r8   r  r2   rK   rm   r   rn   s         r9   ri   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   )hasattrrh   __del__r8   rn   s    r9   r  HfFileSystemFile.__del__  s     t_--w  r<   startendr3   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  ru  r+   r   HF_HUB_DOWNLOAD_TIMEOUTr*   rU  )r8   r  r  r  ru  rs         r9   _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|  r7   s    r9   _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   r2   rP  rL   rJ   r   rI   rK   rm   rV   r  remover   r:   )r8   r  blocks      r9   _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  r2   rO  r   rh   )r8   lengthrT  r   rn   s       r9   rO  HfFileSystemFile.read  s     99&.FbLdhhRSmdii!<ffhCH$ =< w|F##	 =<s   0B
B'c                 L    U R                   R                  U R                  5      $ rg   r  ru  r2   r7   s    r9   ru  HfFileSystemFile.url      ww{{499%%r<   )r   r|  rg   r  )Fr^  )r>   r?   r@   rA   r   rC   r   ri   r  r  bytesr  r  r  r  rO  ru  rE   r   r   s   @r9   r   r     st    
< 
s 
hsm 
 
!# C E S4 D 4$&S & &r<   r   c                      ^  \ rS rSr    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  r  r2   r   rK   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   rS   r  )r   r  r   r   r  )r   r   r   rB  rV   r:   detailsrh   ri   responser   _exit_stack_stream_iterator	bytearray_stream_buffer)
r8   r  r2   r   rK   r   r  rm   r   rn   s
            r9   ri   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	
 37$;;?'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   )r8   r  r  s      r9   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  )r8   r  retried_oncer   s       r9   rO  HfFileSystemStreamFile.read&  s     == !!#$==(D,A,A,I,,T-B-BFKCH$
 $==,MM'')%%'#$ s   A9 ;A9 9ACCiteratorr3   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   )r8   r  r  bufchunkresultneeds          r9   r  (HfFileSystemStreamFile._read_from_streamB  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      $ rg   r  r7   s    r9   ru  HfFileSystemStreamFile.urld  r  r<   c                 x   > [        U S5      (       d  g U R                  R                  5         [        TU ]  5       $ r  )r  r  r  rh   r  r  s    r9   r  HfFileSystemStreamFile.__del__g  s2    t_-- w  r<   c                     [         U R                  U R                  U R                  U R                  U R
                  R                  44$ rg   )reopenr  r2   r   	blocksizecacher   r7   s    r9   r  !HfFileSystemStreamFile.__reduce__n  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  ru  r  r   r  r  r  enter_contextr,   r   r  r  r*   r   status_code
iter_bytes)r8   ru  r  r   s       r9   r  'HfFileSystemStreamFile._open_connectionq  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?   r@   rA   r   rC   r   r  ri   r  rO  r   r  r  ru  r  r  r  rE   r   r   s   @r9   r   r     s    
 "& !*!* !* 	!*
 3-!* !* !* !*F: :S :$3 $8 (5/  3  PU  D&S &!X; ;r<   r   rK   r3   c                 P    [         R                  U 5      (       a  U $ [        U 5      $ rg   )r   r   
safe_quoter   s    r9   rX   rX     s#    288BB8\
S[H\\r<   sc                     [        U SS9$ )NrS   )safe)r   )r	  s    r9   r  r    s    r<   r2   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  )r2   r   msgs      r9   r   r     se    
C#.//-.	C.	/	/+,	C*	+	+./
C
 c)r<   r  r   r   r  c                 "    U R                  XX4S9$ )Nr  )rN  )r  r2   r   r   r  s        r9   r  r    s    774z7QQr<   c                 `    U " U0 UD6nUR                  5        H  u  pV[        XEU5        M     U$ rg   )r}   r~   )rk   rl   rm   r   r  r   r   s          r9   r  r    s6    	d	f	B+113+& 4Ir<   )Zr  rer  rt   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   rS   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/   rG   r]   rz   AbstractFileSystemrb   rD   rd   r   specAbstractBufferedFiler   r   rC   rX   r  r  r   r  r  r  hffsr=   r<   r9   <module>r)     s   	 	       (   ' E E '   J J #  C  0 Y Y \ \ ' !jj
 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<   