
    _j*              
       B   U d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZmZmZ d dlmZmZ d dlZd dlZd dlmZm Z m!Z! d dl"m#Z# d dl$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z=m>Z>m?Z?m@Z@mAZA ddlBmCZC e G d d                      ZDe G d deD                      ZEe G d deD                      ZF eGejH                  ZIeeJd<    G d deI          ZK G d  d!ejH        eK"          ZL G d# d$ejM        jN                  ZO G d% d&ejM        jN                  ZPd'eQd(eQfd)ZRd*eQd(eQfd+ZSd,eQd-eTdz  d(efd.ZUd/eLd,eQd0eQd1eVd2eQf
d3ZWd4 ZX eL            ZYdS )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parse_hf_uri)md5c                   4    e Zd ZU dZeed<   eed<   defdZdS )HfFileSystemResolvedPathz_Top level Data structure containing information about a resolved Hugging Face file system path.rootpathreturnc                 J    | j          d| j                             d          S )N/)r2   r3   rstripselfs    [/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/huggingface_hub/hf_file_system.py	unresolvez"HfFileSystemResolvedPath.unresolve+   s(    )))di))00555    N)__name__
__module____qualname____doc__str__annotations__r;    r<   r:   r1   r1   $   sI         ii
III
III63 6 6 6 6 6 6r<   r1   c                       e Zd ZU dZeed<   eed<   eed<   eed<    ed          Zeed<    ed          Zeed	<    ed
d          Z	ed
z  ed<   d Z
d
S )"HfFileSystemResolvedRepositoryPathzLData 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                     t           j                            | j        d          | j        z   }| j        r| d| j         | _        n;| j        t           j        k    r| dt          | j                   | _        n|| _        | j
        | _        d S )N @)r   REPO_TYPES_URL_PREFIXESgetrF   rG   rN   r2   rH   DEFAULT_REVISIONsafe_revisionrI   r3   )r9   	repo_paths     r:   __post_init__z0HfFileSystemResolvedRepositoryPath.__post_init__=   s    599$."MMPTP\\	 	"$;;t'9;;DII]i888$EE}T]'C'CEEDII!DI%			r<   )r=   r>   r?   r@   rA   rB   r	   r2   r3   rN   rW   rC   r<   r:   rE   rE   /   s         VVNNNLLLMMM5!!!D#!!!5!!!D#!!! !&d ? ? ?M3:???& & & & &r<   rE   c                   F    e Zd ZU dZeed<    ed          Zeed<   d ZdS )HfFileSystemResolvedBucketPathzHData structure containing information about a resolved path in a bucket.	bucket_idFrJ   r2   c                 $    d| j         z   | _        d S )Nzbuckets/)rZ   r2   r8   s    r:   rW   z,HfFileSystemResolvedBucketPath.__post_init__O   s    /			r<   N)	r=   r>   r?   r@   rA   rB   r	   r2   rW   rC   r<   r:   rY   rY   H   sQ         RRNNN5!!!D#!!!0 0 0 0 0r<   rY   _cached_basec                   (     e Zd ZdZ fdZd Z xZS )_Cacheda  
    Metaclass for caching HfFileSystem instances according to the args.

    This creates an additional reference to the filesystem, which prevents the
    filesystem from being garbage collected when all *user* references go away.
    A call to the :meth:`AbstractFileSystem.clear_instance_cache` must *also*
    be made for a filesystem instance to be garbage collected.

    This is a slightly modified version of `fsspec.spec._Cached` to improve it.
    In particular in `_tokenize` the pid isn't taken into account for the
    `fs_token` used to identify cached instances. The `fs_token` logic is also
    robust to defaults values and the order of the args. Finally new instances
    reuse the states from sister instances in the main thread.
    c                 H     t                      j        |i | i | _        d S N)super__init___cache)clsargskwargs	__class__s      r:   rb   z_Cached.__init__g   s,    $)&))) 


r<   c                 t   t          | |          }|                    dd          } | j        | t          j                    g|R i |} | j        | t          j                    j        g|R i |}|s$| j        r|| j        v r|| _	        | j        |         S t          j        | g|R i |}|sZ| j        rS|| j        v rJ| j        |                                         }|                                D ]\  }}	t          |||	           ||_        ||_        ||_        | j        r|s|| _	        || j        |<   |S )Nskip_instance_cacheF)r   pop	_tokenize	threading	get_identmain_threadidentcachablerc   _latesttype__call___get_instance_stateitemssetattr
_fs_token_storage_argsstorage_options)
rd   re   rf   skipfs_tokenfs_token_main_threadobjinstance_stateattrstate_values
             r:   rs   z_Cached.__call__o   s    c6**zz/77 3=i&9&;&;MdMMMfMM,s}S)2G2I2I2OaRVaaaZ`aa 	 	SZ)?)?"CK:h'' -5d555f55C 4CL 4-ASZ-O-O!$,@!A!U!U!W!W)7)=)=)?)? 4 4%D+C{3333%CN#C"(C| +D +&'*
8$Jr<   )r=   r>   r?   r@   rb   rs   __classcell__rg   s   @r:   r^   r^   W   sQ                   r<   r^   c                       e Zd ZdZdZdZddddddedz  deez  dz  dedz  d	edz  f fd
Z	e
dedefd            Zdedededz  deeedz  f         fdZdedeeedz  f         fdZ	 d9dededz  deez  fdZd9dedz  ddfdZ	 	 	 d:dedededz  dedz  ded         f
dZd9dededz  ddfdZ	 	 	 d;dedededz  dedz  ddf
dZ	 d<ded!ed"ededz  deeeeef         z           f
d#Z	 	 	 	 	 d=deded"ededz  d	edz  dedz  fd$Zded%ededeeez           fd&Z dede!eeee         ee         f                  f fd'Z"d9dededz  dee         f fd(Z#	 	 	 	 	 d>dededz  d)ed!ed"ededz  dee         eeeeef         f         z  fd*Z$d9d+ed,ededz  ddfd-Z%dede&fd.Z'd?ded"ededz  deeef         fd/Z(d0 Z)d1 Z*d2 Z+dedefd3Z,e-dfd@ fd4Z.e/d5             Z0d6 Z1d7 Z2d8 Z3 xZ4S )AHfFileSystemaz
  
    Access a remote Hugging Face Hub repository as if were a local file system.

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

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

    * Models, Datasets and Spaces repositories:

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

    * Buckets (generic storage):

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

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

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

    Usage:

    ```python
    >>> from huggingface_hub import hffs

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

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

    Specify a token for authentication:
    ```python
    >>> from huggingface_hub import HfFileSystem
    >>> hffs = HfFileSystem(token=token)
    ```
    rP   hfN)endpointtoken
