Ë
    rPêjŠ= ã            
       óà  — U d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ d d	lmZmZ d d
lmZmZmZ d dlmZmZ d dlZd dl Z d dl!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@mAZA ddlBmCZCmDZDmEZEmFZFmGZG ddlHmIZImJZJmKZKmLZLmMZMmNZN ddlOmPZP ddlQmRZRmSZS ddlTmUZU e G d„ d«      «       ZVe G d„ deV«      «       ZWe G d „ d!eV«      «       ZX eYej´                  «      Z[ee\d"<   d#eFeGz  e1z  e2z  d$e]d%e^e]ef   fd&„Z_d'Z` G d(„ d)«      Za G d*„ d+e[«      Zb G d,„ d-ej´                  eb¬.«      Zc G d/„ d0ejÈ                  jÊ                  «      Zf G d1„ d2ejÈ                  jÊ                  «      Zgd3e]d%e]fd4„Zhd5e]d%e]fd6„Zid7e]d8ejdz  d%efd9„Zkd:ecd7e]d;e]d<eld=e]f
d>„Zmd?„ Zn ec«       Zoy)@é    N)Údeque)ÚIterableÚIterator)ÚThreadPoolExecutor)Ú	ExitStack)Údeepcopy)Ú	dataclassÚfieldÚreplace)Údatetime)ÚPathÚPurePosixPath)ÚAnyÚNoReturnÚUnion)ÚquoteÚunquote)Ú_DEFAULT_CALLBACKÚNoOpCallbackÚTqdmCallback)Úapply_config)Ú
isfilelikeé   )Ú	constants)ÚBUCKET_FOLLOWERSÚBUCKET_FOLLOWERS_LOCKÚBucketFileChangeÚBucketFollower)Ú
BucketFileÚBucketFolder)ÚCommitOperationCopyÚCommitOperationDelete)Ú_validate_relative_filename)ÚBucketNotFoundErrorÚEntryNotFoundErrorÚHfHubHTTPErrorÚRepositoryNotFoundErrorÚRevisionNotFoundError)Ú
hf_hub_urlÚhttp_getÚxet_get)ÚSPECIAL_REFS_REVISION_REGEXÚHfApiÚLastCommitInfoÚRepoFileÚ
RepoFolder)ÚHFValidationErrorÚXetFileDataÚhf_raise_for_statusÚhttp_backoffÚhttp_stream_backoffÚparse_hf_uri)Úis_xet_available)ÚXetTokenTypeÚxet_connection_info_refresh_url)Úmd5c                   ó2   — e Zd ZU dZeed<   eed<   defd„Zy)ÚHfFileSystemResolvedPathz_Top level Data structure containing information about a resolved Hugging Face file system path.ÚrootÚpathÚreturnc                 óV   — | j                   › d| j                  › �j                  d«      S )Nú/)r=   r>   Úrstrip©Úselfs    úc/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/huggingface_hub/hf_file_system.pyÚ	unresolvez"HfFileSystemResolvedPath.unresolve2   s&   € Ø—)‘)�˜A˜dŸi™i˜[Ð)×0Ñ0°Ó5Ð5ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__rF   © rG   rE   r<   r<   +   s   … áià
ƒIØ
ƒIð6˜3ô 6rG   r<   c                   óœ   — e Zd ZU dZeed<   eed<   eed<   eed<    ed¬«      Zeed<    ed¬«      Zeed	<    ed
d¬«      Z	ed
z  ed<   d„ Z
y
)Ú"HfFileSystemResolvedRepositoryPathzLData structure containing information about a resolved path in a repository.Ú	repo_typeÚrepo_idÚrevisionÚpath_in_repoF©Úinitr=   r>   N)ÚdefaultÚreprÚ_raw_revisionc                 ób  — t         j                  j                  | j                  d«      | j                  z   }| j
                  r|› d| j
                  › �| _        nD| j                  t         j                  k7  r |› dt        | j                  «      › �| _        n|| _        | j                  | _        y )NÚ ú@)r   ÚREPO_TYPES_URL_PREFIXESÚgetrQ   rR   rY   r=   rS   ÚDEFAULT_REVISIONÚsafe_revisionrT   r>   )rD   Ú	repo_paths     rE   Ú__post_init__z0HfFileSystemResolvedRepositoryPath.__post_init__D   sŽ   € Ü×5Ñ5×9Ñ9¸$¿.¹.È"ÓMÐPT×P\ÑP\Ñ\ˆ	Ø×ÒØ$˜+ Q t×'9Ñ'9Ð&:Ð;ˆD�IØ�]‰]œi×8Ñ8Ò8Ø$˜+ Q¤}°T·]±]Ó'CÐ&DÐEˆD�Ià!ˆDŒIØ×%Ñ%ˆ�	rG   )rH   rI   rJ   rK   rL   rM   r
   r=   r>   rY   rb   rN   rG   rE   rP   rP   6   sT   … áVàƒNØƒLØƒMØÓÙ˜5Ô!€Dˆ#Ó!Ù˜5Ô!€Dˆ#Ó!ñ !&¨d¸Ô ?€M�3˜‘:Ó?ó&rG   rP   c                   ó>   — e Zd ZU dZeed<    ed¬«      Zeed<   d„ Zy)ÚHfFileSystemResolvedBucketPathzHData structure containing information about a resolved path in a bucket.Ú	bucket_idFrU   r=   c                 ó,   — d| j                   z   | _        y )Núbuckets/)re   r=   rC   s    rE   rb   z,HfFileSystemResolvedBucketPath.__post_init__V   s   € Ø §¡Ñ/ˆ�	rG   N)	rH   rI   rJ   rK   rL   rM   r
   r=   rb   rN   rG   rE   rd   rd   O   s   … áRàƒNÙ˜5Ô!€Dˆ#Ó!ó0rG   rd   Ú_cached_baseÚ	path_infoÚ
cache_pathr?   c           	      ó¬  — t        | t        «      rG|| j                  d| j                  | j                  | j
                  | j                  | j                  dœS t        | t        «      r1|| j                  d| j
                  | j                  | j                  dœS t        | t        «      r|dd| j                  | j                  dœS |dd| j                  dœS )zNConvert an API path info into the dict format used in `HfFileSystem.dircache`.Úfile©ÚnameÚsizeÚtypeÚblob_idÚlfsÚxet_hashÚlast_commitÚsecurity)rn   ro   rp   rs   ÚmtimeÚuploaded_atr   Ú	directory©rn   ro   rp   Útree_idrt   )rn   ro   rp   rw   )Ú
isinstancer/   ro   rq   rr   rs   rt   ru   r   rv   rw   r0   rz   )ri   rj   s     rE   Ú_cache_info_from_path_infor|   ^   sÛ   € ô �)œXÔ&àØ—N‘NØØ ×(Ñ(Ø—=‘=Ø!×*Ñ*Ø$×0Ñ0Ø!×*Ñ*ñ	
ð 		
ô �)œZÔ(àØ—N‘NØØ!×*Ñ*Ø—_‘_Ø$×0Ñ0ñ
ð 	
ô �)œZÔ(àØØØ ×(Ñ(Ø$×0Ñ0ñ
ð 	
ð ØØØ ×,Ñ,ñ	ð rG   é   c                   óÜ   — e Zd ZdZdddededz  fd„Zded	ee	e
ef      fd
„Zdeded	dfd„Zdeded	dfd„Zdeded	dfd„Zde	e
ef   ded	efd„Zdeded	dfd„Zdededeeez     d	dfd„Zy)Ú_ParallelRepoTreeListingah  List a repo tree recursively, listing independent directories in parallel.

    The Hub `tree` endpoint returns at most 1000 entries per request (50 when `expand=True`) and
    pagination is cursor-based: a page can only be fetched once the previous one has been received.
    Listing a repo with 800k files through a single request therefore requires ~800 *sequential*
    requests, which takes many minutes.

    To work around this, the listing is split into independent sub-trees listed concurrently by a
    thread pool. Since sub-directories can only be known by listing their parent, a sub-tree is split
    lazily while it is being paginated:

    - A sub-tree that fits in a single page is kept as-is: it costs one request, exactly like it would
      without parallelization. Small sub-trees are therefore never split (no request is wasted).
    - Once `_MIN_PAGES_BEFORE_SPLIT` pages have been fetched without reaching the end of the sub-tree,
      the sub-tree is split if (and only if) the sub-directories seen so far hold enough entries to
      "pay" for their own request (see `_is_worth_splitting`). In that case the directory is listed
      one level deep, and each of its sub-directories is dispatched to a new task applying the same
      logic recursively. If splitting is not worth it, the pagination is simply followed to its end.

    The number of requests stays close to the theoretical minimum (one request per 1000 entries)
    while independent directories are listed concurrently. Listing `datasets/allenai/objaverse`
    (~800k files spread in 160 sub-directories) goes from ~30 minutes to ~30 seconds.
    ÚfsÚHfFileSystemÚexpand_infoÚmaxdepthNc                 óÐ   — || _         || _        || _        t        |j                  d¬«      | _        t        j                  «       | _        d| _	        d | _
        g | _        i | _        y )Nz
hf-ls-tree)Úmax_workersÚthread_name_prefixr   )r€   r‚   rƒ   r   r…   ÚpoolÚ	threadingÚ	ConditionÚlockÚpending_tasksÚerrorÚoutÚlistings)rD   r€   r‚   rƒ   s       rE   Ú__init__z!_ParallelRepoTreeListing.__init__¤   sX   € ØˆŒØ&ˆÔØ ˆŒÜ&°2·>±>ÐVbÔcˆŒ	ä×'Ñ'Ó)ˆŒ	ØˆÔØ+/ˆŒ
Ø)+ˆŒØ9;ˆ�rG   Úresolved_pathr?   c                 óæ  — | j                  |d¬«       	 | j                  5  | j                  r'| j                  j                  «        | j                  rŒ'ddd«       | j                  j                  dd¬«       | j
                  �| j
                  ‚| j                  S # 1 sw Y   ŒJxY w# t        $ r}| j
                  xs || _        ‚ d}~ww xY w# | j                  j                  dd¬«       w xY w)zRList the full tree below `resolved_path` and return the path infos (in any order).r   )ÚdepthNT)ÚwaitÚcancel_futures)	Ú_submitrŠ   r‹   r“   ÚBaseExceptionrŒ   r‡   Úshutdownr�   )rD   r�   Úexcs      rE   Úrunz_ParallelRepoTreeListing.run°   sÉ   € à�‰�]¨!ˆÔ,ð	?Ø—‘ñ %Ø×(Ò(Ø—I‘I—N‘NÔ$ð ×(Ó(÷%ð �I‰I×Ñ D¸ÐÔ>Ø�:‰:Ð!Ø—*‘*ÐØ�x‰xˆ÷%ð %ûô ò 	ØŸ™Ò* sˆDŒJØûð	ûð �I‰I×Ñ D¸ÐÕ>ús:   •B* ¡3BÁB* ÂB'Â#B* Â*	CÂ3C	Ã	CÃC ÃC0r’   c                 óê   — | j                   5  | j                  �
	 ddd«       y| xj                  dz  c_        ddd«       | j                  j	                  | j
                  ||«       y# 1 sw Y   Œ1xY w)z\Dispatch the listing of a sub-tree to the thread pool (no-op if the listing already failed).Nr   )rŠ   rŒ   r‹   r‡   ÚsubmitÚ	_run_task)rD   r�   r’   s      rE   r•   z _ParallelRepoTreeListing._submitÃ   sd   € à�Y‰Yñ 	$Ø�z‰zÐ%Ø÷	$ð 	$ð ×Ò !Ñ#Õ÷	$ð 	�	‰	×Ñ˜Ÿ™¨¸Õ>÷		$ð 	$ús   �A)¤A)Á)A2c                 ól  — 	 | j                   5  | j                  d u}d d d «       s| j                  ||«       | j                   5  | xj                  dz  c_        | j                   j                  «        d d d «       y # 1 sw Y   ŒbxY w# t        $ r?}| j                   5  | j                  €|| _        d d d «       n# 1 sw Y   nxY wY d }~Œ”d }~ww xY w# 1 sw Y   y xY w# | j                   5  | xj                  dz  c_        | j                   j                  «        d d d «       w # 1 sw Y   w xY wxY w)Nr   )rŠ   rŒ   Ú_list_subtreer–   r‹   Ú
