
    9i              
       6   % 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  S S	K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,  SSK-J.r.J/r/  SSK0J1r1J2r2J3r3  SSK4J5r5J6r6J7r7J8r8  SSK9J:r:  \Rv                  " S\Rx                  5      r=\ " S S5      5       r>\?" \R                  5      rA\\BS'    " S S\A5      rC " S S\R                  \CS9rD " S S\R                  R                  5      rG " S  S!\R                  R                  5      rHS"\IS#\I4S$ jrJS%\IS#\I4S& jrKS'\IS(\\L   S#\4S) jrMS*\DS'\IS+\IS,\NS-\I4
S. jrOS3S/\R                  S0\NS#\Q4S1 jjrRS2 rS\D" 5       rTg)4    N)deque)	ExitStack)deepcopy)	dataclassfield)datetime)chain)Path)AnyIteratorNoReturnOptionalUnion)quoteunquote)_DEFAULT_CALLBACKNoOpCallbackTqdmCallback)
isfilelike   )	constants)CommitOperationCopyCommitOperationDelete)EntryNotFoundErrorHfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError)
hf_hub_urlhttp_get)HfApiLastCommitInfoRepoFile)HFValidationErrorhf_raise_for_statushttp_backoffhttp_stream_backoff)md5zy
    (^refs\/convert\/\w+)     # `refs/convert/parquet` revisions
    |
    (^refs\/pr\/\d+)          # PR revisions
    c                   n    \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \" SSS	9r\	\   \S
'   S\4S jr
Srg)HfFileSystemResolvedPath(   zUData structure containing information about a resolved Hugging Face file system path.	repo_typerepo_idrevisionpath_in_repoNF)defaultrepr_raw_revisionreturnc                    [         R                  R                  U R                  S5      U R                  -   nU R
                  (       a-  U SU R
                   SU R                   3R                  S5      $ U R                  [         R                  :w  a6  U S[        U R                  5       SU R                   3R                  S5      $ U SU R                   3R                  S5      $ )N @/)r   REPO_TYPES_URL_PREFIXESgetr+   r,   r1   r.   rstripr-   DEFAULT_REVISIONsafe_revision)self	repo_paths     ^/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/huggingface_hub/hf_file_system.py	unresolve"HfFileSystemResolvedPath.unresolve4   s    5599$.."MPTP\P\\	[$"4"4!5Qt7H7H6IJQQRUVV]]i888[-">!?qARAR@ST[[\_``[$"3"3!45<<SAA     )__name__
__module____qualname____firstlineno____doc__str__annotations__r   r1   r   r?   __static_attributes__rB   rA   r>   r)   r)   (   s?    _NLM $)E#BM8C=BB3 BrA   r)   _cached_basec                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )_CachedB   a  
Metaclass for caching HfFileSystem instances according to the args.

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

This is a slightly modified version of `fsspec.spec._Cached` to improve it.
In particular in `_tokenize` the pid isn't taken into account for the
`fs_token` used to identify cached instances. The `fs_token` logic is also
robust to defaults values and the order of the args. Finally new instances
reuse the states from sister instances in the main thread.
c                 4   > [         TU ]  " U0 UD6  0 U l        g N)super__init___cache)clsargskwargs	__class__s      r>   rR   _Cached.__init__R   s    $)&) 
rA   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cachablerS   _latesttype__call___get_instance_stateitemssetattr
_fs_token_storage_argsstorage_options)
rT   rU   rV   skipfs_tokenfs_token_main_threadobjinstance_stateattrstate_values
             r>   rd   _Cached.__call__Z   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$JrA   rB   )	rC   rD   rE   rF   rG   rR   rd   rJ   __classcell__rW   s   @r>   rM   rM   B   s     rA   rM   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S4S\S\\   S\4S jjrS4S\\   SS4S jjr   S5S\S\S	\\   S\\   S\	S   4