block_sizeexpand_infor   r   r   r   c                     t                      j        |i | |pt          j        | _        || _        t          ||          | _        || _        || _	        i | _
        i | _        i | _        d S )N)r   r   )ra   rb   r   ENDPOINTr   r   r&   _apir   r   _repo_and_revision_exists_cache_bucket_exists_cachedircache)r9   r   r   r   r   re   ry   rg   s          r:   rb   zHfFileSystem.__init__   s{     	$2/222 6I$6
85999	$& rt,NP! :<r<   threading_identr4   c                 B                        d          pt          j        d<                        d          d<   fdt                    D             | ||f}t	          t          |                                                    }|                                S )zDeterministic token for cachingr   r   c                 "    i | ]}||         S rC   rC   ).0keyrf   s     r:   
<dictcomp>z*HfFileSystem._tokenize.<locals>.<dictcomp>   s    ===s#vc{===r<   )rS   r   r   sortedr/   rA   encode	hexdigest)rd   r   re   rf   tokenize_argshs      `  r:   rk   zHfFileSystem._tokenize   s     $ZZ
33Iy7Iz **W--w====fVnn===otV<M""))++,,{{}}r<   rF   rG   rH   c                    |||f| j         vr	 | j                            |||t          j                   d| j         |||f<   d| j         ||d f<   nj# t
          t          f$ r(}d|f| j         |||f<   d|f| j         ||d f<   Y d }~n6d }~wt          $ r&}d|f| j         |||f<   d| j         ||d f<   Y d }~nd }~ww xY w| j         |||f         S )N)rH   rF   timeoutTNF)r   r   	repo_infor   HF_HUB_ETAG_TIMEOUTr   r*   r    )r9   rF   rG   rH   es        r:   _repo_and_revision_existz%HfFileSystem._repo_and_revision_exist   sT    w)1UUU^	##h)YMj $    Xb4i(5STS]4i$5OPP ,->? \ \ \W\^_W_4i(5STSXZ[S[4i$5OPPPPPP( ^ ^ ^W\^_W_4i(5STS]4i$5OPPPPPP^ 3Y4RSSs#   (A B8"BB8B33B8rZ   c                     || j         vrI	 | j                            |           d| j         |<   n## t          $ r}d|f| j         |<   Y d }~nd }~ww xY w| j         |         S )Nr   F)r   r   bucket_infor   )r9   rZ   r   s      r:   _bucket_existszHfFileSystem._bucket_exists
  s    D555B	%%i000 8B))44 ' @ @ @7<ax))444444@ (33s   0 
AAAr3   c                    |                      |          }|st          d          |                    d          dk    rt          d| d          t	          t
          j         |           }|j        rJ|                     |j	                  \  }}|st          ||           t          |j	        |j                  S ||j        |j        |k    r|                    d          d         t
          j        v r|                    dd          d         n|}|                    d	d          \  }}d|v r|                    dd          n|d
f\  }	}
t!          |	          }||k    rt          d| d| d          |                     |j        ||          \  }}|st          ||           t'          |j        |||
|	          S |j        	||j        }|                     |j        |j	        |          \  }}|st          ||           d}d	|v r|j        |                    d          d         t
          j        v r|                    dd          d         n|}|                    d	d          d         }|j        r |dt)          |j                  dz             n|}||nt
          j        }t'          |j        |j	        ||j        |          S )a  
        Resolve a Hugging Face file system path into its components.

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

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

        Raises:
            `ValueError`:
                If path contains conflicting revision information.
            `NotImplementedError`:
                If trying to list repositories.
        z<Access to buckets and repositories lists is not implemented.r6   r   z-Repository id must be 'namespace/name', got 'z<'. Single-segment ids (e.g. 'gpt2') are no longer supported.)rZ   r3   Nr   rQ   rP   zRevision specified in path ("z ") and in `revision` argument ("z") are not the same.)rN   )_strip_protocolNotImplementedErrorcount
ValueErrorr.   r   HF_PROTOCOL	is_bucketr   id_raise_file_not_foundrY   rI   rH   splitHF_URI_TYPE_PREFIXESr   r   rr   rE   lenrT   )r9   r3   rH   parsedbucket_existserrpath_without_typerG   after_atrevision_in_pathrI   revision_in_path_decodedrepo_and_revision_existraw_revisionraw_after_ats                  r:   resolve_pathzHfFileSystem.resolve_path  se   * ##D)) 	f%&deee::c??a C  C  C  C   !6>>>??  	a!%!4!4VY!?!?M3  1%dC0001FIFL_```` FO$?FOW_D_D_
 :>C9KyOm9m9m