notify_all)rD   r�   r’   Úfailedr˜   s        rE   rœ   z"_ParallelRepoTreeListing._run_taskË   s  € ð	'Ø—‘ñ 0ØŸ™¨4Ð/�÷0áØ×"Ñ" =°%Ô8ð —‘ñ 'Ø×"Ò" aÑ'Õ"Ø—	‘	×$Ñ$Ô&÷'ð '÷0ð 0ûô ò 	%Ø—‘ñ %Ø—:‘:Ð%Ø!$�D”J÷%÷ %ñ %ÿûð	%ú÷
'ð 'û�—‘ñ 'Ø×"Ò" aÑ'Õ"Ø—	‘	×$Ñ$Ô&÷'÷ 'ñ 'ýs{   ‚B
 ŽA>�B
 Á0CÁ>BÂB
 Â
	CÂCÂB<Â3	CÂ<C	ÃCÃC! ÃCÃC! ÃCÃ!D3Ã.0D'Ä	D3Ä'D0Ä,D3c                 ó^  — | j                   �"|| j                   k\  r| j                  ||«       yg }i }d}|j                  r|j                  dz   nd}| j                  j                  j                  |j                  |j                  xs dd| j                  |j                  |j                  ¬«      }t        |d¬«      D ]Ø  \  }\  }	}
| j                  � y|j                  |	«       t        |t        |	«      «      }|	D ]d  }|j                  j!                  |«      sŒ|j                  t        |«      d j#                  d«      \  }}}|sŒM|j%                  |d«      dz   ||<   Œf |
rŒ©|t&        k\  sŒ³| j)                  ||«      sŒÆ| j                  ||«        y | j+                  |||«       y)	zÊList a single sub-tree, splitting it in sub-directories if it is worth it.

        `depth` is the depth (relative to the root of the listing) of the direct children of
        `resolved_path`.
        Nr   rA   r[   T©Ú	recursiveÚexpandrS   rQ   r   )Ústart)rƒ   Ú_list_childrenr>   r€   Ú_apiÚ_iter_repo_tree_pagesrR   rT   r‚   rS   rQ   Ú	enumeraterŒ   ÚextendÚmaxÚlenÚ
startswithÚ	partitionr^   Ú_MIN_PAGES_BEFORE_SPLITÚ_is_worth_splittingÚ_record)rD   r�   r’   ÚentriesÚentries_per_folderÚmax_page_sizeÚprefixÚpagesÚpage_nbÚpageÚfinishedri   ÚfolderÚsepÚ_s                  rE   rž   z&_ParallelRepoTreeListing._list_subtreeÚ   s¦  € ð �=‰=Ð$¨°$·-±-Ò)?ð ×Ñ ¨uÔ5Øà/1ˆØ-/ÐØˆØ-:×-?Ò-?�×#Ñ# cÒ)ÀRˆà—‘—‘×2Ñ2Ø×!Ñ!Ø×&Ñ&Ò.¨$ØØ×#Ñ#Ø"×+Ñ+Ø#×-Ñ-ð 3ó 
ˆô *3°5ÀÔ)Bò 	Ñ%ˆGÑ%�d˜HØ�z‰zÐ%ÙØ�N‰N˜4Ô Ü ¬s°4«yÓ9ˆMØ!ò W�	Ø —~‘~×0Ñ0°Ô8ØØ!*§¡´°F³°Ð!>×!HÑ!HÈÓ!M‘�˜˜QÚØ1C×1GÑ1GÈÐPQÓ1RÐUVÑ1VÐ& vÒ.ðWò ØÔ6Ó6Ø×,Ñ,Ð-?ÀÕOà×#Ñ# M°5Ô9Ùð#	ð( 	�‰�] E¨7Õ3rG   r³   Ú	page_sizec                 ól   — t        |«      xr( t        |j                  «       «      |t        |«      z  k\  S )zNSplit only if sub-directories hold at least a full page of entries on average.)ÚboolÚsumÚvaluesr¬   )rD   r³   r½   s      rE   r°   z,_ParallelRepoTreeListing._is_worth_splitting
  s4   € äÐ&Ó'Òs¬CÐ0B×0IÑ0IÓ0KÓ,LÐPYÔ\_Ð`rÓ\sÑPsÑ,sÐsrG   c           
      óÀ  — t        | j                  j                  j                  |j                  |j
                  xs dd| j                  |j                  |j                  ¬«      «      }| j                  |||«       | j                  �|dz   | j                  kD  ry|D ]=  }t        |t        «      sŒ| j                  t        ||j                  ¬«      |dz   «       Œ? y)zåList the direct children of a directory and dispatch each sub-directory to a new task.

        Sub-directories are only dispatched as long as their content is at a depth that is still
        requested (see `maxdepth`).
        NFr¢   r   ©rT   )Úlistr€   r§   Úlist_repo_treerR   rT   r‚   rS   rQ   r±   rƒ   r{   r0   r•   r   r>   )rD   r�   r’   Úchildrenri   s        rE   r¦   z'_ParallelRepoTreeListing._list_children  sÇ   € ô Ø�G‰G�L‰L×'Ñ'Ø×%Ñ%Ø×*Ñ*Ò2¨dØØ×'Ñ'Ø&×/Ñ/Ø'×1Ñ1ð (ó ó	
ˆð 	�‰�] E¨8Ô4Ø�=‰=Ð$¨°©°T·]±]Ò)BØØ!ò 	]ˆIÜ˜)¤ZÕ0Ø—‘œW ]ÀÇÁÔPÐRWÐZ[ÑR[Õ\ñ	]rG   Ú
path_infosc                 ó¨  — |j                  «       }g }i }|D ]¹  }|j                  dz   |j                  z   }t        ||«      }	||k7  r:|j	                  | j
                  j                  |«      g «      j                  |	«       ||t        |«      d j                  d«      z   dz
  }
| j                  �|
| j                  k  sŒ©|j                  |	«       Œ» | j                  5  | j                  j                  |«       |j                  «       D ]0  \  }}| j                  j	                  |g «      j                  |«       Œ2 	 ddd«       y# 1 sw Y   yxY w)zHStore freshly listed entries in the (shared) output and directory cache.rA   Nr   )rF   r=   r>   r|   Ú
setdefaultr€   Ú_parentÚappendr¬   Úcountrƒ   rŠ   r�   rª   ÚitemsrŽ   )rD   r�   r’   rÇ   r>   r�   rŽ   ri   rj   Úcache_path_infoÚentry_depthÚparentÚpath_infos_s                rE   r±   z _ParallelRepoTreeListing._record%  s4  € ð ×&Ñ&Ó(ˆØ$&ˆØ46ˆØ#ò 	,ˆIØ&×+Ñ+¨cÑ1°I·N±NÑBˆJÜ8¸ÀJÓOˆOØ˜TÒ!Ø×#Ñ# D§G¡G§O¡O°JÓ$?ÀÓD×KÑKÈOÔ\Ø *¬S°«Y¨[Ð"9×"?Ñ"?ÀÓ"DÑDÀqÑHˆKØ�}‰}Ð$¨°t·}±}Ó(DØ—
‘
˜?Õ+ð	,ð �Y‰Yñ 	IØ�H‰H�O‰O˜CÔ Ø'/§~¡~Ó'7ò IÑ#�˜Ø—‘×(Ñ(¨°Ó4×;Ñ;¸KÕHñI÷	I÷ 	Iñ 	Iús   ÃAEÅE)rH   rI   rJ   rK   r¿   Úintr�   rP   rÄ   ÚdictrL   r   r™   r•   rœ   rž   r°   r¦   r   r/   r0   r±   rN   rG   rE   r   r   ‹   s$  „ ñð0
<˜>ð 
<¸ð 
<ÈÈdÉ
ó 
<ðÐ!Cð ÈÈTÐRUÐWZÐRZÉ^ÑH\ó ð&?Ð%Gð ?ÐPSð ?ÐX\ó ?ð'Ð'Ið 'ÐRUð 'ÐZ^ó 'ð.4Ð+Mð .4ÐVYð .4Ð^bó .4ð`t°d¸3À¸8±nð tÐQTð tÐY]ó tð]Ð,Nð ]ÐWZð ]Ð_có ]ð.Ià9ðIð ðIð ˜X¨
Ñ2Ñ3ð	Ið
 
ôIrG   r   c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )Ú_Cachedaò  
    Metaclass for caching HfFileSystem instances according to the args.

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

    This is a slightly modified version of `fsspec.spec._Cached` to improve it.
    In particular in `_tokenize` the pid isn't taken into account for the
    `fs_token` used to identify cached instances. The `fs_token` logic is also
    robust to defaults values and the order of the args. Finally new instances
    reuse the states from sister instances in the main thread.
    c                 ó2   •— t        ‰| �  |i |¤Ž i | _        y ©N)Úsuperr�   Ú_cache)ÚclsÚargsÚkwargsÚ	__class__s      €rE   r�   z_Cached.__init__M  s   ø€ ä‰Ñ˜$Ð) &Ò)ð ˆ�
rG   c                 ó¾  — t        | |«      }|j                  dd«      } | j                  | t        j                  «       g|¢­i |¤Ž} | j                  | t        j
                  «       j                  g|¢­i |¤Ž}|s0| j                  r$|| j                  v r|| _	        | j                  |   S t        j                  | g|¢­i |¤Ž}|s\| j                  rP|| j                  v rB| j                  |   j                  «       }|j                  «       D ]  \  }}	t        |||	«       Œ ||_        ||_        ||_        | j                  r|s|| _	        || j                  |<   |S )NÚskip_instance_cacheF)r   ÚpopÚ	_tokenizerˆ   Ú	get_identÚmain_threadÚidentÚcachablerÙ   Ú_latestrp   Ú__call__Ú_get_instance_staterÍ   ÚsetattrÚ
_fs_token_Ústorage_argsÚstorage_options)
rÚ   rÛ   rÜ   ÚskipÚfs_tokenÚfs_token_main_threadÚobjÚinstance_stateÚattrÚstate_values
             rE   rç   z_Cached.__call__U  sH  € ô ˜c 6Ó*ˆØ�z‰zÐ/°Ó7ˆØ �3—=‘= ¤i×&9Ñ&9Ó&;ÐM¸dÒMÀfÑMˆØ,˜sŸ}™}¨S´)×2GÑ2GÓ2I×2OÑ2OÐaÐRVÒaÐZ`ÑaÐÙ˜Ÿš¨°S·Z±ZÑ)?à"ˆCŒKØ—:‘:˜hÑ'Ð'ô —-‘- Ð5 dÒ5¨fÑ5ˆCÙ˜CŸLšLÐ-AÀSÇZÁZÑ-Oà!$§¡Ð,@Ñ!A×!UÑ!UÓ!W�Ø)7×)=Ñ)=Ó)?ò 4Ñ%�D˜+Ü˜C  {Õ3ð4à%ˆCŒNØ#ˆCÔØ"(ˆCÔØ�|Š|¡DØ&�”Ø'*�—
‘
˜8Ñ$ØˆJrG   )rH   rI   rJ   rK   r�   rç   Ú__classcell__©rÝ   s   @rE   rÕ   rÕ   =  s   ø„ ñôörG   rÕ   c                   ó&  ‡ — e Zd ZdZdZdZdddddddœdedz  deez  dz  d	edz  d
edz  dededz  fˆ fd„Z	e
dedefd„«       Zdedededz  deeedz  f   fd„Zdedeeedz  f   fd„Z	 dBdededz  deez  fd„ZdBdedz  ddfd„Zdeddfd„Zdeddfd„Zdedee   ddfd„Zdeddfd„Z	 	 	 dCdeded	edz  dedz  ded    f
d!„ZdBdededz  ddfd"„Z	 	 	 dDded#ed$edz  dedz  ddf
d%„Z	 dEded&ed'ededz  deeeee f   z     f
d(„Z!	 	 	 	 	 dFded#ed'ededz  d
edz  d$edz  fd)„Z"deddfd*„Z#ded+ed#edee$e%z     fd,„Z&dede'eeee   ee   f      fˆ fd-„Z(dBded$edz  dee   fˆ fd.„Z)	 	 	 	 	 dGded$edz  d/ed&ed'ededz  dee   eeeee f   f   z  fd0„Z*dBd1ed2ededz  ddfd3„Z+dede,fd4„Z-dHded'ededz  deee f   fd5„Z.d6„ Z/d7„ Z0d8„ Z1dedefd9„Z2d:eez  d;eee f   de3dz  fd<„Z4de5dfdIˆ fd=„Z6e7d>„ «       Z8d?„ Z9d@„ Z:dA„ Z;ˆ xZ<S )Jr�   a$  
    Access a remote Hugging Face Hub repository as if were a local file system.

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

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

    * Models, Datasets and Spaces repositories:

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

    * Buckets (generic storage):

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

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

    Args:
        endpoint (`str`, *optional*):
                Endpoint of the Hub. Defaults to <https://huggingface.co>.
        token (`bool` or `str`, *optional*):
            A valid user access token (string). Defaults to the locally saved
            token, which is the recommended method for authentication (see
            https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
            To disable authentication, pass `False`.
        block_size (`int`, *optional*):
            Block size for reading and writing files.
        expand_info (`bool`, *optional*):
            Whether to expand the information of the files.
        max_workers (`int`, *optional*):
            Maximum number of concurrent requests used to list large directories in parallel (see
            [`~HfFileSystem.find`]). Defaults to 16. Set it to 1 to disable parallel listings.
        live_follow (`bool`, *optional*):
            Whether to follow file changes in buckets as they happen on the Hub, so that cached listings stay
            fresh without manual [`HfFileSystem.invalidate_cache`] calls.
            When enabled, listing a bucket opens a background connection to the Hub event feed for that bucket.
            Has no effect on model, dataset and space repositories (the Hub does not feed changes for those).
        **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)
    ```
    r[   ÚhfNé   )ÚendpointÚtokenÚ