S jjrS4S\S\\   SS4S jjr   S6S\S\
S\\   S\\   SS4
S jjr S7S\S\
S\
S\\   S\\	\\\\4   4      4
S jjr     S8S\S\
S\
S\\   S
\\
   S\\   4S  jjrS\S\\\\\   \\   4      4U 4S! jjrS4S\S\\   S\\   4U 4S" jjjr     S9S\S\\   S#\
S\
S\
S\\   S\	\\   \\\\\4   4   4   4S$ jjr S4S%\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&S, r'S\S\4S- jr(\)S4S;U 4S. jjjr*\+S/ 5       r,S0 r-S1 r.S2 r/S3r0U =r1$ )<HfFileSystemt   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.

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)
```
r4   hfN)endpointtoken
block_sizeexpand_infory   rz   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        g )N)ry   rz   )rQ   rR   r   ENDPOINTry   rz   r    _apir{   r|   _repo_and_revision_exists_cachedircache)r<   ry   rz   r{   r|   rU   rj   rW   s          r>   rR   HfFileSystem.__init__   s[     	$2/2 6I$6$6
89	$&  	, :<rA   threading_identr2   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 cachingry   rz   )r8   r   r~   sortedr'   rH   encode	hexdigest)rT   r   rU   rV   keytokenize_argshs          r>   r\   HfFileSystem._tokenize   s     $ZZ
3Iy7I7Iz **W-w.4Vn=nsv{"n=t<M"))+,{{}	 >s   Br+   r,   r-   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)r-   r+   timeout)TNF)r   r   	repo_infor   HF_HUB_ETAG_TIMEOUTr   r#   r   )r<   r+   r,   r-   es        r>   _repo_and_revision_exist%HfFileSystem._repo_and_revision_exist   s    )1U1UU^		##)YMjMj $  Xb44i(5STS]44i$5OP33Y4RSS ,->? \W\^_W_44i(5STSXZ[S[44i$5OP( ^W\^_W_44i(5STS]44i$5OP^s#   )A0 0C& &B++C&8$C!!C&pathc                 H   S[         [           S[         [           S[         [           4S jnU R                  U5      nU(       d  [        S5      eUR	                  S5      S   S-   [
        R                  R                  5       ;   a9  SU;  a  [        S5      eUR	                  SS5      u  pA[
        R                  U   nO[
        R                  nUR                  S5      S:  Ga  S	U;   a  UR	                  S	S5      u  pVS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  phOSnU" [!        U5      U5      nU R#                  XEU5      u  pU	(       d  [%        X5        GOIS
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#                  XEU5      u  pU	(       dQ  [)        U
[*        [,        45      (       a+  UnUnU R#                  XEU5      u  pU	(       d  [%        X5        Oe[%        X5        OYUnSnS	U;   a'  UR	                  S	S5      u  pVU" [!        U5      U5      nOS
nU R#                  XEU5      u  pU	(       d  [        S5      eUb  UO[
        R.                  n[1        XEX(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_pathr-   r2   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   r-   s     r>   %_align_revision_in_path_with_revisionHHfFileSystem.resolve_path.<locals>._align_revision_in_path_with_revision   sS     ##/4D4P$78H7IIijris t- -  O ,OrA   z0Access to repositories lists is not implemented.r6   r   r   r5   Nr4      )r1   )r   rH   _strip_protocolNotImplementedErrorsplitr   r7   valuesREPO_TYPES_MAPPINGREPO_TYPE_MODELcountSPECIAL_REFS_REVISION_REGEXsearchgroupsublstripr   r   _raise_file_not_foundjoin
isinstancer   r#   r:   r)   )r<   r   r-   r   r+   r,   r   matchr.   repo_and_revision_existerrrepo_id_with_namespacepath_in_repo_with_namespacerepo_id_without_namespacepath_in_repo_without_namespace_s                   r>   resolve_pathHfFileSystem.resolve_path   s   (	&sm	7?}	c]	 ##D)%&XYYZZ_Q#%)J)J)Q)Q)SS$)*\]]"jja0OI!44Y?I!11I::c?Qd{,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&#*)*\]]'389S9S'	HbrssrA   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                  (       dq  U R                  R                  UR                  UR                  S4S5        U R                  R                  UR                  UR                  UR                  4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?   r[   _parentr.   r+   r,   r-   )r<   r   resolved_paths      r>   invalidate_cacheHfFileSystem.invalidate_cache>  s     MM!00668 --d3M **,D!!$-||D) $
 !--4488-:Q:QS`ShShjn9oquv4488",,m.C.C]E[E[\^b .rA   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   r-   )r{   r   r   r   )r<   r   r   r{   r-   rV   s         r>   _openHfFileSystem._openZ  sh     $.#9Zt