3 2 21 5 5sw 1 7 7Q ? ?GXGJhX^^C-C-C-C]egi\j*l'./?'@'@$'833  M4L  M  Mnv  M  M  M   ,0+H+HV]_g+h+h(#S* 1%dC0005WhL\    ?&8+;H'+'D'DV[RXR[]e'f'f$& 	-!$,,, $($;;6?69=C9KyOm9m9m

3 2 21 5 5sw,223::1=LNTNas<(IC0C,D,Dq,H*I(IJJgsL'3889S1KHf.AQ]
 
 
 	
r<   c                 V   |s4| j                                          | j                                         dS |                     |          }|                                }|r2| j                             |d           |                     |          }|2|j        st          |t                    rW| j                            |j
        |j        dfd           | j                            |j
        |j        |j        fd           dS | j                            |j        d           dS dS )ac  
        Clear the cache for a given path.

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

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

        N)r   clearr   r   r;   rj   _parentr3   
isinstancerE   rF   rG   rH   r   rZ   )r9   r3   resolved_paths      r:   invalidate_cachezHfFileSystem.invalidate_cachec  sX     	QM!!!06688888 --d33M **,,D *!!$---||D))  *
 !% 	Qm-OPP Q8<<&0-2GNPT   8<<&0-2GI_`bf     -11-2I4PPPPP	Q 	Qr<   rbmode)HfFileSystemFileHfFileSystemStreamFilec                     ||n| j         }|||d<   d|v rt          d          |dk    rt          | |f||d|S t          | |f||d|S )Nr   az/Appending to remote files is not yet supported.r   )r   rH   )r   r   r   r   )r9   r3   r   r   rH   rf   s         r:   _openzHfFileSystem._open  s     $.#9ZZt
!#-F< $;;%&WXXX??)$]4(]]V\]]]#D$WTHWWPVWWWr<   c                    |                      ||          }t          |t                    r(| j                            |j        |j        g           n`| j                            |j        |j	        | j
        |j        |j        |                    d          |                    d                     |                     |                                           d S )NrH   deletecommit_messagecommit_description)rI   rG   r   rF   rH   r   r   r3   )r   r   rY   r   batch_bucket_filesrZ   r3   delete_filerI   rG   r   rF   rH   rS   r   r;   )r9   r3   rH   rf   r   s        r:   _rmzHfFileSystem._rm  s    ))$)BBm%CDD 	I(()@-J\I](^^^^I!!*7%-j'1&/%zz*:;;#)::.B#C#C "    	=#:#:#<#<=====r<   F	recursivemaxdepthc                 f                          ||          }                     ||||          }t          |t                    r0 fd|D             } j                            |j        |           n fd|D             }	d |	D             }
d| d}||rd	nd
z  }||d| dnd
z  } j                            |j        |j	         j
        |
|j        |                    d|          |                    d                                          |                                           dS )a  
        Delete files from a repository.

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

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

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

        r   )r   r   rH   c                 n    g | ]1}                     |                              |          j        2S rC   isdirr   r3   r   r3   r9   s     r:   
<listcomp>z#HfFileSystem.rm.<locals>.<listcomp>  s<    ]]]tDJJW[L\L\]d''--2]]]r<   r   c                 n    g | ]1}                     |                              |          j        2S rC   r   r   s     r:   r   z#HfFileSystem.rm.<locals>.<listcomp>  s?    ddddSWS]S]^bScScdT..t449dddr<   c                 .    g | ]}t          |           S ))rI   )r   )r   rI   s     r:   r   z#HfFileSystem.rm.<locals>.<listcomp>  s$    mmm|/\JJJmmmr<   zDelete  zrecursively rP   Nzup to depth r   r   )rG   rF   r   
operationsrH   r   r   r   )r   expand_pathr   rY   r   r   rZ   create_commitrG   rF   r   rH   rS   r   r;   )r9   r3   r   r   rH   rf   r   pathsr   paths_in_repor   r   s   `           r:   rmzHfFileSystem.rm  s~   6 ))$)BB  XX` aam%CDD 	]]]]u]]]FI(()@(PPPPddddedddMmm_lmmmJ.t...N	AnnrANH<P8X8888VXXNI##%-'1j%&/%zz*:NKK#)::.B#C#C $    	=#:#:#<#<=====r<   Tdetailrefreshc                    |                      |          }|                                	  | j        f||d|}n# t          $ r |j        st          d           	  | j        |                               f||d|}n# t          $ r g }Y nw xY wfd|D             }t          |          dk    rt          d           Y nw xY w|r|nd |D             S )a  
        List the contents of a directory.

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

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

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

        Returns:
            `list[Union[str, dict[str, Any]]]`: List of file paths (if detail=False) or list of file information
            dictionaries (if detail=True).
        r   )r   rH   Nc                 ,    g | ]}|d          k    |S namerC   r   or3   s     r:   r   z#HfFileSystem.ls.<locals>.<listcomp>  s'    777QvY$%6%61%6%6%6r<   r   c                     g | ]
}|d          S r   rC   r   r   s     r:   r   z#HfFileSystem.ls.<locals>.<listcomp>  s    ":":":1V9":":":r<   )r   r;   _ls_treer   r3   r   r   r   )r9   r3   r   r   rH   rf   r   outs    `      r:   lszHfFileSystem.ls  s>   4 ))$)BB&&((	2$-SgSSFSSCC! 
	2 
	2 
	2 % 2%dD111#dmDLL$6$6eRZee^dee%   7777c777C3xx1}}%dD111
	2 :ss":":c":":"::s5   A   !C"$BCBCB4CCc           
          ||n j          j         nd}                     ||          }|                                }|j        }|r|nd}g }	| j        v r[|sX j        |         }
|	                    |
           g }|rdt          fd|
D                       }|r|                                \  }||k    rt|d          j        vr|                    |d                    nI j        |d                  }
|	                    |
           |                    fd|