block_sizer‚   r…   Úlive_followrù   rú   rû   r‚   r…   rü   c                ó  •— t        ‰	| �  |i |¤Ž |xs t        j                  | _        || _        t        ||¬«      | _        || _        || _	        || _
        || _        t        «       | _        i | _        i | _        i | _        y )N)rù   rú   )rØ   r�   r   ÚENDPOINTrù   rú   r-   r§   rû   r‚   r…   rü   r   Ú_pending_bucket_changesÚ_repo_and_revision_exists_cacheÚ_bucket_exists_cacheÚdircache)
rD   rù   rú   rû   r‚   r…   rü   rÛ   rì   rÝ   s
            €rE   r�   zHfFileSystem.__init__À  s…   ø€ ô 	‰Ñ˜$Ð2 /Ò2Ø Ò6¤I×$6Ñ$6ˆŒØˆŒ
Ü 8°5Ô9ˆŒ	Ø$ˆŒØ&ˆÔØ&ˆÔØ&ˆÔäY^ÓY`ˆÔ$ð rtˆÔ,àNPˆÔ!ð :<ˆ�rG   Úthreading_identr?   c                 ó(  — |j                  d«      xs t        j                  |d<   |j                  d«      |d<   t        |«      D �ci c]  }|||   “Œ
 }}| |||f}t	        t        |«      j                  «       «      }|j                  «       S c c}w )zDeterministic token for cachingrù   rú   )r^   r   rþ   Úsortedr:   rL   ÚencodeÚ	hexdigest)rÚ   r  rÛ   rÜ   ÚkeyÚtokenize_argsÚhs          rE   rá   zHfFileSystem._tokenizeß  s‹   € ð $ŸZ™Z¨
Ó3ÒI´y×7IÑ7IˆˆzÑØ Ÿ*™* WÓ-ˆˆw‰Ü.4°V«nÖ= s�#�v˜c‘{Ñ"Ð=ˆÐ=à˜o¨t°VÐ<ˆÜ”�MÓ"×)Ñ)Ó+Ó,ˆØ�{‰{‹}Ðùò	 >s   ÁBrQ   rR   rS   c                 óâ  — |||f| j                   vrR	 | j                  j                  |||t        j                  ¬«       d| j                   |||f<   d| j                   ||d f<   | j                   |||f   S # t
        t        f$ r2}d|f| j                   |||f<   d|f| j                   ||d f<   Y d }~ŒNd }~wt        $ r0}d|f| j                   |||f<   d| j                   ||d f<   Y d }~Œ…d }~ww xY w)N)rS   rQ   Útimeout©TNF)r   r§   Ú	repo_infor   ÚHF_HUB_ETAG_TIMEOUTr'   r1   r(   )rD   rQ   rR   rS   Úes        rE   Ú_repo_and_revision_existz%HfFileSystem._repo_and_revision_existë  s!  € ð �w Ð)°×1UÑ1UÑUð^Ø—	‘	×#Ñ#Ø h¸)ÌY×MjÑMjð $ô ð Xb�×4Ñ4°iÀÈ(Ð5SÑTØS]�×4Ñ4°iÀÈ$Ð5OÑPØ×3Ñ3°YÀÈÐ4RÑSÐSøô ,Ô->Ð?ò \ØW\Ð^_ÐW_�×4Ñ4°iÀÈ(Ð5SÑTØSXÐZ[ÐS[�×4Ñ4°iÀÈ$Ð5OÖPûÜ(ò ^ØW\Ð^_ÐW_�×4Ñ4°iÀÈ(Ð5SÑTØS]�×4Ñ4°iÀÈ$Ð5OÖPûð^ús#   “-A6 Á6C.Â(B2Â2C.Â>&C)Ã)C.re   c                 óà   — || j                   vr+	 | j                  j                  |«       d| j                   |<   | j                   |   S # t        $ r}d|f| j                   |<   Y d }~Œ.d }~ww xY w)Nr  F)r  r§   Úbucket_infor$   )rD   re   r  s      rE   Ú_bucket_existszHfFileSystem._bucket_existsþ  st   € Ø˜D×5Ñ5Ñ5ðBØ—	‘	×%Ñ% iÔ0ð 8B�×)Ñ)¨)Ñ4Ø×(Ñ(¨Ñ3Ð3øô	 'ò @Ø7<¸a°x�×)Ñ)¨)Ö4ûð@ús   �A	 Á		A-ÁA(Á(A-r>   c                 ó˜  — | j                  |«      }|st        d«      ‚|j                  d«      dk(  rt        d|› d�«      ‚t	        t
        j                  › |› �«      }|j                  rM| j                  |j                  «      \  }}|st        ||«       t        |j                  |j                  ¬«      S |�ò|j                  �æ|j                  |k7  r×|j                  d«      d   t
        j                  v r|j                  dd«      d   n|}|j                  d	d«      \  }}d|v r|j                  dd«      n|d
f\  }	}
t!        |	«      }||k7  rt        d|› d|› d�«      ‚| j#                  |j$                  ||«      \  }}|st        ||«       t'        |j$                  |||
|	¬«      S |j                  �|€|j                  }| j#                  |j$                  |j                  |«      \  }}|st        ||«       d}d	|v r†|j                  �z|j                  d«      d   t
        j                  v r|j                  dd«      d   n|}|j                  d	d«      d   }|j                  r|dt)        |j                  «      dz     n|}|�|nt
        j*                  }t'        |j$                  |j                  ||j                  |¬«      S )a€  
        Resolve a Hugging Face file system path into its components.

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

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

        Raises:
            `ValueError`:
                If path contains conflicting revision information.
            `NotImplementedError`:
                If trying to list repositories.
        z<Access to buckets and repositories lists is not implemented.rA   r   z-Repository id must be 'namespace/name', got 'z<'. Single-segment ids (e.g. 'gpt2') are no longer supported.)re   r>   Nr   r\   r[   zRevision specified in path ("z ") and in `revision` argument ("z") are not the same.)rY   )Ú_strip_protocolÚNotImplementedErrorrÌ   Ú
ValueErrorr6   r   ÚHF_PROTOCOLÚ	is_bucketr  ÚidÚ_raise_file_not_foundrd   rT   rS   ÚsplitÚHF_URI_TYPE_PREFIXESr   r  rp   rP   r¬   r_   )rD   r>   rS   ÚparsedÚbucket_existsÚerrÚpath_without_typerR   Úafter_atÚrevision_in_pathrT   Úrevision_in_path_decodedÚrepo_and_revision_existÚraw_revisionÚraw_after_ats                  rE   Úresolve_pathzHfFileSystem.resolve_path  sä  € ð* ×#Ñ# DÓ)ˆÙÜ%Ð&dÓeÐeØ�:‰:�c‹?˜aÒÜØ?À¸vð  FBð  Cóð ô ¤×!6Ñ!6Ð 7¸°vÐ>Ó?ˆð ×ÒØ!%×!4Ñ!4°V·Y±YÓ!?ÑˆM˜3Ù Ü% d¨CÔ0Ü1¸F¿I¹IÈF×L_ÑL_Ô`Ð`ð Ð F§O¡OÐ$?ÀFÇOÁOÐW_ÒD_ð
 :>¿¹ÀC»ÈÑ9KÌy×OmÑOmÑ9m §
¡
¨3°Ó 2°1Ò 5ÐswÐØ 1× 7Ñ 7¸¸QÓ ?ÑˆG�XØGJÈhÁ¨X¯^©^¸CÀÔ-CÐ]eÐgiÐ\jÑ*Ð˜lÜ'.Ð/?Ó'@Ð$Ø'¨8Ò3Ü Ø3Ð4LÐ3MÐMmÐnvÐmwð  xLð  Móð ð ,0×+HÑ+HÈÏÉÐV]Ð_gÓ+hÑ(Ð# SÙ*Ü% d¨CÔ0Ü5Ø—‘˜W h°ÐL\ôð ð �?‰?Ð&¨8Ð+;Ø—‘ˆHà'+×'DÑ'DÀVÇ[Á[ÐRX×R[ÑR[Ð]eÓ'fÑ$Ð Ù&Ü! $¨Ô,ð $(ˆØ�$‰;˜6Ÿ?™?Ð6Ø9=¿¹ÀC»ÈÑ9KÌy×OmÑOmÑ9m §
¡
¨3°Ó 2°1Ò 5ÐswÐØ,×2Ñ2°3¸Ó:¸1Ñ=ˆLØNT×NaÒNa˜<Ð(I¬C°×0CÑ0CÓ,DÀqÑ,HÐ*IÑJÐgsˆLà'Ð3‘8¼×9SÑ9SˆÜ1Ø�K‰K˜Ÿ™ H¨f×.AÑ.AÐQ]ô
ð 	
rG   c                 ó’  — |sO| j                   j                  «        | j                  j                  «        | j                  j                  «        y	 | j	                  |«      }|j                  «       }| j                  |«       |j                  s¨t        |t        «      rq| j                  j                  |j                  |j                  dfd«       | j                  j                  |j                  |j                  |j                  fd«       y| j                  j                  |j                   d«       yy# t
        $ rƒ | j                  j                  «       D ��ci c]  \  }}|d   sŒ||“Œ nc c}}w c}}| _        | j                  j                  «       D ��ci c]  \  }}|d   sŒ||“Œ nc c}}w c}}| _        Y yw xY w)ac  
        Clear the cache for a given path.

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

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

        r   N)r  Úclearr   r  r)  ÚFileNotFoundErrorrÍ   rF   Ú_invalidate_dircache_ancestorsr>   r{   rP   rà   rQ   rR   rS   re   )rD   r>   r�   ÚkÚvs        rE   Úinvalidate_cachezHfFileSystem.invalidate_cacheW  s•  € ñ Ø�M‰M×ÑÔ!Ø×0Ñ0×6Ñ6Ô8Ø×%Ñ%×+Ñ+Õ-ðØ $× 1Ñ 1°$Ó 7�ð !×*Ñ*Ó,ˆDØ×/Ñ/°Ô5ð !×%Ò%Ü˜mÔ-OÔPØ×8Ñ8×<Ñ<Ø&×0Ñ0°-×2GÑ2GÈÐNÐPTôð ×8Ñ8×<Ñ<Ø&×0Ñ0°-×2GÑ2GÈ×I_ÑI_Ð`Ðbfõð ×-Ñ-×1Ñ1°-×2IÑ2IÈ4ÕPð &øô %ò ð &*×%IÑ%I×%OÑ%OÓ%Q÷8Ù!˜Q ÐUVÐWXÓUY�A�q‘Dñ8ùö 8�Ô4ð ?C×>WÑ>W×>]Ñ>]Ó>_×,h±d°a¸ÐcdÐefÓcg¨Q°©TÑ,hùÖ,h�Ô)Ùðús6   ÁD: Ä:&GÅ E4Å.E4Å3-GÆ F4Æ.F4Æ3GÇGc                 ój   — |r1| j                   j                  |d«       | j                  |«      }|rŒ0yy)zZDrop the cached listing of a path (unresolved) and of every one of its parent directories.N)r  rà   rÊ   ©rD   r>   s     rE   r-  z+HfFileSystem._invalidate_dircache_ancestors  s,   € áØ�M‰M×Ñ˜d DÔ)Ø—<‘< Ó%ˆDô rG   c                 óÂ   — d|› �}| j                   D �cg c]  }||k(  s|j                  |dz   «      sŒ|‘Œ  c}D ]  }| j                   j                  |d«       Œ  yc c}w )z0Drop every cached listing belonging to a bucket.rg   rA   N)r  r­   rà   )rD   re   r=   r>   Úcached_paths        rE   Ú_invalidate_bucket_treez$HfFileSystem._invalidate_bucket_tree…  s[   € à˜)˜Ð%ˆØ-1¯]©]Öj T¸dÀdºlÈdÏoÉoÐ^bÐehÑ^hÕNišDÒjò 	1ˆKØ�M‰M×Ñ˜k¨4Õ0ñ	1ùÒjs
   ”A³AÚchangesc                 ó
  — d|› �}|D ]t  }|› d|j                   › �}| j                  D �cg c]  }|j                  |dz   «      sŒ|‘Œ c}D ]  }| j                  j                  |d«       Œ  | j	                  |«       Œv yc c}w )a8  
        Apply a batch of live-follow changes to the dircache. Called by `_ls_tree`, on the thread owning the instance.

        A change is applied as an invalidation of the cached listings of every parent directory of the changed
        path (up to the bucket root), plus the subtree under that path in case it was itself listed as a
        directory. Dropping a cached listing is always safe: the next call to
        [`HfFileSystem.ls`] re-lists just that directory. Directories that were never
        listed need nothing, their first listing is fresh.
        rg   rA   N)r>   r  r­   rà   r-  )rD   re   r6  r=   Úchanger>   Úcachedr4  s           rE   Ú_apply_bucket_changesz"HfFileSystem._apply_bucket_changes‹  sŠ   € ð ˜)˜Ð%ˆØò 	6ˆFØ�V˜1˜VŸ[™[˜MÐ*ˆDØ59·]±]Öd¨6Àf×FWÑFWÐX\Ð_bÑXbÕFc¢Òdò 5�Ø—‘×!Ñ! +¨tÕ4ð5à×/Ñ/°Õ5ñ		6ùâds   ªB ÁB c           
      ó*  ‡‡‡— | j                   | j                  ‰f}t        5  |t        v rDt        |   d   xŠr6t	        | «      ‰vr| ‰t	        | «      <   | j                  ‰«       	 ddd«       yt        j                  t	        | «      | i«      Šdt        t           dz  ddfˆˆfd„Št        | j                   ‰| j                  ‰ˆfd„ˆfd„¬«      }|‰ft        |<   |j                  «        | j                  ‰«       ddd«       y# 1 sw Y   yxY w)	zjSubscribe to the live-follow thread of a bucket, shared by all instances with the same endpoint and token.r   Nr6  r?   c                 óò   •— t         5  t        ‰j                  «       «      D ]>  \  }}t        |j                  «      dk\  r‰|= Œ"|j                  j                  ‰| f«       Œ@ 	 d d d «       y # 1 sw Y   y xY w)Ni'  )r   rÄ   rÍ   r¬   rÿ   rË   )r6  Úfs_idr€   re   Úsubscriberss      €€rE   Úpushz2HfFileSystem._ensure_bucket_follower.<locals>.push«  sv   ø€ Ü*ñ TÜ%)¨+×*;Ñ*;Ó*=Ó%>ò T™	˜˜rÜ˜r×9Ñ9Ó:¸fÒDà +¨EÑ 2à×6Ñ6×=Ñ=¸yÈ'Ð>RÕSñT÷T÷ Tñ Tús   ˆAA-Á-A6c                  ó   •—  ‰ d «      S r×   rN   )r?  s   €rE   ú<lambda>z6HfFileSystem._ensure_bucket_follower.<locals>.<lambda>¹  s   ø€ ¡T¨$£Z€ rG   c                  ó    •— t        ‰ «      dkD  S )Nr   )r¬   )r>  s   €rE   rA  z6HfFileSystem._ensure_bucket_follower.<locals>.<lambda>º  s   ø€ ¤ [Ó!1°AÑ!5€ rG   )rù   re   rú   Ú