!#-< $;%&WXX?)$]4]V\]]#DWTWPVWWrA   c                 :   U R                  XS9nU 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r-   commit_messagecommit_description)r.   r,   rz   r+   r-   r   r   r   )r   r   delete_filer.   r,   rz   r+   r-   r8   r   r?   )r<   r   r-   rV   r   s        r>   _rmHfFileSystem._rml  s    ))$)B		&33!))**#--"++!::&67%zz*>? 	 	
 	=#:#:#<=rA   	recursivemaxdepthc                 R   U R                  XS9nU R                  XX4S9nU 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 )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   r-   )r.   zDelete  zrecursively r4   Nzup to depth r   r   )r,   r+   rz   
operationsr-   r   r   r   )r   expand_pathisdirr.   r   r   create_commitr,   r+   rz   r-   r8   r   r?   )r<   r   r   r   r-   rV   r   pathspaths_in_repor.   r   r   s               r>   rmHfFileSystem.rmy  s.   6 ))$)B  X aJOh%$WaWabfWg=**40==%h[hi[h<+F[h
i"4&*I.2=8LL
!4RTT		!))#--**!"++!::&6G%zz*>? 	  	
 	=#:#:#<= iis   DD&D$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   r-   Nnamer   )r   r?   _ls_treer   r.   r   r   len)	r<   r   r   r   r-   rV   r   outos	            r>   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                  UR
                  UR                  SUR                  S9R                  5       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(       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                  R1                  US 5        M<     U R                  R1                  US 5        U	R                  U R3                  UUSUUUS95        U	$ U R4                  R7                  UR
                  UR8                  UUUR                  UR                  S9nU H  nUS-   UR                  -   n[;        U[<        5      (       a=  UUR>                  SUR@                  URB                  URD                  URF                  S.nOUSSURH                  URD                  S.nU R                  US   5      nU R                  RK                  U/ 5      R                  U5        U[)        U5      S  R+                  S5      nUb  X::  d  M  U	R                  U5        M     U	$ s  snf s  snf s  snf s  snf )NFr   r4   r.   r1   r   rc   	directoryr   r   last_commitr6   T)r   r   r-   r|   r   )r   expandr-   r+   filer   sizerc   blob_idlfsr   securityr   r   r   rc   tree_idr   )&r|   r   r?   r)   r+   r,   r-   r1   r   extendr   popleftappendr   osr   commonprefixendswithr	   r9   r   r   
startswithlistr[   r   r   list_repo_treer.   r   r"   r   r   r   r   r   r   
setdefault)r<   r   r   r   r-   r|   r   r   	root_pathr   cached_path_infosdirs_not_in_dircachedepth	path_infodirs_to_visitdir_infodirs_not_expandedr   common_prefixcommon_pathcommon_path_depthcached_pathtree
cache_pathcache_path_infoparent_paths                             r>   r   HfFileSystem._ls_tree  s    '2KTM]M]Mi9I9Iot 	 ))$)B&&(,##!!""'55
 )+ 	 ==  $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  !#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#"+ $!)$/!) " 	X 
C 99++%%**#"&//'11 , D "	&_y~~=
i22 * ) &#,#4#4(}}'0'<'<$-$6$6'O !+ ! +#,#4#4'0'<'<'O #ll?6+BC((b9@@Q"3t9;/55c:#u'8JJ/1 "2 
o p!" %g" Vs0   R
!R
*R;R#
R1R R&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.
r-   r   N)r   r8   r?   rQ   walk)r<   r   rU   rV   rW   s       r>   r  HfFileSystem.walkH  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.
r-   r   r   )r   r8   r?   rQ   glob)r<   r   r   rV   rW   s       r>   r  HfFileSystem.globX  sC       

