
    HTh              
          S SK r S SKrS SKrS SKJr  S SKJrJr  S SKJr  S SK	J
r
  S SKJr  S SKJrJrJrJrJrJrJrJr  S SKJrJr  S SKrS S	KJrJrJr  S S
KJr  S SK J!r!  SSK"J#r#  SSK$J%r%J&r&  SSK'J(r(J)r)J*r*  SSK+J,r,J-r-  SSK.J/r/J0r0J1r1  SSK2J3r3J4r4J5r5  \Rl                  " S\Rn                  5      r8\ " S S5      5       r9 " S S\Rt                  5      r; " S S\Rx                  Rz                  5      r> " S S\Rx                  Rz                  5      r?S\@S\@4S jrAS\@S\@4S  jrBS!\@S"\\C   S\4S# jrDS$\;S!\@S%\@S&\ES'\@4
S( jrFg))    N)deque)	dataclassfield)datetime)chain)Path)AnyDictIteratorListNoReturnOptionalTupleUnion)quoteunquote)_DEFAULT_CALLBACKNoOpCallbackTqdmCallback)
isfilelike)Response   )	constants)CommitOperationCopyCommitOperationDelete)EntryNotFoundErrorRepositoryNotFoundErrorRevisionNotFoundError)
hf_hub_urlhttp_get)HfApiLastCommitInfoRepoFile)HFValidationErrorhf_raise_for_statushttp_backoffzy
    (^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+   r0   r-   rstripr,   DEFAULT_REVISIONsafe_revision)self	repo_paths     V/var/www/auris/envauris/lib/python3.13/site-packages/huggingface_hub/hf_file_system.py	unresolve"HfFileSystemResolvedPath.unresolve0   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   r0   r   r>   __static_attributes__rA   r@   r=   r(   r(   $   s?    _NLM $)E#BM8C=BB3 Br@   r(   c                   8  ^  \ rS rSrSrSrSrSSS.S\\   S\	\
\S4   4U 4S	 jjjrS
\S\S\\   S\\
\\   4   4S jrS0S\S\\   S\4S jjrS0S\\   SS4S jjr   S1S\S\S\\   S\\   SS4
S jjrS0S\S\\   SS4S jjr   S2S\S\
S\\   S\\   SS4
S jjr S3S\S\
S\
S\\   S\\	\\\\4   4      4
S jjr    S4S\S\
S\
S\\   S\
4
S jjrS\S\\\\\   \\   4      4U 4S jjrS\S\\   4U 4S  jjr     S5S\S\\   S!\
S\
S\
S\\   S\	\\   \\\\\4   4   4   4U 4S" jjjrS0S#\S$\S\\   SS4S% jjrS\S\ 4S& jr!S6S\S\
S\\   S\\\4   4S' jjr"S( r#S) r$S* r%S\S\4S+ jr&\'S4S7U 4S, jjjr(\)S- 5       r*S. r+S/r,U =r-$ )8HfFileSystem:   a  
Access a remote Hugging Face Hub repository as if were a local file system.

<Tip warning={true}>

    [`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.

</Tip>

Args:
    token (`str` or `bool`, *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`.
    endpoint (`str`, *optional*):
        Endpoint of the Hub. Defaults to <https://huggingface.co>.
Usage:

```python
>>> from huggingface_hub import HfFileSystem

>>> fs = HfFileSystem()

>>> # List files
>>> fs.glob("my-username/my-model/*.bin")
['my-username/my-model/pytorch_model.bin']
>>> fs.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 fs.open("my-username/my-model/pytorch_model.bin") as f:
...     data = f.read()
>>> with fs.open("my-username/my-model/pytorch_model.bin", "wb") as f:
...     f.write(data)
```
r3   hfNendpointtokenrO   rP   c                   > [         TU ]  " U0 UD6  U=(       d    [        R                  U l        X l        [        XS9U l        0 U l        g )NrN   )	super__init__r   ENDPOINTrO   rP   r!   _api_repo_and_revision_exists_cache)r;   rO   rP   argsstorage_options	__class__s        r=   rS   HfFileSystem.__init__f   sG     	$2/2 6I$6$6
89	  	,r@   r*   r+   r,   r1   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)rV   rU   	repo_infor   HF_HUB_ETAG_TIMEOUTr   r$   r   )r;   r*   r+   r,   es        r=   _repo_and_revision_exist%HfFileSystem._repo_and_revision_existx   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,   r1   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)rd   r,   s     r=   %_align_revision_in_path_with_revisionHHfFileSystem.resolve_path.<locals>._align_revision_in_path_with_revision   sS     ##/4D4P$78H7IIijris t- -  O ,Or@   z0Access to repositories lists is not implemented.r5   r   r   r4   Nr3      )r0   )r   rG   _strip_protocolNotImplementedErrorsplitr   r6   valuesREPO_TYPES_MAPPINGREPO_TYPE_MODELcountSPECIAL_REFS_REVISION_REGEXsearchgroupsublstripr   r`   _raise_file_not_foundjoin
isinstancer   r$   r9   r(   )r;   rb   r,   rg   r*   r+   rd   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sr@   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)dircacheclearrV   r   r>   pop_parentr-   r*   r+   r,   )r;   rb   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 .r@   mode
block_sizeHfFileSystemFilec                 l    SU;   a  [        S5      eUS:X  a  [        X4X#US.UD6$ [        X4X#US.UD6$ )Naz/Appending to remote files is not yet supported.r   )r   r,   r   )rk   HfFileSystemStreamFiler   )r;   rb   r   r,   r   kwargss         r=   _openHfFileSystem._open  sP     $;%&WXX?)$t4_itmstt#DnTYcngmnnr@   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+   rP   r*   r,   r   r   rb   )r   rU   delete_filer-   r+   rP   r*   r,   r7   r   r>   )r;   rb   r,   r   r   s        r=   _rmHfFileSystem._rm  s    ))$)B		&33!))**#--"++!::&67%zz*>? 	 	
 	=#:#:#<=r@   	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 )aw  
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).

<Tip warning={true}>

    Note: When possible, use `HfApi.delete_file()` for better performance.

</Tip>

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 r3   Nzup to depth r   r   )r+   r*   rP   
operationsr,   r   r   r   )r   expand_pathisdirr-   r   rU   create_commitr+   r*   rP   r,   r7   r   r>   )r;   rb   r   r   r,   r   r   pathspaths_in_repor-   r   r   s               r=   rmHfFileSystem.rm"  s.   < ))$)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SU0UE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 )aZ  
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).