on_changesÚon_reconcileÚis_alive)rù   rú   r   r   r  r5  ÚweakrefÚWeakValueDictionaryrÄ   r   r   r¥   )rD   re   r  Úfollowerr?  r>  s    `  @@rE   Ú_ensure_bucket_followerz$HfFileSystem._ensure_bucket_followerœ  s  ú€ à�}‰}˜dŸj™j¨)Ð4ˆä"ñ 	4ØÔ&Ñ&Ô;KÈCÑ;PÐQRÑ;SÐ,S¨KÐ,SÜ�d“8 ;Ñ.à,0�K¤ 4£Ñ)Ø×0Ñ0°Ô;Ø÷	4ð 	4ô "×5Ñ5´r¸$³xÀÐ6FÓGˆKðTœdÔ#3Ñ4°tÑ;ð TÀö Tô &ØŸ™Ø#Ø—j‘jØÛ/Û5ôˆHð &.¨{Ð$;Ô˜SÑ!Ø�N‰NÔØ×(Ñ(¨Ô3÷=	4÷ 	4ñ 	4ús   £AD	Á0BD	Ä	DÚmode)ÚHfFileSystemFileÚHfFileSystemStreamFilec                 ó˜   — |�|n| j                   }|�||d<   d|v rt        d«      ‚|dk(  rt        | |f||dœ|¤ŽS t        | |f||dœ|¤ŽS )Nrû   Úaz/Appending to remote files is not yet supported.r   )rJ  rS   )rû   r  rL  rK  )rD   r>   rJ  rû   rS   rÜ   s         rE   Ú_openzHfFileSystem._openÀ  sr   € ð $.Ð#9‘Z¸t¿¹ˆ
ØÐ!Ø#-ˆF�<Ñ Ø�$‰;Ü%Ð&WÓXÐXØ˜Š?Ü)¨$°Ð]¸4È(Ñ]ÐV\Ñ]Ð]ä# D¨$ÐW°TÀHÑWÐPVÑWÐWrG   c                 óÔ  — | j                  ||¬«      }t        |t        «      r3| j                  j	                  |j
                  |j                  g¬«       nr| j                  j                  |j                  |j                  | j                  |j                  |j                  |j                  d«      |j                  d«      ¬«       | j                  |j                  «       ¬«       y )N©rS   ©ÚdeleteÚcommit_messageÚcommit_description)rT   rR   rú   rQ   rS   rT  rU  ©r>   )r)  r{   rd   r§   Úbatch_bucket_filesre   r>   Údelete_filerT   rR   rú   rQ   rS   r^   r0  rF   )rD   r>   rS   rÜ   r�   s        rE   Ú_rmzHfFileSystem._rmÒ  sÀ   € Ø×)Ñ)¨$¸Ð)ÓBˆÜ�mÔ%CÔDØ�I‰I×(Ñ(¨×)@Ñ)@È-×J\ÑJ\ÐI]Ð(Õ^à�I‰I×!Ñ!Ø*×7Ñ7Ø%×-Ñ-Ø—j‘jØ'×1Ñ1Ø&×/Ñ/Ø%Ÿz™zÐ*:Ó;Ø#)§:¡:Ð.BÓ#Cð "ô ð 	×Ñ =×#:Ñ#:Ó#<ÐÕ=rG   r£   rƒ   c                 óF  — | j                  ||¬«      }| j                  ||||¬«      }t        |t        «      rb|D �cg c]/  }| j	                  |«      rŒ| j                  |«      j
                  ‘Œ1 }}| j                  j                  |j                  |¬«       nØ|D �cg c]/  }| j	                  |«      rŒ| j                  |«      j
                  ‘Œ1 }	}|	D �
cg c]  }
t        |
¬«      ‘Œ }}
d› d�}||rdndz  }||�d
|› d�ndz  }| j                  j                  |j                  |j                  | j                  ||j                  |j                  d|«      |j                  d«      ¬«       | j!                  |j#                  «       ¬«       y	c c}w c c}w c c}
w )aÔ  
        Delete files from a repository.

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

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

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

        rQ  )r£   rƒ   rS   rR  rÃ   zDelete ú zrecursively r[   Nzup to depth rT  rU  )rR   rQ   rú   Ú
operationsrS   rT  rU  rV  )r)  Úexpand_pathr{   rd   Úisdirr>   r§   rW  re   r"   Úcreate_commitrR   rQ   rú   rS   r^   r0  rF   )rD   r>   r£   rƒ   rS   rÜ   r�   ÚpathsrS  Úpaths_in_reporT   r\  rT  s                rE   ÚrmzHfFileSystem.rmâ  s‘  € ð6 ×)Ñ)¨$¸Ð)ÓBˆØ× Ñ  °ÀXÐX`Ð ÓaˆÜ�mÔ%CÔDØ?DÖ]°tÈDÏJÉJÐW[ÕL\�d×'Ñ'¨Ó-×2Ó2Ð]ˆFÐ]Ø�I‰I×(Ñ(¨×)@Ñ)@ÈÐ(ÕPàFKÖd¸dÐSW×S]ÑS]Ð^bÕSc˜T×.Ñ.¨tÓ4×9Ó9ÐdˆMÐdØ_lÖmÈ|Ô/¸\ÖJÐmˆJÐmØ& t f¨AÐ.ˆNØ±	™n¸rÑAˆNØ¸HÐ<P ¨X¨J°aÑ8ÐVXÑXˆNà�I‰I×#Ñ#Ø%×-Ñ-Ø'×1Ñ1Ø—j‘jØ%Ø&×/Ñ/Ø%Ÿz™zÐ*:¸NÓKØ#)§:¡:Ð.BÓ#Cð $ô ð 	×Ñ =×#:Ñ#:Ó#<ÐÕ=ùò% ^ùò eùÚms   ½FÁFÂFÂ6FÃFÚdetailÚrefreshc                 óÜ  — | j                  ||¬«      }|j                  «       }	  | j                  |f||dœ|¤Ž}|r|S |D �cg c]  }|d   ‘Œ	 c}S # t        $ r‹ |j                  st        |d«       	  | j                  | j                  |«      f||dœ|¤Ž}n# t        $ r g }Y nw xY w|D �cg c]  }|d   |k(  sŒ|‘Œ nc c}w }}t        |«      dk(  rt        |d«       Y Œªw xY wc c}w )a×  
        List the contents of a directory.

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

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

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

        Returns:
            `list[Union[str, dict[str, Any]]]`: List of file paths (if detail=False) or list of file information
            dictionaries (if detail=True).
        rQ  )rd  rS   Nrn   r   )r)  rF   Ú_ls_treer%   r>   r  rÊ   r¬   )	rD   r>   rc  rd  rS   rÜ   r�   r�   Úos	            rE   ÚlszHfFileSystem.ls  s  € ð4 ×)Ñ)¨$¸Ð)ÓBˆØ×&Ñ&Ó(ˆð	2Ø�$—-‘- ÐS¨gÀÑSÈFÑSˆCñ ˆsÐ:°cÖ":° 1 V£9Ò":Ð:øô "ò 
	2à ×%Ò%Ü% d¨DÔ1ðØ#�d—m‘m D§L¡L°Ó$6ÐeÀÐRZÑeÐ^dÑe‘øÜ%ò Ø’ðúà!Ö7˜ Q v¡Y°$Ó%6’1Ñ7ùÒ7ˆCÐ7Ü�3‹x˜1Š}Ü% d¨DÔ1ùð
	2üò #;sM   ¥A ÁC)Á!C&Á4%BÂC&ÂB(Â%C&Â'B(Â(C&Â/CÂ=CÃ"C&Ã%C&c           
      ó:
  — |�|n| j                   �| j                   nd}| j                  ||¬«      }|j                  «       }|j                  }|r|dk(  rd}|r|nd}| j                  r�t        |t        «      r�| j                  |j                  «       | j                  rf| j                  j                  «       x  r dk(  r\  c€}	 | j                  |	«       n    r dk(  r\  }	}