:0F GQQSw|D>8>v>>rA   withdirsc                 ~   Ub  US:  a  [        S5      eU R                  XS9nUR                  5       n U R                  " U4SXXR                  US.UD6n	U(       d  U	 V
s/ s H  oS   S:w  d  M  U
PM     n	n
O0U R
                  " U4SUR                  0UD6nUS   S:X  a  U/U	-   OU	n	U	 V
s0 s H  oS	   U
_M
     n	n
[        U	5      nU(       d  U$ U Vs0 s H  oX   _M	     sn$ s  sn
f s  sn
f ! [         a;     U R
                  " U4SU0UD6S   S
:X  a  U0 0n	 N`0 n	 Nd! [         a    0 n	  Nsf = ff = fs  snf )aE  
List all files below path.

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

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

Returns:
    `Union[list[str], dict[str, dict[str, Any]]]`: List of paths or dict of file information.
r   zmaxdepth must be at least 1r   T)r   r   r-   r   rc   r   r-   r   r   )	r   r   r?   r   r-   infor   FileNotFoundErrorr   )r<   r   r   r  r   r   r-   rV   r   r   r   r   namesr   s                 r>   findHfFileSystem.findh  sy   @ HqL:;;))$)B&&(	.-- $g@V@VaimsC "%B#Q6k)Aq#B !IIdV]5K5KVvV	+4V+<+KykC'QT),-AV9a<C-sL056#)O66 C
 .! " 	99T?H??G6Q*CC$ 	* 7sG   !C2 !C(1C(.C-D:2
D7= D#D##D3/D72D33D7path1path2c                    U R                  XS9nU R                  X#S9n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 z to r   r   r4   )src_path_in_repor.   src_revision)r,   r+   r-   r   r   r   rbNpath_or_fileobjr.   r,   rz   r+   r-   r   r   r   )r   r+   r,   r   r   r-   r8   r   r.   openreadupload_filerz   r   r?   )r<   r  r  r-   rV   resolved_path1resolved_path2	same_repor   fcontents              r>   cp_fileHfFileSystem.cp_file  s     **5*D**5*D $$(@(@@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   G
G"c                 D    U R                   " U40 0 UESS0ED6nUS   S   $ )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 commit date of the file.
r|   Tr   dater  )r<   r   rV   r  s       r>   modifiedHfFileSystem.modified  s4     yyA!@F!@M4!@AM"6**rA   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S.n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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aX  U(       GaP  US   GcI  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[,        5      (       aM  US-   UR.                  -   UR0                  SUR2                  UR4                  UR6                  UR8                  S.nO,US-   UR.                  -   SSUR:                  UR6                  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 )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.

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   rc   r   )r+   r-   )oidtitler'  )r   r   r   r   )r   r-   r+   r4   r   r6   r   r   r   )r   r   rc   )r   r?   r8   r|   r.   r   list_repo_commitsr,   r+   r-   r!   	commit_idr.  
created_atr   r   r   r   get_paths_infor)   r1   r   r"   r   r   r   r   r   r   r   )r<   r   r   r-   rV   r   r|   r   r   r  r   out1
paths_infor   r   ks                   r>   r  HfFileSystem.info  s   * ))$)B&&(jjt/?/?/K4++QV
 )) ##	C "ii99!))]5L5LWdWmWm : ##1'119J9JQ\QgQg$ C,,t,K;mm#C$mm+#'==#=S#=a6dAR#=S)$51g#++##mBTB\!YY55!))!..&*33+55 6 
 ")$5&qM	4!++!))!**!#"/"="= )+  i22 )C).. @ ) &#,#4#4(}}'0'<'<$-$6$6C !*C).. @ ! +#,#4#4'0'<'<C #.FG.Fcf9.FCG
W TR Hs   2KK<K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)r8   r   r  )r<   r   rV   s      r>   existsHfFileSystem.existsQ  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.
rc   r   F)r  OSErrorr<   r   s     r>   r   HfFileSystem.isdirj  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.
rc   r   Fr(  r<  s     r>   isfileHfFileSystem.isfile|  s)    	99T?6*f44	s    c                     U R                  U5      n[        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.
)r+   r-   ry   z	/resolve/z/tree/r   )	r   r   r,   r.   r+   r-   ry   r   replace)r<   r   r   urls       r>   rC  HfFileSystem.url  sq     ))$/!!&&#--"++]]
 ::d++k8Q7C
rA   c                 6  > 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
R0                  U
R2                  U
R4                  U
R6                  U R8                  S9UUUSU R:                  R=                  5       [        U[
        5      (       a  UR>                  OSS9  URA                  U	5        U(       a  URC                  5         gg! U(       a  URC                  5         f f = f)a  
Copy single remote file to local.

> [!WARNING]
> Note: When possible, use `HfApi.hf_hub_download()` 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.

r-   r   )callbackoutfileT)exist_okNFwbr   r   r,   r-   filenamer+   ry   )rC  	temp_filedisplayed_filenameexpected_sizeresume_sizeheaders	_tqdm_bar)"r8   setkeysr   r   r   r   rQ   get_filer   r   r   makedirsrH   r
   r   dirnamer  tellr   r  set_sizer   r   r,   r-   r.   r+   ry   r   _build_hf_headerstqdmseekclose)r<   rpathlpathrF  rG  rV   r-   unhandled_kwargs
close_fileinitial_posresolve_remote_pathrN  rW   s               r>   rT  HfFileSystem.get_file  s   $ ::j)v{{}-<(\<$@AASIYEZ]^E^ 7#E_8_X^__ eGZZKK-ec4[))KK.> 
?5$'GJlln #///I		%	;FC-(	 /770990==1;;!]] "#(+		335+5h+M+M(--SW LL%  z s   BG> >H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   r<   s    r>   transactionHfFileSystem.transaction  s     ""LMMrA   c                     [        S5      e)z@Begin write transaction for deferring files, non-context versionre  rf  rg  s    r>   start_transactionHfFileSystem.start_transaction  s     ""LMMrA   c                 p    [         [        U 5      U R                  U R                  U R	                  5       44$ rP   )make_instancerc   ri   rj   re   rg  s    r>   
__reduce__HfFileSystem.__reduce__  s9    J  $$&	
 
 	
rA   c                 X    [        U R                  5      [        U R                  5      S.$ )N)r   r   )r   r   r   rg  s    r>   re    HfFileSystem._get_instance_state  s&     //78\8\/]
 	
rA   )r   r   r{   r   ry   r|   rz   rP   )r  NN)FNN)TFN)FFNNN)NFFFN)FNr2   N)2rC   rD   rE   rF   rG   root_markerprotocolr   rH   r   boolintrR   classmethodr\   tuple	Exceptionr   r)   r   r   r   r   r   r   dictr   r   r   r   r  r  r  r$  r   r)  r  r8  r   r?  rC  r   rT  propertyrh  rk  ro  re   rJ   rs   rt   s   @r>   rv   rv   t   s(   .` KH
 #'(,$(&*< 3-< T3_%	<
 SM< d^< <0 	 	 	 	TT'*T6>smT	tXi((	)T&]t ]t ]tIa ]t~Xc] d > $("&XX X SM	X
 3-X 
;	<X$> >x} >$ >   "&"&,>,> ,> 3-	,>
 3-,> 
,>^ `d&;&;!%&;7;&;OWX[}&;	eCc3h'(	)&;V  "&&*"&ww w 	w
 3-w d^w 3-wr7 7(5d3iQUVYQZAZ;[2\ 7 ? ? ?4PS9 ? ?& #'"&=7=7 3-=7 	=7
 =7 =7 3-=7 
tCy$sDcN233	4=7~6?S 6? 6? 6?[_ 6?p+S +x + ` `t `x} `bfgjlogobp `D2$$  . /@ B  B H N NN

 
rA   rv   )	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fsr   r-   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   r4   B.
Make sure the repository and revision exist before writing data.)r   r   r  r8   rQ   rR   r?   )r<   r  r   r-   rV   r   rW   s         r>   rR   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   )hasattrrQ   __del__r<   rW   s    r>   r  HfFileSystemFile.__del__  s     t_--w  rA   startendr2   c                    SSU SUS-
   30U R                   R                  R                  5       En[        U R                  R
                  U R                  R                  U R                  R                  U R                  R                  U R                   R                  S9n[        SXC[        R                  S9n[        U5        UR                  $ )Nrangebytes=-r   rJ  GETrP  r   )r  r   rY  r   r   r,   r-   r.   r+   ry   r%   r   HF_HUB_DOWNLOAD_TIMEOUTr$   r#  )r<   r  r  rP  rC  rs         r>   _fetch_rangeHfFileSystemFile._fetch_range  s    veWAcAgY/
ggll,,.
 &&..''00''44((22WW%%
 i>_>_`AyyrA   c                 8    [         R                  " SSS9U l        g )Nzhffs-F)prefixdelete)tempfileNamedTemporaryFilerL  rg  s    r>   _initiate_upload!HfFileSystemFile._initiate_upload-  s    !44GERrA   finalc                 H   U R                   R                  S5        U R                   R                  5       nU R                  R	                  U5        U(       GaJ  U R                  R                  5         U 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  [$        R&                  " U R                  R                  5        U R                  R)                  U R                  R+                  5       S9  g g )Nr   r   r   r  r   )bufferr[  r  rL  writer\  r  r   r  r   r   r.   r,   rz   r+   r-   rV   r8   r   remover   r?   )r<   r  blocks      r>   _upload_chunkHfFileSystemFile._upload_chunk0  s"     "U#NN  "GGLL$$ $ 3 3!//<<**22ggmm,,66++44#{{/?@#';;??3G#H % 	 IIdnn))*GG$$''113 %  rA   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.
r  Nr,  r   )r{   )r   locr  r  r   r  r   rQ   )r<   lengthr"  r   rW   s       r>   r  HfFileSystemFile.readE  s     99&.FbLdhhRSmdii!<ffhCH$ =< w|F##	 =<s   0B
B'c                 L    U R                   R                  U R                  5      $ rP   r  rC  r   rg  s    r>   rC  HfFileSystemFile.urlR      ww{{499%%rA   )r   rL  rP   rs  )Fr,  )rC   rD   rE   rF   rv   rH   r   rR   r  rw  bytesr  r  rv  r  r  rC  rJ   rs   rt   s   @r>   r   r   
  st    
< 
s 
hsm 
 
!# C E  S4 D *$&S & &rA   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\4S jrU 4S jrS rS rSrU =r$ )r   iV  r  r   r   r-   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        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   r4   r  )r   r   r   r{   r  )r   r   r   r  r8   r?   detailsrQ   rR   responser   _exit_stack)
r<   r  r   r   r-   r{   r  rV   r   rW   s
            r>   rR   HfFileSystemStreamFile.__init__W  s    ?YZdYefgg^_i^jkll$;Z[_Z``abcc	!#!ID !% 2 2 < < >M"",,.	
59]g	
kq	
 37$; ! 	fjj,,'c\] -	s    B; ;
C4%C//C4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   )r<   r  r  s      r>   r[  HfFileSystemStreamFile.seekw  s0    !8!((?v{899rA   r  c                 r   U R                   c  U R                  5         Sn  U R                   c  g[        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.
FTrA   )r  _open_connection_partial_readr  r   rz  r\  )r<   r  retried_oncer   s       r>   r  HfFileSystemStreamFile.read~  s     == !!#$==(#DMM6:CH$
 $==,MM'')%%'#$ s   A& 5A& &AB43B4r2   c                 L    U R                   R                  U R                  5      $ rP   r  rg  s    r>   rC  HfFileSystemStreamFile.url  r  rA   c                 x   > [        U S5      (       d  g U R                  R                  5         [        TU ]  5       $ r  )r  r  r\  rQ   r  r  s    r>   r  HfFileSystemStreamFile.__del__  s2    t_-- w  rA   c                     [         U R                  U R                  U R                  U R                  U R
                  R                  44$ rP   )reopenr  r   r   	blocksizecacher   rg  s    r>   ro  !HfFileSystemStreamFile.__reduce__  s0    DIIt~~tzzWWWrA   c           	         [        U R                  R                  U R                  R                  U R                  R                  U R                  R
                  U R                  R                  S9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        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.rJ  r   r  r  Ranger  r  i  N)r   r   r,   r-   r.   r+   r  ry   r   rY  r  r  enter_contextr&   r   r  r  r$   r   status_code)r<   rC  rP  r   s       r>   r  'HfFileSystemStreamFile._open_connection  s   &&..''00''44((22WW%%
 '',,00288a<!'z3GG((66!99	
	. 	zz%%, $	s   2D 
D>!D98D99D>)r  r  r   r  )r  Nr   r  )r   r  )rC   rD   rE   rF   rv   rH   r   rw  rR   r[  r  rC  r  ro  r  rJ   rs   rt   s   @r>   r   r   V  s    
 "& '' ' 	'
 3-' ' ' '@: :S :$3 $8&S &!X rA   r   r-   r2   c                 P    [         R                  U 5      (       a  U $ [        U 5      $ rP   )r   r   
safe_quoter   s    r>   r;   r;     s#    288BB8\
S[H\\rA   sc                     [        U SS9$ )Nr4   )safe)r   )r  s    r>   r  r    s    rA   r   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#   r  )r   r   msgs      r>   r   r     se    
C#.//-.	C.	/	/+,	C*	+	+./
C
 c)rA   r  r   r{   r  c                 "    U R                  XX4S9$ )Nr  )r  )r  r   r   r{   r  s        r>   r  r    s    774z7QQrA   r  r  c                 Z   [        5       nUS:  a  [        S5      eUS:X  a  gUS:X  a3  U R                  5        H  nUR                  U5        M     [	        U5      $ U R                  US9 H3  nUR                  U5        [        U5      U:  d  M%  [	        USU 5      s  $    [	        U5      $ )zV
Read up to `length` bytes from a streamed response.
If length == -1, read until EOF.
r,  zlength must be -1 or >= 0r   rA   )
chunk_sizeN)	bytearrayr   
iter_bytesr   r  r   )r  r  bufchunks       r>   r  r    s    
 +C{455{|((*EJJu +Sz$$$7

5s8vWf&& 8
 :rA   c                 `    U " U0 UD6nUR                  5        H  u  pV[        XEU5        M     U$ rP   )rf   rg   )rT   rU   rV   ro   r  rp   rq   s          r>   rn  rn    s6    	d	f	B+113+& 4IrA   r  )Ur   rer  r]   collectionsr   
contextlibr   copyr   dataclassesr   r   r   	itertoolsr	   pathlibr
   typingr   r   r   r   r   urllib.parser   r   fsspechttpxfsspec.callbacksr   r   r   fsspec.utilsr   r4   r   _commit_apir   r   errorsr   r   r   r   file_downloadr   r   hf_apir    r!   r"   utilsr#   r$   r%   r&   utils.insecure_hashlibr'   compileVERBOSEr   r)   rc   AbstractFileSystemrK   rI   rM   rv   specAbstractBufferedFiler   r   rH   r;   r  rz  r   rw  r  Responser  r  rn  hffsrB   rA   r>   <module>r     s   	 	       (    ; ; '   J J #  C f f / 3 3 \ \ ' !jj
 JJ  B B B, 223c 3/l /dS
6,, S
lI&v{{77 I&XmV[[== m`]C ]C ]# # * *(9*= *( *R| R3 Rc Rs RPS RENN C  . ~rA   