<Tip warning={true}>

    Note: When possible, use `HfApi.list_repo_tree()` for better performance.

</Tip>

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   expand_info)r   r,   Nnamer   )r   r>   _ls_treer   r-   rv   r   len)	r;   rb   r   r   r,   r   r   outos	            r=   lsHfFileSystem.lsS  s    : ))$)B&&(262		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%)C 9C ?#C%$C%r   c           
      >   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ag  U(       Gd_  U R                  U   n	UR                  U	5        / n
U(       a  [        U	 Vs/ s H  oS   S:X  d  M  UPM     sn5      nU(       a  UR                  5       nUS   U R                  ;  a  U
R                  US   5        OOU R                  US      n	UR                  U	5        UR                  U	 Vs/ s H  oS   S:X  d  M  UPM     sn5        U(       a  M  / nU(       a+  U Vs/ s H  oS   b  M
  U R                  US   5      PM      nnU(       a  U
(       d  U(       Ga-  U(       Ga%  [        R                  R                  X-   5      nUR!                  S5      (       d  UU:X  d  U[#        X5      ;   a  UR%                  S5      OU R                  U5      nU Vs/ s H"  oS   R'                  US-   5      (       a  M   UPM$     nnU R                   H:  nUR'                  US-   5      (       d  M  U R                  R)                  US 5        M<     U R                  R)                  US 5        UR                  U R+                  UUS	UUS
95        U$ U R,                  R/                  UR                  UR0                  UUUR
                  UR                  S9nU H  n[3        U[4        5      (       aM  US-   UR                  -   UR6                  SUR8                  UR:                  UR<                  UR>                  S.nO,US-   UR                  -   SSUR@                  UR<                  S.nU R                  US   5      nU R                  RC                  U/ 5      R                  U5        UR                  U5        M     U$ s  snf s  snf s  snf s  snf )Nr   r3   r-   r0   type	directoryr   last_commitr5   T)r   r   r,   r   )r   expandr,   r*   filer   sizer   blob_idlfsr   securityr   r   r   r   tree_idr   )"r   r>   r(   r*   r+   r,   r0   r   extendr   popleftappendr   osrb   commonprefixendswithr   r8   
startswithr   r   rU   list_repo_treer-   rx   r#   r   r   r   r   r   r   
setdefault)r;   rb   r   r   r,   r   r   	root_pathr   cached_path_infosdirs_not_in_dircache	path_infodirs_to_visitdir_infodirs_not_expandedr   common_prefixcommon_pathcached_pathtreecache_path_infoparent_paths                         r=   r   HfFileSystem._ls_tree  s    ))$)B&&(,##!!""'55
 )+ 	 ==  $d 3JJ()#%  !&0Af0A9vEVZeEeY0Af! $,446H't}}<,33HV4DE,0MM(6:J,K)

#45%,,8In8I9W]M^bmMmY8In $m !#FI$fc}M]%<T\\!F)%<c!$f2HY !# 4 45I5] ^ %--c22$	1$.B(VV "((- m4  #&U#QvY-A-A+PSBS-Tq#U#'==K"--kC.?@@))+t< $1 !!+t4

MM#"+ $!)$/ " P 
= 99++%%**#"&//'11 , D "	i22 )C).. @ ) &#,#4#4(}}'0'<'<$-$6$6'O !*C).. @ ! +#,#4#4'0'<'<'O #ll?6+BC((b9@@Q

?++ ", 
W g o %g Vs0   /P?P=PP0	P=P'P
Pc              /      >#    SUR                  SS5      0UEn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   Fr,   r   N)r7   r   r>   rR   walk)r;   rb   rW   r   rY   s       r=   r   HfFileSystem.walk  sc       He!<GG  

:0F GQQS7<6t6v666s   AA%A#A%c                    > SUR                  SS5      0UEnU R                  XR                  S5      S9R                  5       n[        TU ]  " U4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   Fr,   r   )r7   r   r>   rR   glob)r;   rb   r   rY   s      r=   r   HfFileSystem.glob  sX      He!<GG  

:0F GQQSw|D+F++r@   withdirsc           	      r  > U(       a  [         TU ]  " U4X#XEUS.UD6$ U R                  XS9nUR                  5       nSU0UEn U R                  " U4SXXR
                  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	 Ncf = 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   r   r   r   r,   r   r   T)r   r   r,   r   r   r,   r   r   )	rR   findr   r>   r   r,   infor   sorted)r;   rb   r   r   r   r   r,   r   r   r   r   r   namesr   rY   s                 r=   r   HfFileSystem.find  s{   @ 7<'6emqw  ))$)B&&(262	.--qgPfPfqjpqC "%B#Q6k)Aq#B !IIdV]5K5KVvV	+4V+<+KykC'QT),-AV9a<C-sL056#)O66 C
 . " 	yy;;F;FCvMRj	$ 7s0    D  /C6?C6<C;%D4 *D1,D10D1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)aU  
Copy a file within or between repositories.

<Tip warning={true}>

    Note: When possible, use `HfApi.upload_file()` for better performance.

</Tip>

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   r3   )src_path_in_repor-   src_revision)r+   r*   r,   r   r   r   rbNpath_or_fileobjr-   r+   rP   r*   r,   r   r   r   )r   r*   r+   rU   r   r,   r7   r   r-   openreadupload_filerP   r   r>   )r;   r   r   r,   r   resolved_path1resolved_path2	same_repor   fcontents              r=   cp_fileHfFileSystem.cp_fileH  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                 8    U R                   " U40 U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   dater   )r;   rb   r   r   s       r=   modifiedHfFileSystem.modified  s'     yy((M"6**r@   c                    U R                  XS9nUR                  5       nUR                  SS5      nUR                  (       d{  U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	SS9  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R.                  SUR0                  UR2                  UR4                  UR6                  S.nO,US-   UR,                  -   SSUR8                  UR4                  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).

<Tip warning={true}>

    Note: When possible, use `HfApi.get_paths_info()` or `HfApi.repo_info()`  for better performance.

</Tip>

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   Tr   r   )r   r   r   )r*   r,   N)oidtitler   )r   r   Fr   r   r   )r   r,   r*   r3   r   r5   r   r   r   )r   r>   r7   r-   rU   list_repo_commitsr+   r*   r,   r"   	commit_idr   
created_atr   r   r   rv   get_paths_infor(   r0   rx   r#   rb   r   r   r   r   r   r   )r;   rb   r   r,   r   r   r   r   r   r   r   out1
paths_infor   r   ks                   r=   r   HfFileSystem.info  s   0 ))$)B&&(jj4
 )) #C
 "ii99!))]5L5LWdWmWm : ##1'119J9JQ\QgQg$ C,,t,K;mm#C7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   J8'J8!J=c                      UR                  SS5      (       a  U R                  U5        U R                  " U40 0 UESS0ED6  g!    g= f)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).