D                        |g }|r#t          |t                    r fd|	D             }|r|s|rN|rKt          j                            ||z             }|                    d	          s||k    s|t          ||          v r|                    d	          n                     |          |/t%          |          d                              d	          }||z  }fd
|	D             }	t)           j                  D ]5}|                    d	z             r j                            |d            6 j                            d            |	                                         |d|||                     nt          |t0                    r#                     |j        |j        |          }n4 j                            |j        |j        |||j        |j                  }|D ]F}|d	z   |j        z   }t          |t@                    r*||j!        d|j"        |j#        |j$        |j%        |j&        d}ngt          |tN                    r||j!        d|j$        |j(        |j)        d}n4t          |tT                    r|dd|j+        |j%        d}n|dd|j)        d}                     |d                   } j        ,                    |g                               |           |t%          |          d                              d	          ||k    r|	                    |           H|	S )NFr   r      c                 0    g | ]}|d          dk    |fS rr   	directoryrC   r   	path_infodepths     r:   r   z)HfFileSystem._ls_tree.<locals>.<listcomp>  s/    oooIiX^N_cnNnNneY'NnNnNnr<   r   c                 6    g | ]}|d          dk    dz   |fS )rr   r   r   rC   r   s     r:   r   z)HfFileSystem._ls_tree.<locals>.<listcomp>)  s<     !" !" !"(1'0'8K'G'G &+QY	$:'G'G'Gr<   c                 V    g | ]%}|d          
                     |d                   &S )last_commitNr   )r   )r   r   r9   s     r:   r   z)HfFileSystem._ls_tree.<locals>.<listcomp>3  s3    $f$f$fQ}M]MeT\\!F)%<%<MeMeMer<   r6   c                 P    g | ]"}|d                               dz              |#S )r   r6   )