| j                  |	|
«       n | j                  rŒfg }|| j                  v �r|�s| j                  |   }|j                  |«       g }|rºd}t        |D �cg c]  }|d   dk(  sŒ||f‘Œ c}«      }|r’|j                  «       \  }}|�||k  ru|d   | j                  vr|j!                  |d   «       nO| j                  |d      }|j                  |«       |j                  |D �cg c]  }|d   dk(  r|dz   |f‘Œ c}«       |rŒ’g }|r7t        |t"        «      r'|D �cg c]  }|d   �Œ	| j%                  |d   «      ‘Œ }}|r|s|rò|rðt'        j(                  ||z   «      }|�"|t+        |«      d  j-                  d	«      }||z  }|D �cg c]  }|d   j/                  |d	z   «      rŒ|‘Œ }}t1        | j                  «      D ]3  }|j/                  |d	z   «      sŒ| j                  j3                  |d «       Œ5 | j                  j3                  |d «       |j                  | j5                  ||d
|||¬«      «       |S t        |t        «      r)| j7                  |j                  |j8                  |¬«      }nÐ|r…| j:                  dkD  rvt=        | ||¬«      }|j?                  |«      }| j                  jA                  |jB                  «       |r| jE                  |«       |S |jB                  sg | j                  |<   |S | jF                  jI                  |jJ                  |j8                  |||jL                  |jN                  ¬«      }i }|D ]‹  }|d	z   |j8                  z   }tQ        ||«      }||k7  r0|jS                  | j%                  |«      g «      j!                  |«       |t+        |«      d  j-                  d	«      }|�||k  sŒ{|j!                  |«       Œ� | j                  jA                  |«       |r| jE                  |«       |S g | j                  |<   |S c c}w c c}w c c}w c c}w )NFrQ  r   r}   rp   rx   rn   rt   rA   T)r£   rd  rS   r‚   rƒ   )rµ   r£   )r‚   rƒ   r¢   )*r‚   r)  rF   r=   rü   r{   rd   rI  re   rÿ   Úpopleftr5  r:  r  rª   r   rË   rP   rÊ   Ú	posixpathÚ
commonpathr¬   rÌ   r­   rÄ   rà   rf  Ú_list_bucket_tree_with_foldersr>   r…   r   r™   ÚupdaterŽ   Ú_drop_outdated_parent_listingr§   rÅ   rR   rS   rQ   r|   rÉ   )rD   r>   r£   rd  rS   r‚   rƒ   r�   Ú	root_pathre   r6  r�   Úcached_path_infosÚdirs_not_in_dircacher’   ri   Údirs_to_visitÚdir_infoÚdirs_not_expandedrg  Úcommon_pathÚcommon_path_depthr4  ÚtreeÚlistingrŽ   rj   rÎ   s                               rE   rf  zHfFileSystem._ls_tree?  s;  € ð 'Ð2‰KÈT×M]ÑM]ÐMi¸×9IÒ9IÐotð 	ð ×)Ñ)¨$¸Ð)ÓBˆØ×&Ñ&Ó(ˆØ!×&Ñ&ˆ	Ù˜ QšàˆIÙ(‘8¨aˆà×Ò¤
¨=Ô:XÔ YØ×(Ñ(¨×)@Ñ)@ÔAØ×.Ò.Ø×2Ñ2×:Ñ:Ó<ß*Ñ*˜) TÑ*Ø×4Ñ4°YÕ?ð +ç-Ò-Ø×2Ñ2°9¸gÕFð .ð	 ×.Ó.ð ˆØ�4—=‘=Ò ªØ $§¡¨dÑ 3ÐØ�J‰JÐ(Ô)Ø#%Ð Ùð �Ü %Ø9JÖo¨IÈiÐX^ÑN_ÐcnÓNn�e˜YÒ'Òoó!�ñ $Ø&3×&;Ñ&;Ó&=‘O�E˜8ØÐ'¨5°HÒ+<Ø# FÑ+°4·=±=Ñ@Ø0×7Ñ7¸ÀÑ8HÕIà04·±¸hÀvÑ>NÑ0OÐ-ØŸJ™JÐ'8Ô9Ø)×0Ñ0ð 6Gö!"à(1Ø'0°Ñ'8¸KÒ'Gð &+¨Q¡Y°	Ò$:ò!"ôò $ð  !#ÐÙœz¨-Ô9[Ô\àFIÖ$fÀÈQÈ}ÑM]ÑMe T§\¡\°!°F±)Õ%<Ð$fÐ!Ð$fáÑ2¹ÑHYô (×2Ñ2Ð3GÐJ[Ñ3[Ó\�ØÐ'Ø(3´C¸³I°KÐ(@×(FÑ(FÀsÓ(KÐ%ØÐ 1Ñ1�HØ"%ÖU˜Q¨Q¨v©Y×-AÑ-AÀ+ÐPSÑBSÕ-T’qÐU�ÐUÜ#'¨¯©Ó#6ò =�KØ"×-Ñ-¨k¸CÑ.?Õ@ØŸ™×)Ñ)¨+°tÕ<ð=ð —‘×!Ñ! +¨tÔ4Ø—
‘
Ø—M‘MØ#Ø"+Ø $Ø!)Ø$/Ø!)ð "ó ô	ðr ˆ
ô[ ˜-Ô)GÔHØ×:Ñ:Ø!×+Ñ+Ø(×-Ñ-Ø'ð ;ó ‘ñ
 ˜t×/Ñ/°!Ò3ô 3°4À[Ð[cÔd�Ø—k‘k -Ó0�à—‘×$Ñ$ W×%5Ñ%5Ô6ÙØ×6Ñ6°tÔ<ð �
ð !×)Ò)à*,�D—M‘M $Ñ'Ø�
à—y‘y×/Ñ/Ø!×)Ñ)Ø!×&Ñ&Ø'Ø&Ø*×3Ñ3Ø+×5Ñ5ð 0ó �ð 9;ˆHØ!ò 0�	Ø&¨™_¨y¯~©~Ñ=�
Ü"<¸YÈ
Ó"S�Ø Ò%Ø×'Ñ'¨¯©°ZÓ(@À"ÓE×LÑLÈ_Ô]Ø"¤3 t£9 ;Ð/×5Ñ5°cÓ:�ØÐ# u°Ó'8Ø—J‘J˜Õ/ð0ð �M‰M× Ñ  Ô*ÙØ×2Ñ2°4Ô8ð ˆ
ð ')�—‘˜dÑ#Øˆ
ùòy pùò!"ùò %gùò Vs*   Å	T	ÅT	ÇTÈ
TÈTÉ;TÊTc                 ó¤   ‡— | j                  ‰«      }|| j                  v r0t        ˆfd„| j                  |   D «       «      r| j                  |= y y y )Nc              3   ó.   •K  — | ]  }|d    ‰k7  –— Œ y­w)rn   NrN   )Ú.0rg  r>   s     €rE   ú	<genexpr>z=HfFileSystem._drop_outdated_parent_listing.<locals>.<genexpr>Ç  s   øè ø€ Ò/fÀa°°&±	¸TÕ0AÑ/fùs   ƒ)rÊ   r  Úall)rD   r>   Úparent_paths    ` rE   ro  z*HfFileSystem._drop_outdated_parent_listingÄ  sI   ø€ à—l‘l 4Ó(ˆØ˜$Ÿ-™-Ñ'¬CÓ/fÈ4Ï=É=ÐYdÑKeÔ/fÔ,fØ—‘˜kÑ*ð -gÐ'rG   rµ   c                 óî  — | j                   j                  |||¬«      }i }|rd|j                  d«      z   nd}g }|D �]  }|r.|j                  |k7  r|j                  j	                  |› d�«      sŒ4|j                  |«       |sŒHt        t        |j                  «      j                  «      d| dz
   D ]¥  }	t        dt        |	«      |j                  ¬«      }
|
j                  |vr!|j                  |
«       |
||
j                  <   ŒS|
j                  €Œ`||
j                     }|j                  �|j                  |
j                  k  sŒ•|
j                  |_        Œ§ �Œ! |r|st        d|› d	|› d
�«      ‚|S )z<Same as `HfApi.list_bucket_tree` but always includes folders)r£   r   rA   r   Nrx   )rp   r>   rw   zFile not found in bucket 'z': 'ú')r§   Úlist_bucket_treerÌ   r>   r­   rË   rÄ   r   Úparentsr    rL   rw   r%   )rD   re   rµ   r£   Úbucket_filesÚbucket_foldersÚ	min_depthr�   Úbucket_entryÚparent_bucket_folder_strÚparent_bucket_folderÚbucket_folders               rE   rm  z+HfFileSystem._list_bucket_tree_with_foldersÊ  sœ  € ð —y‘y×1Ñ1°)¸VÈyÐ1ÓYˆØ24ˆÙ-3�A˜Ÿ™ SÓ)Ò)¸ˆ	Ø/1ˆà(ó 	UˆLñ ˜,×+Ñ+¨vÒ5¸l×>OÑ>O×>ZÑ>ZÐ^dÐ]eÐefÐ[gÔ>hØØ�J‰J�|Ô$ñ Øô -1´¸|×?PÑ?PÓ1Q×1YÑ1YÓ,ZÐ[kÐ^gÐ]gÐjkÑ]kÐ,lò UÐ(Ü'3Ø$¬3Ð/GÓ+HÐVb×VnÑVnô(Ð$ð
 (×,Ñ,°NÑBØ—J‘JÐ3Ô4Ø@T�NÐ#7×#<Ñ#<Ñ=Øð (×3Ñ3Ñ?Ø$2Ð3G×3LÑ3LÑ$M�MØ$×0Ñ0Ð8Ø%×1Ñ1Ð4H×4TÑ4TÓTà4H×4TÑ4T˜Õ1ò#Uð	UñD ™#Ü$Ð'AÀ)ÀÈDÐQWÐPXÐXYÐ%ZÓ[Ð[Øˆ
rG   c              /   ó¨   •K  — | j                  ||j                  d«      ¬«      j                  «       }t        ‰| �  |g|¢­i |¤ŽE d{  –—†  y7 Œ­w)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.
        rS   rQ  N)r)  r^   rF   rØ   Úwalk)rD   r>   rÛ   rÜ   rÝ   s       €rE   rŒ  zHfFileSystem.walkù  sL   øè ø€ ð × Ñ  °·
±
¸:Ó0FÐ ÓG×QÑQÓSˆÜ‘7‘< Ð6 tÒ6¨vÑ6×6Ò6ús   ƒAAÁ
AÁAc                 óˆ   •— | j                  ||j                  d«      ¬«      j                  «       }t        ‰| �  |fd|i|¤ŽS )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.
            maxdepth (`int`, *optional*):
                Maximum depth to descend into directories. By default, no limit.

        Returns:
            `list[str]`: List of paths matching the pattern.
        rS   rQ  rƒ   )r)  r^   rF   rØ   Úglob)rD   r>   rƒ   rÜ   rÝ   s       €rE   rŽ  zHfFileSystem.glob	  sE   ø€ ð × Ñ  °·
±
¸:Ó0FÐ ÓG×QÑQÓSˆÜ‰w‰|˜DÑ>¨8Ð>°vÑ>Ð>rG   Úwithdirsc                 ó,  — |�|dk  rt        d«      ‚| j                  ||¬«      }|j                  «       }	  | j                  |fd||dœ|¤Ž}	|s|	D �
cg c]  }
|
d   dk7  sŒ|
‘Œ }	}
n# | j                  |fi |¤Ž}|d   dk(  r|g|	z   n|	}	|	D �
ci c]  }
|
d   |
“Œ
 }	}
t        |	«      }|s|S |D �ci c]  }||	|   “Œ
 c}S c c}
w c c}
w # t
        $ r9 	  | j                  |fd	|i|¤Ž}|d   d
k(  r||ini }	n# t        $ r i }	Y nw xY wY Œnw xY wc c}w )aÎ  
        List all files below path.

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

        > [!TIP]
        > Large repositories are listed directory by directory, in parallel, to work around the
        > cursor-based pagination of the Hub `tree` endpoint. Tune this with the `max_workers`
        > argument of [`HfFileSystem`].

        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 1rQ  T)r£   rd  rƒ   rp   rx   rn   rS   rl   )r  r)  rF   rf  Úinfor%   r,  r  )rD   r>   rƒ   r�  rc  rd  rS   rÜ   r�   r�   rg  ri   Únamesrn   s                 rE   ÚfindzHfFileSystem.find  sj  € ðJ Ð H¨q¢LÜÐ:Ó;Ð;Ø×)Ñ)¨$¸Ð)ÓBˆØ×&Ñ&Ó(ˆð	.Ø�$—-‘- Ðc°¸gÐPXÑcÐ\bÑcˆCñ Ø"%ÖB˜Q¨¨6©°kÓ)A’qÐB�ÑBð &˜DŸI™I dÑ5¨fÑ5�	Ø+4°VÑ+<ÀÒ+K�y�k CÒ'ÐQT�Ø),Ö- A�1�V‘9˜a‘<Ð-ˆCÐ-Ü�s“ˆÙØˆLà05Ö6¨�D˜#˜d™)‘OÒ6Ð6ùò Cùò
 .øô "ò 	ðØ%˜DŸI™I dÑH°XÐHÀÑH�	Ø+4°VÑ+<ÀÒ+F�t˜YÑ'ÈB‘øÜ$ò Ø’ðüð	üò& 7sM   ·C ÁCÁ"CÂCÂ2DÃ	DÃ#C:Ã9DÃ:DÄDÄDÄDÄDÚpath1Úpath2c                 óÐ  — | j                  ||¬«      }| j                  ||¬«      }t        |t        «      �r?| j                  ||¬«      }|d   dk(  ryt        |t        «      rd|j                  }	}n|j
                  |j                  }	}|j                  d«      x}
�7| j                  j                  |j                  ||	|
|j                  fg¬«       na| j                  |d|¬«      5 }|j                  «       }ddd«       | j                  j                  |j                  |j                  fg¬	«       | j                  |j                  «       ¬
«       | j                  |j                  «       ¬
«       yt        |t        «      rt        d«      ‚|j
                  |j
                  k(  xr |j                  |j                  k(  }|r“d|› d|› �}| j                  j!                  |j                  |j
                  |j"                  |j                  d|«      |j                  dd«      t%        |j&                  |j&                  |j"                  ¬«      g¬«       n³| j                  |d|j"                  ¬«      5 }|j                  «       }ddd«       d|› d|› �}| j                  j)                  |j&                  |j                  | j*                  |j
                  |j"                  |j                  d|«      |j                  d«      ¬«       | j                  |j                  «       ¬