<Tip warning={true}>

    Note: When possible, use `HfApi.file_exists()` for better performance.

</Tip>

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

Returns:
    `bool`: True if file exists, False otherwise.
r   Fr   T)r7   r   r   )r;   rb   r   s      r=   existsHfFileSystem.exists  sQ    &	zz)U++%%d+IId?>>>?	s   AA Ac                 P     U R                  USS9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.
Fr   r   r   )r   OSErrorr;   rb   s     r=   r   HfFileSystem.isdir  s6    	99Tu95f=LL 		s    
%%c                 >     U R                  USS9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.
Fr   r   r   r   r  s     r=   isfileHfFileSystem.isfile%  s.    	99Tu95f=GG	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,   rO   z	/resolve/z/tree/r   )	r   r   r+   r-   r*   r,   rO   r   replace)r;   rb   r   urls       r=   r  HfFileSystem.url7  sq     ))$/!!&&#--"++]]
 ::d++k8Q7C
r@   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.

<Tip warning={true}>

    Note: When possible, use `HfApi.hf_hub_download()` for better performance.

</Tip>

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*   rO   )r  	temp_filedisplayed_filenameexpected_sizeresume_sizeheaders	_tqdm_bar)"r7   setkeysrx   r   r   r   rR   get_filer   r   r   makedirsrG   r   rb   dirnamer   tellr   r   set_sizer    r   r+   r,   r-   r*   rO   rU   _build_hf_headerstqdmseekclose)r;   rpathlpathr  r  r   r,   unhandled_kwargs
close_fileinitial_posresolve_remote_pathr   rY   s               r=   r&  HfFileSystem.get_fileN  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.rk   r;   s    r=   transactionHfFileSystem.transaction  s     ""LMMr@   c                     [        S5      e)z@Begin write transaction for deferring files, non-context versionr7  r8  r9  s    r=   start_transactionHfFileSystem.start_transaction  s     ""LMMr@   )rU   rV   rO   rP   N)r   NN)FNN)TFN)FFNT)NFFFN)FNr1   N).rB   rC   rD   rE   rF   root_markerprotocolr   rG   r   boolrS   r   	Exceptionr`   r(   r   r   intr   r   r   r   r
   r	   r   r   r   r   r   r   r   r   r   r   r
  r   r  r  r   r&  propertyr:  r=  rI   __classcell__rY   s   @r=   rK   rK   :   s   &P KH
 #'(,	 3- T3_%	 $TT'*T6>smT	tXi((	)T&]t ]t ]tIa ]t~Xc] d > "&$(oo o 3-	o
 SMo 
o> >x} >$ >   "&"&/>/> /> 3-	/>
 3-/> 
/>d `d*;*;!%*;7;*;OWX[}*;	eCc3h'(	)*;^  "& ff f 	f
 3-f fP7 7(5d3iQUVYQZAZ;[2\ 7$, ,49 ,* #'"&;7;7 3-;7 	;7
 ;7 ;7 3-;7 
tCy$sDcN233	4;7 ;7z9?S 9? 9? 9?[_ 9?v+S +x + b bt bx} bbfgjlogobp bH8$$  . /@ E  E N N NN Nr@   rK   c                      ^  \ 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fsrb   r,   c                 |  >  UR                  X#S9U l        UR                  SS5      S:X  a-  UR	                  U R                  R                  5       S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   r3   B.
Make sure the repository and revision exist before writing data.r   Fr   )	r   r   FileNotFoundErrorr7   r   r>   detailsrR   rS   )r;   rJ  rb   r,   r   r_   rY   s         r=   rS   HfFileSystemFile.__init__  s    	!#!ID ::fd#t+774#5#5#?#?#Au7UDL//99;FvF ! 	fjj,,'c\] 	s   B 
B;&B66B;c                 D   > [        U S5      (       d  g [        TU ]	  5       $ Nr   hasattrrR   __del__r;   rY   s    r=   rU  HfFileSystemFile.__del__       t_--w  r@   startendr1   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UUS[        R                  S9n[        U5        UR                  $ )	Nrangezbytes=-r   r  GETi  i  i  i  )r"  retry_on_status_codesr\   )rJ  rU   r+  r   r   r+   r,   r-   r*   rO   r&   r   HF_HUB_DOWNLOAD_TIMEOUTr%   r   )r;   rY  rZ  r"  r  rs         r=   _fetch_rangeHfFileSystemFile._fetch_range  s    veWAcAgY/
ggll,,.
 &&..''00''44((22WW%%
 "655
 	Ayyr@   c                 8    [         R                  " SSS9U l        g )Nzhffs-F)prefixdelete)tempfileNamedTemporaryFiler  r9  s    r=   _initiate_upload!HfFileSystemFile._initiate_upload  s    !44GERr@   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   r  writer.  rJ  rU   r   r   r   r-   r+   rP   r*   r,   r   r7   r   remover   r>   )r;   rl  blocks      r=   _upload_chunkHfFileSystemFile._upload_chunk  s"     "U#NN  "GGLL$$ $ 3 3!//<<**22ggmm,,66++44#{{/?@#';;??3G#H % 	 IIdnn))*GG$$''113 %  r@   c                 T  > U R                   S:X  ax  Ub  US:X  ao  U R                  S:X  a_  U R                  R                  U R                  SSS9 nUR                  5       nU =R                  [        U5      -  sl        UsSSS5        $ [        TU ]  U5      $ ! , (       d  f       N= f)a	  Read remote file.

If `length` is not provided or is -1, the entire file is downloaded and read. On POSIX systems and if
`hf_transfer` is not enabled, 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   locrJ  r   rb   r   r   rR   )r;   lengthr   r   rY   s       r=   r   HfFileSystemFile.read  s     99&.FbLdhhRSmdii!<ffhCH$ =< w|F##	 =<s   0B
B'c                 L    U R                   R                  U R                  5      $ r?  rJ  r  rb   r9  s    r=   r  HfFileSystemFile.url      ww{{499%%r@   )rO  r   r  r?  r@  )Fr   )rB   rC   rD   rE   rK   rG   r   rS   rU  rE  bytesrc  rj  rC  rr  r   r  rI   rG  rH  s   @r=   r   r     st    < s hsm  !# C E ,S4 D *$&S & &r@   r   c                      ^  \ rS rSr    SS\S\S\S\\   S\S\4U 4S jjjrSS	\S
\4S jjr	SS\4S jjr
S\4S jrU 4S jrS rSrU =r$ )r   i  rJ  rb   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   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 rL  z;HfFileSystemStreamFile only supports reading but got mode=''r   r   r3   rM  )r   r   r   r   r  )
rf   r   r   rN  r7   r>   rO  rR   rS   response)
r;   rJ  rb   r   r,   r   r  r   r_   rY   s
            r=   rS   HfFileSystemStreamFile.__init__  s    ?YZdYefgg^_i^jkll$;Z[_Z``abcc	!#!ID !% 2 2 < < >M"",,.	
59]g	
kq	
 -1 ! 	fjj,,'c\] -	s    B, ,