startswith)r   r   common_paths     r:   r   z)HfFileSystem._ls_tree.<locals>.<listcomp>D  s6    UUUQQvY-A-A+PSBS-T-TUqUUUr<   T)r   r   rH   r   r   )prefixr   )r   expandrH   rF   filer   sizerr   blob_idlfsxet_hashr   security)r   r  rr   r  mtimeuploaded_atr   r   r   r  rr   tree_idr   )r   r  rr   r	  )-r   r   r;   r2   r   extendr   popleftappendr   rE   osr3   commonprefixendswithr   r7   r   r   r   listr   rj   r   rY   _list_bucket_tree_with_foldersrZ   r   list_repo_treerG   rH   rF   r(   r  r  r  r  r   r  r$   r  r	  r)   r  
setdefault)r9   r3   r   r   rH   r   r   r   	root_pathr   cached_path_infosdirs_not_in_dircachedirs_to_visitdir_infodirs_not_expandedcommon_prefixcommon_path_depthcached_pathtreer   
cache_pathcache_path_infoparent_pathr   r   s   `                      @@r:   r   zHfFileSystem._ls_tree  sz    '2KKTM]Mi9I9Iot 	 ))$)BB&&((!&	(/88a4=    $d 3JJ()))#%    %oooo9Jooo! ! $ &3&;&;&=&=OE8'5H+<+<#F+4=@@0778HIIII04hv>N0O-JJ'8999)00!" !" !" !"5F!" !" !"   $   !# gz-9[\\ g$f$f$f$fc$f$f$f! 2  HY  !# 4 45IL]5] ^ ^ %--c225$	11$.BDU(V(VVV "((--- m44  '(3CIIKK(@(F(Fs(K(K% 11HUUUU#UUU#'#6#6 = =K"--kC.?@@ =))+t<<<!!+t444

MM#"+ $!)$/!) "  	 	 	 -)GHH ::!+(-' ;   y//!)!&'&*3+5 0   " )0 )0	&_y~=
i22 " * ) &#,#4(}$-$6'0'<$-$6	' 	'OO  	:66  * ) &$-$6!*'0'<' 'OO  	:66  * ! +#,#4'0'<' 'OO !+ ! +'0'<	' 'O #ll?6+BCC((b99@@QQQ"3t99;;/55c::#u'8'8JJ///
r<   r   c                 \   | j                             |||          }i }|rd|                    d          z   nd}g }|D ]}|                    |           |st	          t          |j                  j                  d| dz
           D ]}	t          dt          |	          |j
                  }
|
j        |vr |                    |
           |
||
j        <   O|
j
        0||
j                 }|j
        |j
        |
j
        k     r|
j
        |_
        |st          d| d	| d
          |S )z<Same as `HfApi.list_bucket_tree` but always includes folders)r   r   r6   r   Nr   )rr   r3   r	  zFile not found in bucket 'z': '')r   list_bucket_treer   r  r  r   r3   parentsr%   rA   r	  r   )r9   rZ   r   r   bucket_filesbucket_folders	min_depthr   bucket_entryparent_bucket_folder_strparent_bucket_folderbucket_folders               r:   r  z+HfFileSystem._list_bucket_tree_with_folders  s    y11)Vy1YY24-3:AS))))	/1( 	U 	ULJJ|$$$   -1|?P1Q1Q1Y,Z,Z[k^g]gjk]k[k,l U U('3$3/G+H+HVbVn( ( ($
 (,NBBJJ3444@TN#7#<= (3?$23G3L$MM$08%14H4TTT4H4T1#U&  	\$%Z)%Z%ZQW%Z%Z%Z[[[
r<   c              /      K   |                      ||                    d                                                    } t                      j        |g|R i |E d{V  dS )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.
        rH   r   N)r   rS   r;   ra   walk)r9   r3   re   rf   rg   s       r:   r/  zHfFileSystem.walk  sw         

:0F0F GGQQSS577<6t666v66666666666r<   c                     |                      ||                    d                                                    } t                      j        |fd|i|S )ah  
        Find files by glob-matching.

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

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

        Returns:
            `list[str]`: List of paths matching the pattern.
        rH   r   r   )r   rS   r;   ra   glob)r9   r3   r   rf   rg   s       r:   r1  zHfFileSystem.glob  sX       

:0F0F GGQQSSuww|D>>8>v>>>r<   withdirsc                    ||dk     rt          d          |                     ||          }|                                }	  | j        |fd||d||sd D             n" | j        |fi |}	|	d         d	k    r|	gz   nd
 D             nE# t
          $ r8 	  | j        |fd|i|d         dk    r|i ini n# t          $ r i Y nw xY wY nw xY wt                    }
|s|
S fd|
D             S )a  
        List all files below path.

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

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

        Returns:
            `Union[list[str], dict[str, dict[str, Any]]]`: List of paths or dict of file information.
        Nr   zmaxdepth must be at least 1r   T)r   r   r   c                 *    g | ]}|d          dk    |S r   rC   r   s     r:   r   z%HfFileSystem.find.<locals>.<listcomp>	  s&    BBBQ6k)A)Aq)A)A)Ar<   rr   r   c                      i | ]}|d          |S r   rC   r   s     r:   r   z%HfFileSystem.find.<locals>.<dictcomp>  s    ---A1V9a---r<   rH   r  c                 "    i | ]}||         S rC   rC   )r   r   r   s     r:   r   z%HfFileSystem.find.<locals>.<dictcomp>  s    666D#d)666r<   )r   r   r;   r   infor   FileNotFoundErrorr   )r9   r3   r   r2  r   r   rH   rf   r   r   namesr   s              @r:   findzHfFileSystem.find  s   @ HqLL:;;;))$)BB&&((	.$-cgPXcc\bccC  UBB#BBB &DId55f55	+4V+<+K+KykC''QT-----CC! " 	 	 	49T??H???G6QQ*CCC$   	" s 	7L66666666s6   B 
C !CCCCCCCpath1path2c                    |                      ||          }|                      ||          }t          |t                    st          |t                    rt          d          |j        |j        k    o|j        |j        k    }|rd| d| }| j                            |j        |j        |j        |	                    d|          |	                    dd          t          |j        |j        |j                  g	           n|                     |d
|j                  5 }	|	                                }
ddd           n# 1 swxY w Y   d| d| }| j                            |
|j        |j        | j        |j        |j        |	                    d|          |	                    d                     |                     |                                           |                     |                                           dS )a  
        Copy a file within or between repositories.

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

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

        r   z)Copy from/to buckets is not available yetzCopy z to r   r   rP   )src_path_in_reporI   src_revision)rG   rF   rH   r   r   r   r   Npath_or_fileobjrI   rG   r   rF   rH   r   r   r   )r   r   rY   r   rF   rG   r   r   rH   rS   r   rI   openreadupload_filer   r   r;   )r9   r;  r<  rH   rf   resolved_path1resolved_path2	same_repor   fcontents              r:   cp_filezHfFileSystem.cp_file  s{     **58*DD**58*DDn&DEE 	S:J
 J
 	S &&QRRR $(@@u^E[_m_uEu 	  	7U7777NI##&.(2'0%zz*:NKK#)::.BB#G#G')7)D%3%@%3%<   $     5$1HII #Q&&((# # # # # # # # # # # # # # #7U7777NI!! '+8&.j(2'0%zz*:NKK#)::.B#C#C " 	 	 	 	>#;#;#=#=>>>>#;#;#=#=>>>>>s   'EEEc                      | j         |fi i |ddi}d|v r(|d         t          d| d          |d         j        S d|v r|d         r|d         S d|v r|d         r|d         S t          d	| d
| d          )ak  
        Get the last modified time of a file.

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

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

        Returns:
            `datetime`: Last modified time of the file.
        r   Tr   Nz9'modified' is not implemented for repository paths like 'r$  r  r	  z'Cannot determined 'modified' for path 'z	' (info: ))r7  r   date)r9   r3   rf   r7  s       r:   modifiedzHfFileSystem.modifiedQ  s     tyAA!@F!@M4!@!@AAD  M"*)*mfj*m*m*mnnn&++__g_= d""tM':"&&%&fPT&f&f_c&f&f&fgggr<   c           	         |                      |          }|                                |                    d| j        | j        nd          }|j        sdddt          |t                    rdd<   t          |t                    r\|rZ| j                            |j	        |j
        |j        	          d
         }i dt          |j        |j        |j                  dnt          |t                     ra|                               }|                     ||           fd| j        |         D             }	|	st)          d           |	d         nd|                               }|s|| j        vr|                     |           || j        v r3fd| j        |         D             }	|	st)          d           |	d         |s|r	rd         | j                            |j	        |j        ||j        |j
                  }
|
st)          d           |
d         }t          |j
        |j	        |j        d|j                                                  }t          |t0                    r5|dz   |j        z   |j        d|j        |j        |j        |j        |j        dn|dz   |j        z   dd|j        |j        d|sfddD             J S )aS  
        Get information about a file or directory.

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

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

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

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

        r   r   NFr   r   )r   r  rr   r   )rF   rH   )oidtitlerM  )r  r   )r   c                 ,    g | ]}|d          k    |S r   rC   r   s     r:   r   z%HfFileSystem.info.<locals>.<listcomp>  s'    OOO!QvY$=N=NA=N=N=Nr<   c                 ,    g | ]}|d          k    |S r   rC   r   s     r:   r   z%HfFileSystem.info.<locals>.<listcomp>  s'    SSSa6dARARARARARr<   )r   rH   rF   rP   )rI   rN   r6   r  r  r
  c                 "    i | ]}||         S rC   rC   )r   kr   s     r:   r   z%HfFileSystem.info.<locals>.<dictcomp>  s    GGG1c!fGGGr<   ) r   r;   rS   r   r3   r   rE   r   list_repo_commitsrG   rF   rH   r'   	commit_idrR  
created_atrY   r   r   r   r   get_paths_inforI   rN   r(   r  r  r  r  r   r  r  )r9   r3   r   rH   rf   r   r   r   r"  out1
paths_infor   r  r   s    `           @r:   r7  zHfFileSystem.infoj  s   , ))$)BB&&((jjt/?/K4++QV
 
 ! N	H # C
 -)KLL *%)M"-)KLL 
