wL iҼ ddlZddlZddlZddlmZddlmZmZddlmZddl m Z ddl m Z ddl mZmZmZmZmZmZmZmZddlmZmZddlZdd lmZmZmZdd lmZdd l m!Z!d d l"m#Z#d dl$m%Z%m&Z&d dl'm(Z(m)Z)m*Z*d dl+m,Z,m-Z-d dl.m/Z/m0Z0m1Z1d dl2m3Z3m4Z4m5Z5ejldejnZ8eGddZ9GddejtZ;GddejxjzZ>GddejxjzZ?de@de@fdZAde@de@fd ZBd!e@d"eeCdefd#ZDd$e;d!e@d%e@d&eEd'e@f d(ZFd)ZGy)*N)deque) dataclassfield)datetime)chain)Path)AnyDictIteratorListNoReturnOptionalTupleUnion)quoteunquote)_DEFAULT_CALLBACK NoOpCallback TqdmCallback) isfilelike)Response) constants)CommitOperationCopyCommitOperationDelete)EntryNotFoundErrorRepositoryNotFoundErrorRevisionNotFoundError) hf_hub_urlhttp_get)HfApiLastCommitInfoRepoFile)HFValidationErrorhf_raise_for_status http_backoffzy (^refs\/convert\/\w+) # `refs/convert/parquet` revisions | (^refs\/pr\/\d+) # PR revisions cjeZdZUdZeed<eed<eed<eed<eddZeeed <d efd Z y) HfFileSystemResolvedPathzUData structure containing information about a resolved Hugging Face file system path. repo_typerepo_idrevision path_in_repoNF)defaultrepr _raw_revisionreturnctjj|jd|jz}|j r-|d|j d|j jdS|jtjk7r6|dt|jd|j jdS|d|j jdS)N@/) rREPO_TYPES_URL_PREFIXESgetr)r*r/r,rstripr+DEFAULT_REVISION safe_revision)self repo_paths d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/hf_file_system.py unresolvez"HfFileSystemResolvedPath.unresolve0s5599$.."MPTP\P\\   [$"4"4!5Qt7H7H6IJQQRUV V ]]i88 8[- ">!?qARAR@ST[[\_` `[$"3"3!45<r<r(r($s?_N LM$)E#BM8C=BB3Br>r(ceZdZdZdZdZdddddeedee edfdee ffd Z d ed ed eed e e ee ffdZd/ded eed efdZd/deed dfdZ d0deded eedee d df dZd/ded eed dfdZ d1dede dee d eed df dZ d2dede de d eed eeeeeefff dZ d3dede de d eede dee f dZded ee eeeeefffd Zded eeffd Z d4dedee d e de de d eed eeeeeeeeffffd!Zd/d"ed#ed eed dfd$Zded efd%Z d5dede d eed eeeffd&Z!d'Z"d(Z#d)Z$ded efd*Z%e&dfd6fd+ Z'e(d,Z)d-Z*d.Z+xZ,S)7 HfFileSystema% Access a remote Hugging Face Hub repository as if were a local file system. > [!WARNING] > [`HfFileSystem`] provides fsspec compatibility, which is useful for libraries that require it (e.g., reading > Hugging Face datasets directly with `pandas`). However, it introduces additional overhead due to this compatibility > layer. For better performance and reliability, it's recommended to use `HfApi` methods when possible. Args: 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 . 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) ``` r2hfN)endpointtoken block_sizerIrJrKct||i||xstj|_||_t |||_||_i|_ i|_ y)N)rIrJ) super__init__rENDPOINTrIrJr!_apirK_repo_and_revision_exists_cachedircache)r:rIrJrKargsstorage_options __class__s r<rNzHfFileSystem.__init__cs[ $2/2 6I$6$6  859 $  ,:< r>r)r*r+r0c|||f|jvrR |jj|||tjd|j|||f<d|j||df<|j|||fS#t t f$r2}d|f|j|||f<d|f|j||df<Yd}~Nd}~wt$r0}d|f|j|||f<d|j||df<Yd}~d}~wwxYw)N)r+r)timeout)TNF)rQrP repo_inforHF_HUB_ETAG_TIMEOUTrr$r)r:r)r*r+es r<_repo_and_revision_existz%HfFileSystem._repo_and_revision_existys! w )1U1U U ^ ##h)YMjMj$Xb44i(5STS]44i$5OP33Y4RSS,->? \W\^_W_44i(5STSXZ[S[44i$5OP( ^W\^_W_44i(5STS]44i$5OP ^s#-A66C.(B22 C.>&C))C.pathcdttdttdttfd}|j|}|s td|j dddzt j jvr8d|vr td|j dd\}}t j|}nt j}|jddkDrd |vr|j d d\}}d|vrwtj|}|J|d |jfvr6tjd |jd}|j}n|j dd\}}nd }|t!||}|j#|||\} } | sJt%|| n._align_revision_in_path_with_revisionsU##/4D4P$78H7IIijrist-- O,Or>z0Access to repositories lists is not implemented.r4rrr3Nr2)r/)rrC_strip_protocolNotImplementedErrorsplitrr5valuesREPO_TYPES_MAPPINGREPO_TYPE_MODELcountSPECIAL_REFS_REVISION_REGEXsearchgroupsublstriprr[_raise_file_not_foundjoin isinstancerr$r8r()r:r\r+rar)r*r^matchr,repo_and_revision_existerrrepo_id_with_namespacepath_in_repo_with_namespacerepo_id_without_namespacepath_in_repo_without_namespace_s r< resolve_pathzHfFileSystem.resolve_paths( &sm 7?}  c] ##D)%&XY Y ZZ_Q # %)J)J)Q)Q)S S$)*\]]"jja0OIt!44Y?I!11I ::c?Q d{,0JJsA,>))**7>>?OPE(X$ 9N-N'B'F'FrK['\'c'cdg'h +0;;=(9I9O9OPSUV9W6(,#%L@IYAZ\de/3/L/LYX_ai/j,'.)$4#' ),$**S/"12E)F&.1hhtzz#qr7J.K+,0JJsOA,>)14$**S/!":M1N.0: /3/L/LYX_ai/j,'.!#(?AR'ST";'E 595R5RS\^ego5p2/61$<-dC8GLd{,0JJsA,>))@IYAZ\de#' )-)F)FyRY[c)d & #Q*)*\]]'389S9S' 7Hlbrssr>c|s5|jj|jjy|j|}|j }|r0|jj |d|j |}|r0|jsq|jj |j|jdfd|jj |j|j|jfdyy)ac Clear the cache for a given path. For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.invalidate_cache). Args: path (`str`, *optional*): Path to clear from cache. If not provided, clear the entire cache. N) rRclearrQrzr=pop_parentr,r)r*r+)r:r\ resolved_paths r<invalidate_cachezHfFileSystem.invalidate_caches MM   !  0 0 6 6 8 --d3M **,D !!$-||D) !--4488-:Q:QS`ShShjn9oquv4488",,m.C.C]E[E[\^b.r>modeHfFileSystemFilec ||n |j}|||d<d|vr td|dk(rt||f||d|St||f||d|S)NrKaz/Appending to remote files is not yet supported.r)rr+)rKrdHfFileSystemStreamFiler)r:r\rr+rKkwargss r<_openzHfFileSystem._opensr$.#9Zt  !#-F< $;%&WX X ?)$]4(]V\] ]#D$WTHWPVW Wr>c N|j||}|jj|j|j|j |j |j|jd|jd|j|jy)Nr+commit_messagecommit_description)r,r*rJr)r+rrr\) rzrP delete_filer,r*rJr)r+r6rr=)r:r\r+rrs r<_rmzHfFileSystem._rms))$)B  &33!))**#--"++!::&67%zz*>?   =#:#:#<=r> recursivemaxdepthc X|j||}|j||||}|Dcgc]/}|j|r|j|j1}}|D cgc]} t | } } dd} | |rdndz } | |d |dndz } |j j |j|j|j| |j|jd | |jd  |j|j ycc}wcc} 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. r)rrr+)r,zDelete  z recursively r2Nz up to depth rr)r*r)rJ operationsr+rrr)rz expand_pathisdirr,rrP create_commitr*r)rJr+r6rr=) r:r\rrr+rrpaths paths_in_repor,rrs r<rmzHfFileSystem.rm&s36))$)B   XX` aJOh$W[WaWabfWg**40==h h[hi<+Fi i"4&*I.2=8LL !4RTT !))#--**!"++!::&6G%zz*>?   =#:#:#<=iisD"D"'D'detailrefreshc |j||}|j} |j|f||d|}|r|S|Dcgc]}|d c}S#t$rx|js t |d|j|j |f||d|}|Dcgc] }|d|k(s |ncc}w}}t|dk(r t |dYwxYwcc}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). r)rr+Nnamer)rzr=_ls_treerr,ror~len) r:r\rrr+rroutos r<lszHfFileSystem.lsTs4))$)B &&( 2$--SgSFSCs:c":1V9"::" 2 --%dD1$-- T 2aGhaZ`aC!7QvY$%6177C73x1}%dD1 2#;s*A CA C B/*B/."CC expand_infoc R|j||}|j}t|j|j|j d|j j}g} ||jvrX|sU|j|} | j| g} |rd} t| D cgc]} | ddk(s | | fc} }|r|j\} }|| |kru|d|jvr| j|dnO|j|d} | j| |j| D cgc]} | ddk(r| dz| fc} |rg}|r'| Dcgc]}|d  |j|d}}|r| s|rC|r@tjj| |z}|j!d s||k(s|t#| |vr|j%d n|j|}|"|t'|dj)d }||z}| Dcgc]}|dj+|d zr|} }t-|jD]3}|j+|d zs|jj/|d5|jj/|d| j|j1||d ||| | S|j2j5|j|j6|||j |j }|D]} |d z| jz}t9| t:r=|| j<d| j>| j@| jB| jDd}n|dd| jF| jBd}|j|d}|jjI|gj||t'|dj)d } || |ks| j|| Scc} wcc} wcc}wcc}w)Nrr2r,r/rbtype directoryrr last_commitr4T)rrr+rr)rexpandr+r)filersizerblob_idlfsrsecurityrrrrtree_idr)%rzr=r(r)r*r+r/rRextendrpopleftappendr~osr\ commonprefixendswithrr7rri startswithlistr}rrPlist_repo_treer,rqr#rrrrrr setdefault)r:r\rrr+rrr root_pathrcached_path_infosdirs_not_in_dircachedepth path_info dirs_to_visitdir_infodirs_not_expandedr common_prefix common_pathcommon_path_depth cached_pathtree cache_pathcache_path_info parent_paths r<rzHfFileSystem._ls_tree|s^))$)B &&(,  # #  ! !  " "'55  )+  4==  $ d 3  JJ( )#%  %9JoIiX^N_cnNneY'o! $&3&;&;&=OE8'5H+<#F+4==@0778HI04 hv>N0O-JJ'89)006G!"(1'0'8K'G&+QY $:!"$ !# FI$fQ}M]MeT\\!F)%<$f!$f2 HY!# 4 45IL]5] ^ %--c2$ 1$.BDU(VV"((-m4 '(3CIK(@(F(Fs(K% 11H"%UQQvY-A-A+PSBS-TqUU#' #6=K"--kC.?@ ))+t<= !!+t4 MM#"+ $!)$/!) " X C99++%%**#"&//'11 ,D" 0 &_y~~= i2 * ) &#,#4#4(}}'0'<'<$-$6$6'O!+ ! +#,#4#4'0'<'< 'O#ll?6+BC  ((b9@@Q"3t9;/55c:#u'8JJ/1 02 op!"%g"Vs*- P;P<P$ P/P!P$>P$c/K|j||jdj}t||g|i|Ed{y7w)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+rN)rzr6r=rMwalk)r:r\rSrrUs r<rzHfFileSystem.walksL   :0F GQQS7<6t6v666sAA A Ac |j||jdj}t||fi|S)ah Find files by glob-matching. For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.glob). Args: path (`str`): Path pattern to match. Returns: `List[str]`: List of paths matching the pattern. r+r)rzr6r=rMglob)r:r\rrUs r<rzHfFileSystem.globs@   :0F GQQSw|D+F++r>withdirsc X||dkr td|j||}|j} |j|fd||j|d|} |s| D cgc] } | ddk7s | } } n/|j |fd|ji|} | ddk(r| g| zn| } | D cic]} | d |  } } t| } |s| S| D cic]} | | |  c} Scc} wcc} w#t $r8 |j |fd|i|dd k(r|ii} ni} n#t$ri} YnwxYwYmwxYwcc} 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). 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. rzmaxdepth must be at least 1rT)rrr+rrrr+rr) r`rzr=rr+inforFileNotFoundErrorsorted)r:r\rrrrr+rrrrrnamesrs r<findzHfFileSystem.finds@  HqL:; ;))$)B &&( .$-- $g @V@VaimsC"%BQ6k)AqBB&DIIdV]5K5KVvV +4V+< +KykC'QT),-A1V9a<-C-s L056D#d)O6 6C .!"  499T?H??G6Q*CC$   *7sM"C# C-C' C D'# D$-"DD$ DD$DD$#D$path1path2c |j||}|j||}|j|jk(xr|j|jk(}|rd|d|}|jj |j|j|j |j d||j ddt|j|j|j gn|j|d |j 5} | j} d d d d|d|}|jj |j|j|j|j|j |j d||j d |j|j |j|j y #1swYxYw) a Copy a file within or between repositories. > [!WARNING] > Note: When possible, use `HfApi.upload_file()` for better performance. Args: path1 (`str`): Source path to copy from. path2 (`str`): Destination path to copy to. revision (`str`, *optional*): The git revision to copy from. rzCopy z to rrr2)src_path_in_repor, src_revision)r*r)r+rrrrbNpath_or_fileobjr,r*rJr)r+rrr)rzr)r*rPrr+r6rr,openread upload_filerJrr=) r:rrr+rresolved_path1resolved_path2 same_reporfcontents r<cp_filezHfFileSystem.cp_fileQs **58*D**58*D  $ $(@(@ @ u^E[E[_m_u_uEu  $UG4w7N II # #&..(22'00%zz*:NK#)::.BB#G')7)D)D%3%@%@%3%<%< $ 5$1H1HI #Q&&( #$UG4w7N II ! ! '+88&..jj(22'00%zz*:NK#)::.B#C "  >#;#;#=> >#;#;#=> # #s G$$G-c D|j|fii|ddi}|ddS)ai 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. rTrdater)r:r\rrs r<modifiedzHfFileSystem.modifieds6tyyA!@F!@M4!@AM"6**r>c 2|j||}|j}|jdd}|js~|dddd}|r=|jj |j |j|jd }i|dt|j|j|j d }nd}|j|} |s| |jvr|j| | |jvr8|j| D cgc] } | d |k(s | } } | s t!|d| d}|s| |rH|rE|d ?|jj#|j |j||j|j} | s t!|d| d} t%|j|j |jd|j&j}t)| t*rM|dz| j,z| j.d| j0| j2| j4| j6d}n,|dz| j,zdd| j8| j4d}|sdDcic]}||| }}|J|Scc} wcc}w)a Get information about a file or directory. For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.info). > [!WARNING] > Note: When possible, use `HfApi.get_paths_info()` or `HfApi.repo_info()` for better performance. Args: path (`str`): Path to get info for. refresh (`bool`, *optional*): If True, bypass the cache and fetch the latest data. Defaults to False. revision (`str`, *optional*): The git revision to get info from. Returns: `Dict[str, Any]`: Dictionary containing file information (type, size, commit info, etc.). rrFrrN)rrrr)r)r+)oidtitler)rrrr)rr+r)r2rr4rrr)rrr)rzr=r6r,rPlist_repo_commitsr*r)r+r" commit_idr created_atr~rRrroget_paths_infor(r/rqr#r\rrrrrr)r:r\rr+rrrrrrrout1 paths_inforrks r<rzHfFileSystem.infos*))$)B &&(jj 5 ))## C "ii99!))]5L5LWdWmWm: ##1'119J9JQ\QgQg$C,,t,K;dmm#C $dmm+#'==#=Sa6dARSS)$51g#++##mBTB\!YY55!))!..&*33+55 6 ")$5&qM 4!++!))!**!#"/"="=  )+ i2 )C).. @ ) &#,#4#4(}}'0'<'<$-$6$6C!*C).. @ ! +#,#4#4'0'<'< C#.FG1c!f9GCG WTRHs J!J: Jc |jddr|j||j|fi|y#YyxYw)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. rFT)r6rr)r:r\rs r<existszHfFileSystem.existssC  zz)U+%%d+ DIId %f % s69=cP |j|ddk(S#t$rYywxYw)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. rrF)rOSErrorr:r\s r<rzHfFileSystem.isdirs1 99T?6*k9 9  s  %%c@ |j|ddk(S#YyxYw)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. rrFrrs r<isfilezHfFileSystem.isfile&s) 99T?6*f4 4 sc|j|}t|j|j|j|j |j }|j|r|jddd}|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. )r)r+rIz /resolve/z/tree/r) rzrr*r,r)r+rIrreplace)r:r\rurls r<rzHfFileSystem.url8sn))$/   ! !  & &#--"++]]   ::d ++k8Q7C r>c |jd}t|jdhz }t|tt frt |dkDrt | ||f||d|St|r|}n)|j|rtj|dyt|ttfr4tjtjj!|dd}|t#|d}d}|j%} |j'|| } |j)|| d } |j+|  t-t/| j0| j2| j4| j6|j8 ||| d|j:j=t|t r |j>nd |jA| |r|jCyy#|r|jCwwxYw) aC Copy single remote file to local. > [!WARNING] > Note: When possible, use `HfApi.hf_hub_download()` for better performance. Args: rpath (`str`): Remote path to download from. lpath (`str`): Local path to download to. callback (`Callback`, *optional*): Optional callback to track download progress. Defaults to no callback. outfile (`IO`, *optional*): Optional file-like object to write to. If provided, `lpath` is ignored. r+r)callbackoutfileT)exist_okNFwbrrr*r+filenamer)rI)r temp_filedisplayed_filename expected_size resume_sizeheaders _tqdm_bar)"r6setkeysrqrrrrMget_filerrrmakedirsrCrr\dirnamertellrzrset_sizer rr*r+r,r)rIrP_build_hf_headerstqdmseekclose) r:rpathlpathrrrr+unhandled_kwargs close_file initial_posresolve_remote_pathr rUs r<rzHfFileSystem.get_fileOs$::j)v{{}- <(\<$@ASIYEZ]^E^7#E5_8W_X^_ _ e G ZZ  KK - ec4[ ) KK. > ?5$'GJlln #///I %( ;FC -( /770990==1;;!]] "#(+ 335+5h +M(--SW  LL % z s BG11Hctd)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.rdr:s r< transactionzHfFileSystem.transactions""LMMr>ctd)z@Begin write transaction for deferring files, non-context versionr r!r"s r<start_transactionzHfFileSystem.start_transactions""LMMr>ctt||j|j|j|j dffS)N)rRrQ) make_instancer storage_argsrTrRrQr"s r< __reduce__zHfFileSystem.__reduce__sB J      MM373W3W     r>N)rNN)FNN)TFN)FFNFN)NFFFN)FNr0N)-r?r@rArB root_markerprotocolrrCrboolintrNr Exceptionr[r(rzrrrrr r r rrr rrrrrrrrrrrrrpropertyr#r%r) __classcell__rUs@r<rGrG:s#JKH #'(,$( <3-<T3_% < SM <,TT'*T6>smT tXi(( )T&]t]t ]tIa]t~Xc]d>"&$( XXX3- X SM X X$ > >x} >$ >  "&"& ,>,>,>3- ,> 3- ,> ,>^`d&;&;!%&;7;&;OWX[}&; eCc3h'( )&;V "&!"&ttt t 3- t  t3-tl77(5d3iQUVYQZAZ;[2\7 ,,49,&#'"&=7=73-=7 =7  =7  =73-=7 tCy$sDcN233 4=7~6?S6?6? 6?[_6?p+S+x+ ``t`x}`bfgjlogobp`D2$$./@B HNNN  r>rGceZdZddededeeffd ZfdZdeded e fd Z dd Z dd e d dfd Z dfd Zd efdZxZS)rNfsr\r+c  |j|||_t |||jj fi||y#t$r)}d|jddvrt|d|d}~wwxYw)Nrwrr2B. Make sure the repository and revision exist before writing data.)rzrrr6rMrNr=)r:r5r\r+rrZrUs r<rNzHfFileSystemFile.__init__s !#!ID  T//99;FvF ! fjj,,'c\]   sA A9$A44A9c:t|dsyt| SNrhasattrrM__del__r:rUs r<r=zHfFileSystemFile.__del__t_- w  r>startendr0cdd|d|dz i|jjj}t|jj |jj |jj|jj|jj}td||tj}t||jS)Nrangezbytes=-rrGET)r rW)r5rPrrrr*r+r,r)rIr&rHF_HUB_DOWNLOAD_TIMEOUTr%r)r:r@rAr rrs r< _fetch_rangezHfFileSystemFile._fetch_ranges veWAcAgY/ ggll,,. &&..''00''44((22WW%%   Wi>_>_ `Ayyr>c<tjdd|_y)Nzhffs-F)prefixdelete)tempfileNamedTemporaryFilerr"s r<_initiate_uploadz!HfFileSystemFile._initiate_uploads!44GERr>finalc H|jjd|jj}|jj ||rO|jj |j jj|jj|jj|jj|j j|jj|jj|j j#d|j j#dt%j&|jj|j j)|jj+yy)Nrrrrr)bufferrrrwriterr5rPrrrr,r*rJr)r+rr6rremoverr=)r:rOblocks r< _upload_chunkzHfFileSystemFile._upload_chunks"    " U#  NN " GGLL $ $ $ 3 3!//<<**22ggmm,,66++44#{{/?@#';;??3G#H %  IIdnn)) * GG $ $''113 %  r>cH|jdk(rx||dk(rq|jdk(rb|jj|jdd5}|j }|xjt |z c_|cdddSt||S#1swYxYw)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. rNrr)rK)rlocr5rr\rrrM)r:lengthrrrUs r<rzHfFileSystemFile.reads 99 &.FbLdhhRSmdii!< ffhCH$  w|F##   s 0BB!cL|jj|jSr*r5rr\r"s r<rzHfFileSystemFile.urlww{{499%%r>r*r+)Fr)r?r@rArGrCrrNr=r/bytesrHrNr.rUrrr2r3s@r<rrsj < s hsm ! #CE S4D* $&S&r>rc eZdZ ddedededeededef fd Zdded efd Zdd efd Z d efdZ fdZ dZ xZ S)rr5r\rr+rK cache_typec |dk7rtd||dk7rtd|d|vrtd|d |j|||_|jj dd |_t | ||jj f|||d |d|_ |y#t$r-}d|j d d vrt|d |Yd}~d}~wwxYw)Nrz:HfFileSystemStreamFile only supports block_size=0 but got nonez?HfFileSystemStreamFile only supports cache_type='none' but got r7z;HfFileSystemStreamFile only supports reading but got mode=''rrr2r8)rrrrKr_) r`rzrrr6r=detailsrMrNresponse) r:r5r\rr+rKr_rrZrUs r<rNzHfFileSystemStreamFile.__init__s ?YZdYefg g  ^_i^jkl l $;Z[_Z``abc c !#!ID !% 2 2 < < >M   "",,. 59j]g kq -1  ! fjj,,'c\]- sB-- C#6#CC#rWwhencecX|dk(r|dk(ry||jk(r|dk(rytd)NrrzCannot seek streaming HF file)rWr`)r:rWrfs r<rzHfFileSystemStreamFile.seeks2 !8!  $((?v{ 899r>rXcl|dk\r|fnd}|jt|jj|jj|jj |jj |jj}td||jjjdtj|_t|j d|jj_|jjj"|}|xj(t+|z c_|S#t$$re|jj't|jj|jj|jj |jj |jj}td|dd|j(zi|jjjdtj|_t|j d|jj_|jjj"|}n(#t$$r|jj'wxYwYwxYw) NrrErrET)r streamrWRangez bytes=%d-)rerrr*r+r,r)r5rIr&rPrrrFr%rawdecode_contentrr0rrWr)r:rX read_argsrrs r<rzHfFileSystemStreamFile.read%s!!'1VI" == **22++44++88,,66)) C) 668!99 DM  . /3DMM   ,($--##(()4C4 CH 5  MM   !**22++44++88,,66)) C) +"8]DGGLLEDJ3>JJ3%J,,J32J3r0cL|jj|jSr*rZr"s r<rzHfFileSystemStreamFile.urlVr[r>c:t|dsyt| Sr:r;r>s r<r=zHfFileSystemStreamFile.__del__Yr?r>ct|j|j|j|j|j j ffSr*)reopenr5r\r blocksizecacherr"s r<r)z!HfFileSystemStreamFile.__reduce___s0DIIt~~tzzWWWr>)rNrra)rr\)r?r@rArGrCrr/rNrrrr=r)r2r3s@r<rrs "&    3-   >::S:/3/b&S&! Xr>rr+r0cFtj|r|St|Sr*)rjrr safe_quoters r<r9r9cs 288B8\ S[H\\r>sct|dS)Nr2)safe)r)rvs r<rurugs  r>r\rtc|}t|tr|d}n+t|tr|d}nt|tr|d}t ||)Nz (repository not found)z (revision not found)z (invalid repository id))rqrrr$r)r\rtmsgs r<roroks\ C#./-. C. /+, C* +./ C c)r>r5rrKr_c,|j||||S)Nrc)r)r5r\rrKr_s r<rqrqvs 774dzj7 QQr>c`||i|}|jD]\}}t||||Sr*)itemssetattr)clsrSrinstance_cache_attributes_dictr5attr cached_values r<r'r'zs? d f B<BBD(lD,'( Ir>)HrrerL collectionsr dataclassesrrr itertoolsrpathlibrtypingr r r r r rrr urllib.parserrfsspecfsspec.callbacksrrr fsspec.utilsrrequestsrr2r _commit_apirrerrorsrrr file_downloadrr hf_apir!r"r#utilsr$r%r&compileVERBOSErjr(AbstractFileSystemrGspecAbstractBufferedFilerrrCr9rur0ror/rqr'rEr>r<rsU (NNN' JJ#CVV/33GG)bjj JJ  BB B*t  6,,t  nJ&v{{77J&ZbXV[[==bXJ]C]C]##**(9*=*(*R|R3RcRsRPSRr>