C%6%C  C%ru  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)ru  rf   )r;   ru  r  s      r=   r-  HfFileSystemStreamFile.seek  s0    !8!((?v{899r@   rv  c           
         US:  a  U4OSnU R                   c  [        U R                  R                  U R                  R                  U R                  R
                  U R                  R                  U R                  R                  S9n[        SUU R                  R                  R                  5       SS[        R                  S9U l         [        U R                   5         U R                   R                  R                   " U6 nU =R&                  [)        U5      -  sl        U$ ! ["         GaE    U R                   R%                  5         [        U R                  R                  U R                  R                  U R                  R
                  U R                  R                  U R                  R                  S9n[        SUSS	U R&                  -  0U R                  R                  R                  5       ESS[        R                  S9U l         [        U R                   5         U R                   R                  R                   " U6 n GNF! ["         a    U R                   R%                  5         e f = ff = f)
Nr   rA   r  r^  r_  T)r"  r`  streamr\   Rangez	bytes=%d-)r  r   r   r+   r,   r-   r*   rJ  rO   r&   rU   r+  r   ra  r%   rawr   rD  r.  ru  r   )r;   rv  	read_argsr  r   s        r=   r   HfFileSystemStreamFile.read$  s   !'1VI"	== **22++44++88,,66))C )668&:!99DM  .	--##(()4C4 	CH
5  	MM! **22++44++88,,66))C ) +"8]DGGLL<Z<Z<\]&:!99DM  .mm'',,i8 ##%-	s   ##D& &C?I6&#I&I22I6r1   c                 L    U R                   R                  U R                  5      $ r?  ry  r9  s    r=   r  HfFileSystemStreamFile.urlU  r{  r@   c                 D   > [        U S5      (       d  g [        TU ]	  5       $ rR  rS  rV  s    r=   rU  HfFileSystemStreamFile.__del__X  rX  r@   c                     [         U R                  U R                  U R                  U R                  U R
                  R                  44$ r?  )reopenrJ  rb   r   	blocksizecacher   r9  s    r=   
__reduce__!HfFileSystemStreamFile.__reduce__^  s0    DIIt~~tzzWWWr@   )rO  r   r  )r   Nr   r  )r   r|  )rB   rC   rD   rE   rK   rG   r   rE  rS   r-  r   r  rU  r  rI   rG  rH  s   @r=   r   r     s    
 "&   	
 3-   >: :S :/3 /b&S &!X Xr@   r   r,   r1   c                 P    [         R                  U 5      (       a  U $ [        U 5      $ r?  )rq   ry   
safe_quoter   s    r=   r:   r:   b  s#    288BB8\
S[H\\r@   sc                     [        U SS9$ )Nr3   )safe)r   )r  s    r=   r  r  f  s    r@   rb   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))rx   r   r   r$   rN  )rb   r{   msgs      r=   rv   rv   j  se    
C#.//-.	C.	/	/+,	C*	+	+./
C
 c)r@   rJ  r   r   r  c                 "    U R                  XX4S9$ )Nr  )r   )rJ  rb   r   r   r  s        r=   r  r  u  s    774z7QQr@   )Gr   rerh  collectionsr   dataclassesr   r   r   	itertoolsr   pathlibr   typingr	   r
   r   r   r   r   r   r   urllib.parser   r   fsspecfsspec.callbacksr   r   r   fsspec.utilsr   requestsr   r3   r   _commit_apir   r   errorsr   r   r   file_downloadr   r    hf_apir!   r"   r#   utilsr$   r%   r&   compileVERBOSErq   r(   AbstractFileSystemrK   specAbstractBufferedFiler   r   rG   r:   r  rD  rv   rE  r  rA   r@   r=   <module>r     sP   	 	   (    N N N '  J J #   C V V / 3 3 G G !jj
 JJ  B B B*jN6,, jNZS&v{{77 S&lbXV[[== bXJ]C ]C ]# # * *(9*= *( *R| R3 Rc Rs RPS Rr@   