Q\ 
"i99!)]5LWdWm :  ##1'19JQ\Qg$ $ $   'EFF :	H,,t,,KGGKG111OOOOt}[9OOOD 2%dD111q'CCC,,t,,K %;dm#C#C$$$dm++SSSS4=#=SSS 6)$5551g &H#+++#+#mBTB\!Y55!)!.&*3+5 6  
 " 6)$555&qM	>!+!)!*!#"/"=   )++  i22  )C). @ ) &#,#4(}$-$6'0'<$-$6	 	CC !*C). @ ! +#,#4'0'< C # HGGGG.FGGGC
r<   c                     	 |                     dd          r|                     |            | j        |fi | dS # t          $ r Y dS w xY w)a  
        Check if a file exists.

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

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

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

        Returns:
            `bool`: True if file exists, False otherwise.
        r   FT)rS   r   r7  OSError)r9   r3   rf   s      r:   existszHfFileSystem.exists  sr     	zz)U++ ,%%d+++DId%%f%%%4 	 	 	55	s   9= 
A
Ac                 d    	 |                      |          d         dk    S # t          $ r Y dS w xY w)ai  
        Check if a path is a directory.

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

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

        Returns:
            `bool`: True if path is a directory, False otherwise.
        rr   r   Fr7  r^  r9   r3   s     r:   r   zHfFileSystem.isdir  sC    	99T??6*k99 	 	 	55	   ! 
//c                 d    	 |                      |          d         dk    S # t          $ r Y dS w xY w)a`  
        Check if a path is a file.

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

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

        Returns:
            `bool`: True if path is a file, False otherwise.
        rr   r  Fra  rb  s     r:   isfilezHfFileSystem.isfile  sC    	99T??6*f44 	 	 	55	rc  c                 Z   |                      |          }t          |t                    r'| j         d|j         dt          |j                   }n-t          |j        |j	        |j
        |j        | j                  }|                     |          r|                    ddd          }|S )z
        Get the HTTP URL of the given path.

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

        Returns:
            `str`: HTTP URL to access the file or directory on the Hub.
        z	/buckets/z	/resolve/)rF   rH   r   z/tree/r   )r   r   rY   r   rZ   r   r3   r!   rG   rI   rF   rH   r   replace)r9   r3   r   urls       r:   rh  zHfFileSystem.url  s     ))$//m%CDD 		]jj]-DjjuUbUgOhOhjjCC%*'1&/  C ::d 	8++k8Q77C
r<   c                    |                     d          }t          |                                          dhz
  }t          |t          t
          f          rt          |          dk    r t                      j        ||f||d|S t          |          r|}n-| 
                    |          rt          j        |d           dS t          |t          t          f          r3t          j        t          j                            |          d           d}|t#          |d          }d}|                                }	|                     ||	          }
|                     ||	          d
         }|                    |           	 t-          |                     |
                                          |||d| j                                        t          |t
                    r|j        nd           |                    |	           |r|                                 dS dS # |r|                                 w w xY w)ad  
        Copy single remote file to local.

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

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

        rH   r   )callbackoutfileT)exist_okNFwbr   r  )rh  	temp_filedisplayed_filenameexpected_sizeresume_sizeheaders	_tqdm_bar)rS   setkeysr   r   r   r   ra   get_filer   r   r  makedirsrA   r   r3   dirnamerB  tellr   r7  set_sizer"   rh  r;   r   _build_hf_headerstqdmseekclose)r9   rpathlpathrj  rk  rf   rH   unhandled_kwargs
close_fileinitial_posresolve_remote_pathrp  rg   s               r:   rv  zHfFileSystem.get_file/  sF   $ ::j))v{{}}--<(\<$@AA 	`SIYEZEZ]^E^E^ $577#E5_8W__X^___ e 	GGZZ 	K----4ec4[)) 	?K..>>>> 
?5$''GJllnn #///II		%(	;;FC-(((	 HH0::<<==!#(+	3355+5h+M+MW(--SW    LL%%%      z   s   BH( (Ic                      t          d          )zA context within which files are committed together upon exit

        Requires the file class to implement `.commit()` and `.discard()`
        for the normal and exception cases.
        (Transactional commits are not supported.r   r8   s    r:   transactionzHfFileSystem.transactionm  s     ""LMMMr<   c                      t          d          )z@Begin write transaction for deferring files, non-context versionr  r  r8   s    r:   start_transactionzHfFileSystem.start_transactionx  s     ""LMMMr<   c                 n    t           t          |           | j        | j        |                                 ffS r`   )make_instancerr   rx   ry   rt   r8   s    r:   