«       | j                  |j                  «       ¬
«       y# 1 sw Y   �ŒWxY w# 1 sw Y   ŒÓxY w)a¬  
        Copy a file within or between repositories, or into a bucket.

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

        rQ  rp   rx   NÚbucketrs   )ÚcopyÚrb©ÚaddrV  z6Copy from buckets to repositories is not available yetzCopy z to rT  rU  r[   )Úsrc_path_in_reporT   Úsrc_revision)rR   rQ   rS   rT  rU  r\  ©Úpath_or_fileobjrT   rR   rú   rQ   rS   rT  rU  )r)  r{   rd   r‘  re   rQ   rR   r^   r§   rW  r>   ÚopenÚreadr0  rF   r  r_  rS   r!   rT   Úupload_filerú   )rD   r”  r•  rS   rÜ   Úresolved_path1Úresolved_path2Úsource_infoÚsource_typeÚ	source_idrs   ÚfÚcontentÚ	same_reporT  s                  rE   Úcp_filezHfFileSystem.cp_file[  s/  € ð  ×*Ñ*¨5¸8Ð*ÓDˆØ×*Ñ*¨5¸8Ð*ÓDˆô �nÔ&DÕEØŸ)™) E°H˜)Ó=ˆKà˜6Ñ" kÒ1Øä˜.Ô*HÔIØ)1°>×3KÑ3K˜Y‘à)7×)AÑ)AÀ>×CYÑCY˜Y�Ø'ŸO™O¨JÓ7Ð7�ÐDà—	‘	×,Ñ,Ø"×,Ñ,°[À)ÈXÐWe×WjÑWjÐ4kÐ3lð -õ ð
 —Y‘Y˜u d°X�YÓ>ð 'À!ØŸf™f›h�G÷'à—	‘	×,Ñ,¨^×-EÑ-EÈWÐVd×ViÑViÐLjÐKkÐ,Ôlà×!Ñ! ~×'?Ñ'?Ó'AÐ!ÔBØ×!Ñ! ~×'?Ñ'?Ó'AÐ!ÔBØô �nÔ&DÔEÜ%Ð&^Ó_Ð_ð ×$Ñ$¨×(@Ñ(@Ñ@ÒuÀ^×E[ÑE[Ð_m×_uÑ_uÑEuð 	ñ Ø$ U G¨4°¨wÐ7ˆNØ�I‰I×#Ñ#Ø&×.Ñ.Ø(×2Ñ2Ø'×0Ñ0Ø%Ÿz™zÐ*:¸NÓKØ#)§:¡:Ð.BÀBÓ#Gä'Ø)7×)DÑ)DØ%3×%@Ñ%@Ø%3×%<Ñ%<ôðð $õ ð —‘˜5 $°×1HÑ1H�ÓIð #ÈQØŸ&™&›(�÷#à$ U G¨4°¨wÐ7ˆNØ�I‰I×!Ñ!Ø 'Ø+×8Ñ8Ø&×.Ñ.Ø—j‘jØ(×2Ñ2Ø'×0Ñ0Ø%Ÿz™zÐ*:¸NÓKØ#)§:¡:Ð.BÓ#Cð "ô 	ð 	×Ñ >×#;Ñ#;Ó#=ÐÔ>Ø×Ñ >×#;Ñ#;Ó#=ÐÕ>÷_'ñ 'ú÷B#ð #ús   Ã)MÉ9MÍMÍM%c                 óÞ   —  | j                   |fi i |¥ddi¥¤Ž}d|v r#|d   €t        d|› d�«      ‚|d   j                  S d|v r
|d   r|d   S d|v r
|d   r|d   S t        d|› d	|› d
�«      ‚)ak  
        Get the last modified time of a file.

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

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

        Returns:
            `datetime`: Last modified time of the file.
        r‚   Trt   z9'modified' is not implemented for repository paths like 'r�  rv   rw   z'Cannot determined 'modified' for path 'z	' (info: ú))r‘  r  Údate)rD   r>   rÜ   r‘  s       rE   ÚmodifiedzHfFileSystem.modified±  s³   € ð ˆt�y‰y˜ÑAÐ!@ FÐ!@¨M¸4Ñ!@ÑAˆØ˜DÑ Ø�MÑ"Ð*Ü)Ð,eÐfjÐekÐklÐ*mÓnÐnØ˜Ñ&×+Ñ+Ð+Ø˜‰_  g¢Ø˜‘=Ð Ø˜dÑ" t¨MÒ':Ø˜Ñ&Ð&ä%Ð(OÐPTÈvÐU^Ð_cÐ^dÐdeÐ&fÓgÐgrG   c           	      ó¨  — | j                  ||¬«      }|j                  «       }|j                  d| j                  �| j                  nd«      }|j                  s£|dddœ}t        |t        «      rd|d<   t        |t        «      �r¹|�r¶| j                  j                  |j                  |j                  |j                  ¬	«      d
   }i |¥dt        |j                  |j                  |j                  ¬«      dœ¥}�nBt        |t         «      r^| j#                  |«      }	| j%                  |	|¬«       | j&                  |	   D �
cg c]  }
|
d   |k(  sŒ|
‘Œ }}
|st)        |d«       |d   }�nÔd}| j#                  |«      }	|s|	| j&                  vr| j%                  |	«       |	| j&                  v r8| j&                  |	   D �
cg c]  }
|
d   |k(  sŒ|
‘Œ }}
|st)        |d«       |d   }|s|�|�rS|�rP|d   �€J| j                  j+                  |j                  |j,                  ||j                  |j                  ¬«      }|st)        |d«       |d   }t        |j                  |j                  |j                  d|j.                  ¬«      j                  «       }t        |t0        «      rX|dz   |j                  z   |j2                  d|j4                  |j6                  |j8                  |j:                  |j<                  dœ}n,|dz   |j                  z   dd|j>                  |j:                  dœ}|sdD �ci c]  }|||   “Œ
 }}|€J ‚|S c c}
w c c}
w c c}w )aS  
        Get information about a file or directory.

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

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

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

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

        rQ  r‚   NFr   rx   )rn   ro   rp   rt   )rQ   rS   éÿÿÿÿ)ÚoidÚtitler®  )rz   rt   )rd  rn   )r¤   rS   rQ   r[   )rT   rY   rA   rl   rm   ry   ) r)  rF   r^   r‚   r>   r{   rP   r§   Úlist_repo_commitsrR   rQ   rS   r.   Ú	commit_idr³  Ú
created_atrd   rÊ   rh  r  r  Úget_paths_inforT   rY   r/   ro   rq   rr   rs   rt   ru   rz   )rD   r>   rd  rS   rÜ   r�   r‚   r�   rt   r  rg  Úout1Ú
paths_infori   rp  r.  s                   rE   r‘  zHfFileSystem.infoÊ  sX  € ð, ×)Ñ)¨$¸Ð)ÓBˆØ×&Ñ&Ó(ˆØ—j‘jØ¨t×/?Ñ/?Ð/K˜4×+Ò+ÐQVó
ˆð ×!Ò!ð ØØ#ñˆCô
 ˜-Ô)KÔLØ%)��MÑ"Ü˜-Ô)KÕLÒQ\Ø"Ÿi™i×9Ñ9Ø!×)Ñ)°]×5LÑ5LÐWd×WmÑWmð :ó àñ�ðØðà#Ü#1Ø'×1Ñ1¸×9JÑ9JÐQ\×QgÑQgô$ò’ô ˜Ô'EÔFØŸ,™, tÓ,ˆKà�G‰G�K¨ˆGÔ1Ø#Ÿ}™}¨[Ñ9ÖO˜!¸Q¸v¹YÈ$Ó=N’AÐOˆDÐOÙÜ% d¨DÔ1Ø�q‘'ŠCàˆCØŸ,™, tÓ,ˆKÙ ;°d·m±mÑ#Cà—‘˜Ô$Ø˜dŸm™mÑ+à#'§=¡=°Ñ#=ÖS˜aÀÀ6ÁÈdÓARšÐS�ÐSÙÜ)¨$°Ô5Ø˜1‘g�Ù˜#˜+ª+º#À#ÀmÑBTÑB\Ø!ŸY™Y×5Ñ5Ø!×)Ñ)Ø!×.Ñ.Ø&Ø*×3Ñ3Ø+×5Ñ5ð 6ó �
ñ "Ü)¨$°Ô5Ø& q™M�	Ü>Ø!×+Ñ+Ø!×)Ñ)Ø!×*Ñ*Ø!#Ø"/×"=Ñ"=ô÷ ‘)“+ð ô ˜i¬Ô2à )¨C¡°)·.±.Ñ @Ø )§¡Ø &Ø#,×#4Ñ#4Ø(Ÿ}™}Ø$-×$6Ñ$6Ø'0×'<Ñ'<Ø$-×$6Ñ$6ñ	‘Cð !*¨C¡°)·.±.Ñ @Ø !Ø +Ø#,×#4Ñ#4Ø'0×'<Ñ'<ñ�Cñ #Ø.FÖG¨˜1˜c !™f™9ÐG�CÐGØˆÐˆØˆ
ùòq Pùò TùòT Hs   ÅMÅMÆ>M
ÇM
Ì0Mc                 ó�   — 	 |j                  dd«      r| j                  |«        | j                  |fi |¤Ž y# t        $ r Y yw xY w)aÁ  
        Check if a file exists.

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

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

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

        Returns:
            `bool`: True if file exists, False otherwise.
        rd  FT)r^   r0  r‘  ÚOSError)rD   r>   rÜ   s      rE   ÚexistszHfFileSystem.exists8  sK   € ð 	Ø�z‰z˜) UÔ+Ø×%Ñ% dÔ+àˆD�I‰I�dÑ%˜fÒ%ØøÜò 	Ùð	ús   ‚69 ¹	AÁAc                 óP   — 	 | j                  |«      d   dk(  S # t        $ r Y yw xY w)ai  
        Check if a path is a directory.

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

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

        Returns:
            `bool`: True if path is a directory, False otherwise.
        rp   rx   F©r‘  r»  r2  s     rE   r^  zHfFileSystem.isdirQ  s1   € ð	Ø—9‘9˜T“? 6Ñ*¨kÑ9Ð9øÜò 	Ùð	úó   ‚ ™	%¤%c                 óP   — 	 | j                  |«      d   dk(  S # t        $ r Y yw xY w)a`  
        Check if a path is a file.

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

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

        Returns:
            `bool`: True if path is a file, False otherwise.
        rp   rl   Fr¾  r2  s     rE   ÚisfilezHfFileSystem.isfilec  s1   € ð	Ø—9‘9˜T“? 6Ñ*¨fÑ4Ð4øÜò 	Ùð	úr¿  c                 óx  — | j                  |«      }t        |t        «      r2| j                  › d|j                  › dt        |j                  «      › �}nBt        |j                  |j                  |j                  |j                  | j                  ¬«      }| j                  |«      r|j                  ddd«      }|S )zÝ
        Get the HTTP URL of the given path.

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

        Returns:
            `str`: HTTP URL to access the file or directory on the Hub.
        z	/buckets/z	/resolve/)rQ   rS   rù   z/tree/r   )r)  r{   rd   rù   re   r   r>   r)   rR   rT   rQ   rS   r^  r   )rD   r>   r�   Úurls       rE   rÃ  zHfFileSystem.urlu  s§   € ð ×)Ñ)¨$Ó/ˆÜ�mÔ%CÔDØ—]‘]�O 9¨]×-DÑ-DÐ,EÀYÌuÐUb×UgÑUgÓOhÐNiÐj‰CäØ×%Ñ%Ø×*Ñ*Ø'×1Ñ1Ø&×/Ñ/ØŸ™ôˆCð �:‰:�dÔØ—+‘+˜k¨8°QÓ7ˆCØˆ
rG   r�   r‘  c                 óH  — t        «       r|j                  d«      x}€yt        |t        «      r|j                  dd}}}n/|j
                  |j                  }}t        |j                  d¬«      }t        t        j                  |||| j                  ¬«      }t        ||¬«      S )zlBuild the Xet metadata of a file from its `info()` entry, or return None if it can't be downloaded with Xet.rs   Nr—  r[   ©Úsafe)Ú
token_typerR   rQ   rS   rù   )Ú	file_hashÚrefresh_route)r7   r^   r{   rd   re   rR   rQ   r   rS   r9   r8   ÚREADrù   r2   )rD   r�   r‘  rs   rR   rQ   rS   rÉ  s           rE   Ú_get_xet_file_datazHfFileSystem._get_xet_file_data�  s™   € ô  Ô!°$·(±(¸:Ó2FÐ&F hÐ%OØÜ�mÔ%CÔDØ+8×+BÑ+BÀHÈd �Y‰Gð "/×!6Ñ!6¸×8OÑ8O�YˆGÜ˜]×3Ñ3¸"Ô=ˆHÜ7Ü#×(Ñ(ØØØØ—]‘]ô
ˆô  X¸]ÔKÐKrG   c                 ó  •— |j                  d«      }| j                  ||¬«      }t        |j                  «       t	        |j                  «       «      dhz
  }t        |t        t        f«      rt        |«      dkD  rt        ‰| �,  ||f||dœ|¤ŽS | j                  ||¬«      }	d}
|�€|€t        d«      ‚t        |«      r|}ný| j                  |«      rt!        j"                  |d¬	«       yt!        j"                  t         j                  j%                  |«      xs t         j&                  d¬	«       | j)                  ||	«      x}�l|j+                  |	d
   «       t-        t/        |«      || j0                  j3                  «       |	d
   |t        |t        «      r|j4                  ¬«       yd¬«       yt7        |d«      }d}
|j9                  «       }|	d
   }|j+                  |«       	 t;        | j=                  |j?                  «       «      |||d| j0                  j3                  «       t        |t        «      r|j4                  nd¬«       |jA                  |«       |
r|jC                  «        yy# |
r|jC                  «        w w xY w)a™  
        Copy single remote file to local.

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

        Args:
            rpath (`str`):
                Remote path to download from.
            lpath (`str`, *optional*):
                Local path to download to. Can be omitted if `outfile` is provided.
            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.

        rS   rQ  r   )ÚcallbackÚoutfileFNz-Either `lpath` or `outfile` must be provided.T)Úexist_okro   )Úincomplete_pathÚxet_file_dataÚheadersÚexpected_sizeÚdisplayed_filenameÚ	_tqdm_barÚwb)rÃ  Ú	temp_filerÔ  rÓ  Úresume_sizerÒ  rÕ  )"r^   r)  r#   r>   ÚsetÚkeysr{   r   r   r¬   rØ   Úget_filer‘  r  r   r^  ÚosÚmakedirsÚdirnameÚcurdirrË  Úset_sizer+   r   r§   Ú_build_hf_headersÚtqdmr   Útellr*   rÃ  rF   ÚseekÚclose)rD   ÚrpathÚlpathrÍ  rÎ  rÜ   rS   Úresolve_remote_pathÚunhandled_kwargsr‘  Ú
close_filerÑ  Úinitial_posrÓ  rÝ   s                 €rE   rÛ  zHfFileSystem.get_file¤  sE  ø€ ð$ —:‘:˜jÓ)ˆØ"×/Ñ/°ÀÐ/ÓIÐô 	$Ð$7×$<Ñ$<Ô=Ü˜vŸ{™{›}Ó-°°Ñ<ÐÜ˜(¤\´<Ð$@ÔAÄSÐIYÓEZÐ]^ÒE^ô ‘7Ñ# E¨5Ð_¸8ÈWÑ_ÐX^Ñ_Ð_à�y‰y˜¨ˆyÓ2ˆð ˆ
Ø‰?Øˆ}Ü Ð!PÓQÐQÜ˜%Ô Ø‘Ø—‘˜EÔ"Ü—‘˜E¨DÕ1Øä—‘œBŸG™GŸO™O¨EÓ2Ò?´b·i±iÈ$ÕOØ%)×%<Ñ%<Ð=PÐRVÓ%WÐW�MÐdà×%Ñ% d¨6¡lÔ3ÜÜ(,¨U«Ø&3Ø $§	¡	× ;Ñ ;Ó =Ø&*¨6¡lØ+0Ü3=¸hÌÔ3U (§-¡-õð  ð \`õð  Ü˜u dÓ+�Ø!�
Ø—l‘l“nˆð ˜V™ˆØ×Ñ˜-Ô(ð	 ÜØ—H‘HÐ0×:Ñ:Ó<Ó=Ø!Ø#(Ø+ØØŸ	™	×3Ñ3Ó5Ü+5°hÄÔ+M˜(Ÿ-š-ÐSWõð �L‰L˜Ô%ñ Ø—‘•ð ø‰zØ—‘•ð ús   Ç'A4I/ É/Jc                 ó   — t        d«      ‚)z½A 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  rC   s    rE   ÚtransactionzHfFileSystem.transactionò  s   € ô "Ð"LÓMÐMrG   c                 ó   — t        d«      ‚)z@Begin write transaction for deferring files, non-context versionrí  rî  rC   s    rE   Ústart_transactionzHfFileSystem.start_transactioný  s   € ô "Ð"LÓMÐMrG   c                 óp   — t         t        | «      | j                  | j                  | j	                  «       ffS r×   )Úmake_instancerp   rë   rì   rè   rC   s    rE   Ú
__reduce__zHfFileSystem.__reduce__  s9   € äÜ�‹JØ×ÑØ× Ñ Ø×$Ñ$Ó&ð	
ð 
ð 	
rG   c                 ó€   — t        | j                  «      t        | j                  «      t        | j                  «      dœS )N)r  r   r  )r   r  r   r  rC   s    rE   rè   z HfFileSystem._get_instance_state  s4   € ä  §¡Ó/Ü/7¸×8\Ñ8\Ó/]Ü$,¨T×-FÑ-FÓ$Gñ
ð 	
rG   r×   )r™  NN)FNN)TFN)FFNNN)NFFFN)FN©r?   N)=rH   rI   rJ   rK   Úroot_markerÚprotocolrL   r¿   rÒ   r�   Úclassmethodrá   ÚtupleÚ	Exceptionr  r  rP   rd   r)  r0  r-  r5  r   r   r:  rI  r   rO  rY  rb  rÄ   rÓ   r   rh  rf  ro  r   r    rm  r   rŒ  rŽ  r“  r«  r   r¯  r‘  r¼  r^  rÁ  rÃ  r2   rË  r   rÛ  Úpropertyrï  rñ  rô  rè   rô   rõ   s   @rE   r�   r�   r  s4  ø„ ñHðT €KØ€Hð
  $Ø#'Ø!%Ø#'ØØ#'ò<ð ˜‘*ð<ð �c‰z˜DÑ ð	<ð
 ˜$‘Jð<ð ˜D‘[ð<ð ð<ð ˜D‘[õ<ð> ð	¨ð 	Àò 	ó ð	ðTØðTØ'*ðTØ69¸D±jðTà	ˆt�Y Ñ%Ð%Ñ	&óTð&4¨ð 4°°d¸IÈÑ<LÐ6LÑ0Mó 4ð 15ñM
ØðM
Ø#&¨¡:ðM
à	+Ð.LÑ	LóM
ñ^&Q S¨4¡Zð &Q¸4ó &QðP&°3ð &¸4ó &ð1°ð 1¸ó 1ð6¨sð 6¸XÐFVÑ=Wð 6Ð\`ó 6ð""4°ð "4¸ó "4ðN Ø!%Ø#ñXàðXð ðXð ˜$‘Jð	Xð
 ˜‘*ðXð 
Ð;Ñ	<óXñ$>˜ð > s¨T¡zð >Àtó >ð&  Ø#Ø#ñ0>àð0>ð ð0>ð ˜‘*ð	0>ð
 ˜‘*ð0>ð 
ó0>ðf ]añ);Øð);Ø!%ð);Ø7;ð);ØORÐUYÉzð);à	ˆc�D˜˜c˜‘NÑ"Ñ	#ó);ð\  ØØ#Ø#'Ø#ñCàðCð ðCð ð	Cð
 ˜‘*ðCð ˜D‘[ðCð ˜‘*óCðJ+°#ð +¸$ó +ð-Øð-Ø&)ð-Ø6:ð-à	�*˜|Ñ+Ñ	,ó-ð^7˜ð 7°(¸5ÀÀdÈ3ÁiÐQUÐVYÑQZÐAZÑ;[Ñ2\õ 7ñ ?˜ð ?¨¨d©
ð ?ÈÈSÉ	õ ?ð*  $ØØØØ#ñ>7àð>7ð ˜‘*ð>7ð ð	>7ð
 ð>7ð ð>7ð ˜‘*ð>7ð 
ˆc‰�T˜#˜t C¨ H™~Ð-Ñ.Ñ	.ó>7ñ@T?˜Sð T?¨ð T?¸¸d¹
ð T?ÐX\ó T?ðlh˜Sð h¨xó hñ2l˜ð l tð l¸sÀT¹zð lÐ_cÐdgÐilÐdlÑ_mó lò\ò2ò$ð$˜ð  ó ð4LØ?ÐB`Ñ`ðLØhlÐmpÐruÐmuÑhvðLà	�tÑ	óLð* %)Ð3DÈdö L ð\ ñNó ðNòNò
ö
rG   r�   )Ú	metaclassc                   ó„   ‡ — e Zd Zddedededz  fˆ fd„Zˆ fd„Zdeded	efd
„Z	dd„Z
dded	dfd„Zdˆ fd„	Zd	efd„Zˆ xZS )rK  Nr€   r>   rS   c                 óø   •— 	 |j                  ||¬«      | _        t	        ‰| �  || j                  j                  «       fi |¤Ž |  y # t        $ r)}d|j                  dd«      v rt        |› d�«      |‚‚ d }~ww xY w)NrQ  ÚwrJ  r[   zB.
Make sure the repository and revision exist before writing data.)r)  r�   r,  r^   rØ   r�   rF   )rD   r€   r>   rS   rÜ   r  rÝ   s         €rE   r�   zHfFileSystemFile.__init__  sŠ   ø€ ð	Ø!#§¡°À Ó!IˆDÔô 	‰Ñ˜˜T×/Ñ/×9Ñ9Ó;ÑF¸vÒFÚøô !ò 	Ø�f—j‘j ¨Ó,Ñ,Ü'Ø�cÐ\Ð]óàðð ûð	ús   ƒA Á	A9Á$A4Á4A9c                 ó:   •— t        | d«      sy t        ‰| �	  «       S ©Nr�   )ÚhasattrrØ   Ú__del__©rD   rÝ   s    €rE   r  zHfFileSystemFile.__del__!  s   ø€ Ü�t˜_Ô-àÜ‰w‰Ó Ð rG   r¥   Úendr?   c                 óì   — dd|› d|dz
  › �i| j                   j                  j                  «       ¥}| j                  «       }t	        d||t
        j                  ¬«      }t        |«       |j                  S )NÚrangeúbytes=ú-r   ÚGET©rÒ  r  )	r€   r§   rá  rÃ  r4   r   ÚHF_HUB_DOWNLOAD_TIMEOUTr3   r©  )rD   r¥   r  rÒ  rÃ  Úrs         rE   Ú_fetch_rangezHfFileSystemFile._fetch_range'  sm   € à�v˜e˜W A c¨A¡g YÐ/ð
à�g‰g�l‰l×,Ñ,Ó.ð
ˆð �h‰h‹jˆÜ˜ ¨W¼i×>_Ñ>_Ô`ˆÜ˜AÔØ�y‰yÐrG   c                 ó<   — t        j                  dd¬«      | _        y )Nzhffs-F)rµ   rS  )ÚtempfileÚNamedTemporaryFiler×  rC   s    rE   Ú_initiate_uploadz!HfFileSystemFile._initiate_upload1  s   € Ü!×4Ñ4¸GÈEÔRˆ�rG   Úfinalc                 óJ  — | j                   j                  d«       | j                   j                  «       }| j                  j	                  |«       |�rÐ| j                  j                  «        t        | j                  t        «      rg| j                  j                  j                  | j                  j                  | j                  j                  | j                  j                  fg¬«       n×| j                  j                  j                  | j                  j                  | j                  j                   | j                  j"                  | j                  j$                  | j                  j&                  | j                  j(                  | j*                  j-                  d«      | j*                  j-                  d«      ¬«       t/        j0                  | j                  j                  «       | j                  j3                  | j                  j5                  «       ¬«       y y )Nr   rš  rT  rU  rž  rV  )Úbufferrä  r¡  r×  Úwriterå  r{   r�   rd   r€   r§   rW  re   rn   r>   r¢  rT   rR   rú   rQ   rS   rÜ   r^   rÜ  Úremover0  rF   )rD   r  Úblocks      rE   Ú_upload_chunkzHfFileSystemFile._upload_chunk4  s  € Ø�‰×Ñ˜ÔØ—‘× Ñ Ó"ˆØ�‰×Ñ˜UÔ#ÚØ�N‰N× Ñ Ô"Ü˜$×,Ñ,Ô.LÔMØ—‘—‘×/Ñ/Ø×&Ñ&×0Ñ0¸¿¹×8KÑ8KÈT×M_ÑM_×MdÑMdÐ7eÐ6fð 0õ ð —‘—‘×(Ñ(Ø$(§N¡N×$7Ñ$7Ø!%×!3Ñ!3×!@Ñ!@Ø ×.Ñ.×6Ñ6ØŸ'™'Ÿ-™-Ø"×0Ñ0×:Ñ:Ø!×/Ñ/×8Ñ8Ø#'§;¡;§?¡?Ð3CÓ#DØ'+§{¡{§¡Ð7KÓ'Lð )ô 	ô �I‰I�d—n‘n×)Ñ)Ô*Ø�G‰G×$Ñ$Ø×'Ñ'×1Ñ1Ó3ð %õ ð% rG   c                 óH  •— | j                   dk(  rx|�|dk(  rq| j                  dk(  rb| j                  j                  | j                  dd¬«      5 }|j                  «       }| xj                  t        |«      z  c_        |cddd«       S t        ‰| �  |«      S # 1 sw Y   ŒxY w)züRead 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û   )rJ  Úlocr€   r   r>   r¡  r¬   rØ   )rD   Úlengthr¨  r�   rÝ   s       €rE   r¡  zHfFileSystemFile.readN  s�   ø€ ð �9‰9˜Ò & .°F¸b²LÀdÇhÁhÐRSÂmØ—‘—‘˜dŸi™i¨¸!�Ó<ð ÀØ—f‘f“h�Ø—’œC ›HÑ$•Ø÷ñ ô ‰w‰|˜FÓ#Ð#÷	ð ús   Á0BÂB!c                 óL   — | j                   j                  | j                  «      S r×   ©r€   rÃ  r>   rC   s    rE   rÃ  zHfFileSystemFile.url[  ó   € Ø�w‰w�{‰{˜4Ÿ9™9Ó%Ð%rG   r×   rö  )F©r±  )rH   rI   rJ   r�   rL   r�   r  rÒ   Úbytesr  r  r¿   r  r¡  rÃ  rô   rõ   s   @rE   rK  rK    sj   ø„ ñ
˜<ð 
¨sð 
¸cÀD¹jõ 
ô!ð #ð ¨Cð °Eó óSñ 4ð °Dó õ4$ð&�S÷ &rG   rK  c                   ó¦   ‡ — e Zd Z	 	 	 	 ddededededz  dedefˆ fd„Zdd	ed
efd„Zddefd„Zdde	e
   dede