__reduce__zHfFileSystem.__reduce__~  s8    JJ $$&&	
 
 	
r<   c                 z    t          | j                  t          | j                  t          | j                  dS )N)r   r   r   )r   r   r   r   r8   s    r:   rt   z HfFileSystem._get_instance_state  s:     ///78\/]/]$,T-F$G$G
 
 	
r<   r`   )r   NN)FNN)TFN)FFNNN)NFFFN)FNr4   N)5r=   r>   r?   r@   root_markerprotocolrA   boolintrb   classmethodrk   tuple	Exceptionr   r   rE   rY   r   r   r   r   r   r   r  dictr   r   r   r   r$   r%   r  r   r/  r1  r:  rJ  r
   rN  r7  r_  r   re  rh  r   rv  propertyr  r  r  rt   r   r   s   @r:   r   r      s       @ @D KH
  $#'!%#'< < < *< czD 	<
 $J< D[< < < < < <2 	 	 	 	 	 [	TT'*T69DjT	tY%%	&T T T T&4 4dI<L6L0M 4 4 4 4 15M
 M
M
#&:M
	+.L	LM
 M
 M
 M
^Q QS4Z Q4 Q Q Q QH !%#X XX X $J	X
 *X 
;	<X X X X$> > >sTz >t > > > >&  ##0> 0>0> 0> *	0>
 *0> 
0> 0> 0> 0>f ]a); ););!%);7;);ORUYz);	cDcN"	#); ); ); );\  ##'#K KK K 	K
 *K D[K *K K K KZ&&&)&6:&	*|+	,& & & &P7 7(5d3iQUVYQZAZ;[2\ 7 7 7 7 7 7 ? ? ?d
 ?S	 ? ? ? ? ? ?&  $#;7 ;7;7 *;7 	;7
 ;7 ;7 *;7 
cT#tCH~-.	.;7 ;7 ;7 ;7z:? :?S :? :?d
 :?X\ :? :? :? :?xhS hx h h h h2l l lt lsTz l_cdgildl_m l l l l\  2  $  $     4 /@ <  <  <  <  <  <  < | N N XNN N N
 
 

 
 
 
 
 
 
r<   r   )	metaclassc                        e Zd Zddedededz  f fdZ fdZdeded	efd
Z	ddZ
dded	dfdZd fd	Zd	efdZ xZS )r   Nfsr3   rH   c                 (   	 |                     ||          | _        n># t          $ r1}d|                    dd          v rt          | d          | d }~ww xY w t	                      j        || j                                        fi | |  d S )Nr   wr   rP   B.
Make sure the repository and revision exist before writing data.)r   r   r8  rS   ra   rb   r;   )r9   r  r3   rH   rf   r   rg   s         r:   rb   zHfFileSystemFile.__init__  s    	!#!I!ID  	 	 	fjj,,,,']]]  	 	T/99;;FFvFFFs     
A,AAc                 h    t          | d          sd S t                                                      S Nr   )hasattrra   __del__r9   rg   s    r:   r  zHfFileSystemFile.__del__  s.    t_-- 	Fww   r<   startendr4   c                     dd| d|dz
   i| j         j                                        }|                                 }t	          d||t
          j                  }t          |           |j        S )Nrangebytes=-r   GETrr  r   )	r  r   r{  rh  r,   r   HF_HUB_DOWNLOAD_TIMEOUTr+   rI  )r9   r  r  rr  rh  rs         r:   _fetch_rangezHfFileSystemFile._fetch_range  sy    /e//cAg//
gl,,..
 hhjjWi>_```Ayr<   c                 <    t          j        dd          | _        d S )Nzhffs-F)r   r   )tempfileNamedTemporaryFilern  r8   s    r:   _initiate_uploadz!HfFileSystemFile._initiate_upload  s    !4GERRRr<   Ffinalc                 \   | j                             d           | j                                         }| j                            |           |r[| j                                         t          | j        t                    rC| j	        j
                            | j        j        | j        j        | j        j        fg           n| j	        j
                            | j        j        | j        j        | j        j        | j	        j        | j        j        | j        j        | j                            d          | j                            d                     t/          j        | j        j                   | j	                            | j                                                   d S d S )Nr   )addr   r   r@  r   )bufferr}  rC  rn  writer~  r   r   rY   r  r   r   rZ   r   r3   rD  rI   rG   r   rF   rH   rf   rS   r  remover   r;   )r9   r  blocks      r:   _upload_chunkzHfFileSystemFile._upload_chunk  s     ""U### 	N  """$,.LMM //&08KTM_Md7e6f 0     (($(N$7!%!3!@ .6'-"0:!/8#';??3C#D#D'+{7K'L'L ) 	 	 	 Idn)***G$$'1133 %     %	 	r<   rP  c                 \   | j         dk    r||dk    rx| j        dk    rm| j                            | j        dd          5 }|                                }| xj        t          |          z  c_        |cddd           S # 1 swxY w Y   t                                          |          S )zRead remote file.

        If `length` is not provided or is -1, the entire file is downloaded and read. On POSIX systems the file is
        loaded in memory directly. Otherwise, the file is downloaded to a temporary file and read from there.
        r   NrP  r   )r   )r   locr  rB  r3   rC  r   ra   )r9   lengthrH  r   rg   s       r:   rC  zHfFileSystemFile.read  s     9&.FbLLdhRSmmdi!<< ffhhCHH$                ww||F###s   3BB	Bc                 @    | j                             | j                  S r`   r  rh  r3   r8   s    r:   rh  zHfFileSystemFile.url      w{{49%%%r<   r`   r  )FrP  )r=   r>   r?   r   rA   rb   r  r  bytesr  r  r  r  rC  rh  r   r   s   @r:   r   r     s       
 
< 
s 
cDj 
 
 
 
 
 
! ! ! ! !# C E    S S S S 4 D    4$ $ $ $ $ $&S & & & & & & & &r<   r   c                        e Zd Z	 	 	 	 ddededededz  d	ed
ef fdZddedefdZddefdZdde	e
         dede
fdZdefdZ fdZd Zd Z xZS )r   r   Nr   noner  r3   r   rH   r   
cache_typec                 p   |dk    rt          d|           |dk    rt          d|           d|v rt          d| d          	 |                    ||          | _        nB# t          $ r5}d|                    d	d
          v rt          | d          |Y d }~nd }~ww xY w| j                                        d d| _         t                      j        || j                                        f|||d| d | _	        |  t                      | _        d | _        t                      | _        d S )Nr   z:HfFileSystemStreamFile only supports block_size=0 but got r  z?HfFileSystemStreamFile only supports cache_type='none' but got r  z;HfFileSystemStreamFile only supports reading but got mode='r$  r   r   rP   r  )r   r  r   r   r  )r   r   r   r8  rS   r;   detailsra   rb   responser   _exit_stack_stream_iterator	bytearray_stream_buffer)
r9   r  r3   r   rH   r   r  rf   r   rg   s
            r:   rb   zHfFileSystemStreamFile.__init__  s    ??fZdffgggk_ikklll$;;b[_bbbccc	!#!I!ID  	 	 	fjj,,,,']]]  -,,,,	 !% 2 < < > >MM",,..	
59j]g	
 	
kq	
 	
 	
 04$;;8<'kks   
A' '
B&1+B!!B&r  whencec                 b    |dk    r|dk    rd S || j         k    r|dk    rd S t          d          )Nr   r   zCannot seek streaming HF file)r  r   )r9   r  r  s      r:   r}  zHfFileSystemStreamFile.seek  s?    !88!F$(??v{{F8999r<   rP  r  c                 h   | j         |                                  d}	 	 | j         | j        dS |                     | j        |          }| xj        t          |          z  c_        |S # t          $ r< | j         | j                                          |r |                                  d}Y nw xY w)zRead the remote file.

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

        If reading the stream fails, we retry with a new connection.
        NFTr<   )r  _open_connectionr  _read_from_streamr  r   r  r~  )r9   r  retried_oncer   s       r:   rC  zHfFileSystemStreamFile.read  s     = !!###	$$=(D,A,I3,,T-BFKKCHH$
 $ $ $=,M''))) %%'''#$	$s   A* 9A* *AB0/B0iteratorr4   c                    |dk    rdS |dk     rVt          | j                  }| j                                         |D ]}|                    |           t	          |          S |t          | j                  k    r(t	          | j        d|                   }| j        d|= |S t          | j                  }| j                                         |D ]|}|t          |          z
  }|t          |          k    r|                    |           =|                    |d|                    | j                            ||d                     t	          |          S )zRead up to `length` bytes from stream buffer and stream.

        If length < 0, read until EOF.

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

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

5!!!!

5$<(((#**5<888Szzr<   c                 @    | j                             | j                  S r`   r  r8   s    r:   rh  zHfFileSystemStreamFile.urlC  r  r<   c                     t          | d          sd S | j                                         t                                                      S r  )r  r  r~  ra   r  r  s    r:   r  zHfFileSystemStreamFile.__del__F  sC    t_-- 	F   ww   r<   c                 Z    t           | j        | j        | j        | j        | j        j        ffS r`   )reopenr  r3   r   	blocksizecacher   r8   s    r:   r  z!HfFileSystemStreamFile.__reduce__M  s$    DIt~tzWWWr<   c                    | j                                          d| _        |                                 }| j        j                                        }| j        dk    rd| j         d|d<   | j        	                    t          d||t          j                            | _        	 t          | j                   n0# t          $ r#}|j        j        dk    rd| _        Y d}~dS  d}~ww xY w| j                                        | _        dS )	z%Open a connection to the remote file.Nr   r  r  Ranger  r  i  )r  r   r  rh  r  r   r{  r  r  enter_contextr-   r   r  r  r+   r   status_code
iter_bytes)r9   rh  rr  r   s       r:   r  z'HfFileSystemStreamFile._open_connectionP  s    	!!### $hhjj',00228a<<3333GG(66!9	  
 
	.... 	 	 	z%,, $	 !% 8 8 : :s   'B< <
C)C$#C$$C))r   Nr   r  )r   r  )r=   r>   r?   r   rA   r  rb   r}  rC  r   r  r  rh  r  r  r  r   r   s   @r:   r   r     s_       
 # !* !*!* !* 	!*
 *!* !* !* !* !* !* !* !*F: : :S : : : :$ $3 $ $ $ $8   (5/  3  PU        D&S & & & &! ! ! ! !X X X; ; ; ; ; ; ;r<   r   rH   r4   c                 L    t          j        |           r| nt          |           S r`   )r#   match
safe_quoter   s    r:   rU   rU   o  s%    28BB\88
S[H\H\\r<   sc                 $    t          | d          S )NrP   )safe)r   )r  s    r:   r  r  s  s    r<   r3   r   c                     | }t          |t                    r|  d}n5t          |t                    r|  d}nt          |t                    r|  d}t	          |          |)Nz (repository not found)z (revision not found)z (invalid repository id))r   r   r    r*   r8  )r3   r   msgs      r:   r   r   w  s~    
C#.// 0...	C.	/	/ 0,,,	C*	+	+ 0///
C
 
 c)r<   r  r   r   r  c                 4    |                      ||||          S )Nr  )rB  )r  r3   r   r   r  s        r:   r  r    s    774dzj7QQQr<   c                 l     | |i |}|                                 D ]\  }}t          |||           |S r`   )ru   rv   )rd   re   rf   r~   r  r   r   s          r:   r  r    sP    	d	f		B+1133 ' 'kD+&&&&Ir<   )Zr  r  rl   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   rP   r   _commit_apir   r   errorsr   r   r   r   r    file_downloadr!   r"   hf_apir#   r$   r%   r&   r'   r(   r)   utilsr*   r+   r,   r-   r.   utils.insecure_hashlibr/   r1   rE   rY   rr   AbstractFileSystemr\   rB   r^   r   specAbstractBufferedFiler   r   rA   rU   r  r  r   r  r  r  hffsrC   r<   r:   <module>r     s   					            . . . . . . . .                   ( ( ( ( ( ( ( (             ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '   J J J J J J J J J J & & & & & & # # # # # #       C C C C C C C C              0 / / / / / / / v v v v v v v v v v v v v v v v v v j j j j j j j j j j j j j j ' ' ' ' ' ' 6 6 6 6 6 6 6 6 & & & & &)A & & &0 0 0 0 0 0%= 0 0 0 D233c 3 3 32 2 2 2 2l 2 2 2j@
 @
 @
 @
 @
6, @
 @
 @
 @
F H& H& H& H& H&v{7 H& H& H&VR; R; R; R; R;V[= R; R; R;j]C ]C ] ] ] ]# #    * *)d*: *x * * * *R| R3 Rc Rs RPS R R R R   |~~r<   