fd„Zdefd„Zˆ fd„Zd„ Zd„ Zˆ xZS )rL  Nr€   r>   rJ  rS   rû   Ú
cache_typec                 ó¢  •— |dk7  rt        d|› �«      ‚|dk7  rt        d|› �«      ‚d|v rt        d|› d�«      ‚|j                  ||¬«      | _        | j                  j                  «       d d	œ| _        t        ‰| �  || j                  j                  «       f|||d
œ|¤Ž d | _        |  t        «       | _	        d | _
        t        «       | _        y )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�  rQ  )rn   ro   ©rJ  rû   r$  )r  r)  r�   rF   ÚdetailsrØ   r�   Úresponser   Ú_exit_stackÚ_stream_iteratorÚ	bytearrayÚ_stream_buffer)	rD   r€   r>   rJ  rS   rû   r$  rÜ   rÝ   s	           €rE   r�   zHfFileSystemStreamFile.__init__`  sí   ø€ ð ˜Š?ÜÐYÐZdÐYeÐfÓgÐgØ˜ÒÜÐ^Ð_iÐ^jÐkÓlÐlØ�$‰;ÜÐZÐ[_ÐZ`Ð`aÐbÓcÐcð  Ÿ_™_¨T¸H˜_ÓEˆÔà $× 2Ñ 2× <Ñ <Ó >ÈÑMˆŒÜ‰ÑØ�×"Ñ"×,Ñ,Ó.ð	
Ø59ÀjÐ]gñ	
Økqò	
ð 15ˆŒÙÜ$›;ˆÔà8<ˆÔÜ'›kˆÕrG   r  Úwhencec                 óX   — |dk(  r|dk(  ry || j                   k(  r|dk(  ry t        d«      ‚)Nr   r   zCannot seek streaming HF file)r  r  )rD   r  r.  s      rE   rä  zHfFileSystemStreamFile.seek  s2   € Ø�!Š8˜ !šØØ�$—(‘(Š?˜v¨š{ØÜÐ8Ó9Ð9rG   r  c                 ó‚  — | j                   €| j                  «        d}	 	 | j                   �| j                  €y| j                  | j                  |«      }| xj                  t        |«      z  c_        |S # t        $ r> | j                   �| j                   j                  «        |r‚ | j                  «        d}Y nw xY wŒ¡)zÞRead 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.
        FTrG   )r)  Ú_open_connectionr+  Ú_read_from_streamr  r¬   rû  rå  )rD   r  Úretried_oncer�   s       rE   r¡  zHfFileSystemStreamFile.read†  s³   € ð �=‰=Ð Ø×!Ñ!Ô#àˆØð$Ø—=‘=Ð(¨D×,AÑ,AÐ,IØØ×,Ñ,¨T×-BÑ-BÀFÓK�Ø—’œC ›HÑ$•Ø�
øÜò $Ø—=‘=Ð,Ø—M‘M×'Ñ'Ô)ÙØà×%Ñ%Ô'Ø#’ð$úð s   ¡A6 º;A6 Á6AB=Â<B=Úiteratorr?   c                 ó–  — |dk(  ry|dk  rRt        | j                  «      }| j                  j                  «        |D ]  }|j                  |«       Œ t	        |«      S |t        | j                  «      k  r)t	        | j                  d| «      }| j                  d|…= |S t        | j                  «      }| j                  j                  «        |D ]m  }|t        |«      z
  }|t        |«      kD  r|j                  |«       Œ1|j                  |d| «       | j                  j                  ||d «        t	        |«      S  t	        |«      S )z°Read up to `length` bytes from stream buffer and stream.

        If length < 0, read until EOF.

        If EOF is reached before length, fewer bytes may be returned.
        r   rG   N)r,  r-  r+  rª   r"  r¬   )rD   r4  r  ÚbufÚchunkÚresultÚneeds          rE   r2  z(HfFileSystemStreamFile._read_from_stream¢  s9  € ð �QŠ;Øà�AŠ:Ü˜D×/Ñ/Ó0ˆCØ×Ñ×%Ñ%Ô'Ø!ò "�Ø—
‘
˜5Õ!ð"ä˜“:Ðà”S˜×,Ñ,Ó-Ò-Ü˜4×.Ñ.¨w°Ð7Ó8ˆFØ×#Ñ# G V GÐ,ØˆMä˜×+Ñ+Ó,ˆØ×Ñ×!Ñ!Ô#Øò 	ˆEØœC ›HÑ$ˆDØ”c˜%“jÒ Ø—
‘
˜5Õ!à—
‘
˜5  $˜<Ô(Ø×#Ñ#×*Ñ*¨5°°¨<Ô8ØÜ�S‹zÐð	ô �S‹zÐrG   c                 óL   — | j                   j                  | j                  «      S r×   r  rC   s    rE   rÃ  zHfFileSystemStreamFile.urlÄ  r   rG   c                 ón   •— t        | d«      sy | j                  j                  «        t        ‰| �  «       S r  )r  r*  rå  rØ   r  r  s    €rE   r  zHfFileSystemStreamFile.__del__Ç  s/   ø€ Ü�t˜_Ô-àØ×Ñ×ÑÔ Ü‰w‰Ó Ð rG   c                 ó”   — t         | j                  | j                  | j                  | j                  | j
                  j                  ffS r×   )Úreopenr€   r>   rJ  Ú	blocksizeÚcachern   rC   s    rE   rô  z!HfFileSystemStreamFile.__reduce__Î  s0   € Ü˜Ÿ™ §¡¨D¯I©I°t·~±~ÀtÇzÁzÇÁÐWÐWÐWrG   c                 ó@  — | j                   j                  «        d| _        | j                  «       }| j                  j
                  j                  «       }| j                  dkD  rd| j                  › d�|d<   | j                  j                  t        d||t        j                  ¬«      «      | _        	 t        | j                  «       | j                  j#                  «       | _        y# t        $ r+}|j                  j                   dk(  rd| _        Y d}~y‚ d}~ww xY w)	z%Open a connection to the remote file.Nr   r	  r
  ÚRanger  r  i   )r-  r+  r+  rÃ  r€   r§   rá  r  r*  Úenter_contextr5   r   r  r)  r3   r&   Ústatus_codeÚ
iter_bytes)rD   rÃ  rÒ  r  s       rE   r1  z'HfFileSystemStreamFile._open_connectionÑ  sì   € ð 	×Ñ×!Ñ!Ô#Ø $ˆÔà�h‰h‹jˆØ—'‘'—,‘,×0Ñ0Ó2ˆØ�8‰8�aŠ<Ø!'¨¯© z°Ð3ˆG�GÑØ×(Ñ(×6Ñ6ÜØØØÜ!×9Ñ9ô	ó
ˆŒð	Ü §¡Ô.ð !%§¡× 8Ñ 8Ó :ˆÕøô ò 	Ø�z‰z×%Ñ%¨Ò,à $�”ÜØûð	ús   Â4C) Ã)	DÃ2 DÄDÄD)r™  Nr   r&  )r   r!  )rH   rI   rJ   r�   rL   rÒ   r�   rä  r¡  r   r"  r2  rÃ  r  rô  r1  rô   rõ   s   @rE   rL  rL  _  s¯   ø„ ð
 Ø#ØØ ñ*àð*ð ð*ð ð	*ð
 ˜‘*ð*ð ð*ð õ*ñ>:˜ð : Só :ñ$˜3ó $ñ8 ¨(°5©/ð  À3ð  ÐPUó  ðD&�Só &ô!òXö;rG   rL  rS   c                 óF   — t        j                  | «      r| S t        | «      S r×   )r,   ÚsearchÚ
safe_quoterQ  s    rE   r`   r`   ð  s    € Ü2×9Ñ9¸(ÔCˆ8Ð]ÌÐT\ÓI]Ð]rG   Úsc                 ó   — t        | d¬«      S )Nr[   rÅ  )r   )rH  s    rE   rG  rG  ô  s   € Ü�˜ÔÐrG   r>   r!  c                 ó    — | }t        |t        «      r| › d�}n+t        |t        «      r| › d�}nt        |t        «      r| › d�}t	        |«      |‚)Nz} (repository not found). If the repo is private, make sure you are authenticated and your token has the required permissions.z (revision not found)z (invalid repository id))r{   r'   r(   r1   r,  )r>   r!  Úmsgs      rE   r  r  ø  se   € Ø
€CÜ�#Ô.Ô/àˆfð ;ð ;ñ 	ô
 
�CÔ.Ô	/Ø�Ð+Ð,‰Ü	�CÔ*Ô	+Ø�Ð.Ð/ˆÜ
˜CÓ
  cÐ)rG   r€   rJ  rû   r$  c                 ó,   — | j                  ||||¬«      S )Nr'  )r   )r€   r>   rJ  rû   r$  s        rE   r=  r=    s   € Ø�7‰7�4˜d¨zÀjˆ7ÓQÐQrG   c                 ó`   —  | |i |¤Ž}|j                  «       D ]  \  }}t        |||«       Œ |S r×   )rÍ   ré   )rÚ   rÛ   rÜ   rñ   r€   rò   ró   s          rE   ró  ró    s?   € Ù	ˆdÐ	�fÑ	€BØ+×1Ñ1Ó3ò 'ÑˆˆkÜ��D˜+Õ&ð'à€IrG   )prÜ  rk  r  rˆ   rF  Úcollectionsr   Úcollections.abcr   r   Úconcurrent.futuresr   Ú
contextlibr   r˜  r   Údataclassesr	   r
   r   r   Úpathlibr   r   Útypingr   r   r   Úurllib.parser   r   ÚfsspecÚhttpx2Úfsspec.callbacksr   r   r   Úfsspec.configr   Úfsspec.utilsr   r[   r   Ú_bucket_live_followr   r   r   r   Ú_bucketsr   r    Ú_commit_apir!   r"   Ú_local_folderr#   Úerrorsr$   r%   r&   r'   r(   Úfile_downloadr)   r*   r+   Úhf_apir,   r-   r.   r/   r0   Úutilsr1   r2   r3   r4   r5   r6   Úutils._runtimer7   Ú
utils._xetr8   r9   Úutils.insecure_hashlibr:   r<   rP   rd   rp   ÚAbstractFileSystemrh   rM   rL   rÓ   r|   r¯   r   rÕ   r�   ÚspecÚAbstractBufferedFilerK  rL  r`   rG  rû  r  rÒ   r=  ró  ÚhffsrN   rG   rE   ú<module>rj     s  ðÜ 	Û Û Û Û Ý ß .Ý 1Ý  Ý ß 1Ñ 1Ý ß 'ß 'Ñ 'ß 'ã Û ß JÑ JÝ &Ý #å ß jÓ jß .ß CÝ 6÷õ ÷ 9Ñ 8ß \Õ \ß w× wÝ ,ß EÝ 'ð ÷6ð 6ó ð6ð ô&Ð)Aó &ó ð&ð0 ô0Ð%=ó 0ó ð0ñ ˜×2Ñ2Ó3€ˆcÓ 3ð%Ø˜*Ñ$ zÑ1°LÑ@ð%ØNQð%à	ˆ#ˆsˆ(�^ó%ðT Ð ÷oIñ oIôd2ˆlô 2ôj_
�6×,Ñ,¸õ _
ôD%H&�v—{‘{×7Ñ7ô H&ôVN;˜VŸ[™[×=Ñ=ô N;ðb^˜Cð ^ Có ^ð�#ð ˜#ó ð* ð *¨)°dÑ*:ð *¸xó *ðRˆ|ð R 3ð R¨cð R¸sð RÐPSó Ròñ ƒ~�rG   