
    5pj                    &   % S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJrJrJrJrJrJr  SSKJr  \	(       a  SSKJrJr  \" S5      rSr1 Skr " S S5      r SSSSSSSSSSSSSS.r!S\"S '   S#S! jr#S$S" jr$g)%zLegacy-compatible HubApi wrapper.

Provides the same interface as ``modelscope.hub.api.HubApi`` (old SDK) by
wrapping the new ``modelscope_hub.HubApi``.
    )annotationsN)defaultdict)TYPE_CHECKINGAny)	urlencode   )HubApi)RepoType)AlreadyExistsErrorAuthenticationErrorInvalidParameterNotExistErrorPermissionDeniedErroris_repo_exists_error)
get_logger)PagedResultRepoInfocompatmaster>   .py.csv.tsv.json.jsonlc            	         \ rS rSr% SrS\S'   S\S'     SI     SJS jjrSKS	 jrSLSMS jjrSNSOS jjr	   SP           SQS jjr
SSSSSS
S
SS.                     SRS jjrSSS jrSTS jrSSS.       SUS jjrSSS
SS.           SVS jjrSSSSSS.               SWS jjrSS.       SXS jjr   SY         SZS jjrS[S  jrS[S! jrS[S" jrS[S# jrS\S$ jrS]S% jrS]S& jrS^S' jr      S_S( jr      S`S) jr   SYSS*.           SaS+ jjjr   SY         SbS, jjrScS- jrSNSdS. jjr S/r!    Se           SfS0 jjr"   SgSSSSSS1.                 ShS2 jjjr#      Si                 SjS3 jjr$ SNSSS4.         SkS5 jjjr%  SI       SlS6 jjr&  SI       SmS7 jjr'\(S8SSS9SSSS:.                   SnS; jjr)0 r*S\S<'     SI         SoS= jjr+  SI             SpS> jjr,\-SqS? j5       r.  SI                 SrS@ jjr/ SN     SsSA jjr0\(S
SS4               StSB jjr1\(S4           SuSC jjr2\(SS4           SvSD jjr3S
\(SS4             SwSE jjr4  SI             SxSF jjr5   Sy           SzSG jjr6SHr7g){LegacyHubApi&   zDrop-in replacement for the old ``modelscope.hub.api.HubApi``.

Accepts the old constructor signature and maps method calls to the
new HubApi implementation.
r	   _api
str | None	_endpointNc                p    U(       a  UR                  S5      (       d  SU 3nXl        [        XS9U l        g )Nhttpzhttps://endpointtoken)
startswithr    r	   r   )selfr$   r%   s      Y/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope_hub/compat/hub_api.py__init__LegacyHubApi.__init__0   s4    
 H//77!(,H!H:	    c                    U(       d  gU R                   R                  U5        U R                   R                  R                  5       =(       d    UnU R                   R	                  5       nX#4$ )zLogin with token (old style returns ``(git_token, cookies)``).

Preserves the legacy return contract: a 2-tuple of
``(git_access_token, cookies)`` so that existing callers doing
``token, cookies = api.login(...)`` continue to work.
NN)r   login_configload_git_tokenget_cookies)r'   r%   	git_tokencookiess       r(   r.   LegacyHubApi.login=   sR     		II%%446?%	))'')##r+   Fc                4    U R                   R                  XS9$ )zUGet cookies for legacy API authentication.

Delegates to :meth:`HubApi.get_cookies`.
)access_tokencookies_required)r   r1   )r'   r6   r7   s      r(   r1   LegacyHubApi.get_cookiesK   s    
 yy$$,$bbr+   dictc                j    U R                   R                  U[        R                  US9n[	        U5      $ )zGet model info as a raw dict.

Parameters
----------
model_id : str
    Model identifier, e.g. ``"owner/model_name"``.
revision : str, optional
    Branch or tag to query. Reserved for future use.
revision)r   get_repor
   MODEL_repo_info_to_dict)r'   model_idr<   infos       r(   	get_modelLegacyHubApi.get_modelU   s.     yy!!(HNNX!N!$''r+   Tc                p   U R                   R                  U[        R                  UUS9nU Vs/ s H  owR                  UR
                  S.PM     nnU(       aR  UR                  S5      n	U Vs/ s H4  owS   U	:X  d'  [        US   5      R                  U	S-   5      (       d  M2  UPM6     nnU$ s  snf s  snf )uR  List files in a model repo.

Legacy-compatible signature: ``revision`` selects a branch/tag/commit,
``root`` restricts results to files under a sub-path, and ``recursive``
walks subdirectories. Other legacy transport kwargs (e.g.
``use_cookies``, ``headers``) are accepted and ignored — auth is
handled by the configured token/session.
)r<   	recursive)PathSize/rF   )	r   list_repo_filesr
   r>   pathsizestripstrr&   )
r'   r@   r<   rootrE   kwargsfilesfresultprefixs
             r(   get_model_filesLegacyHubApi.get_model_filesb   s      		))NN	 * 
 =BBEq661662EBZZ_F!'jAV9+>#ai.B[B[\beh\hBiaFj	 C ks   "B./1B3$B3model)r%   
visibility	repo_typechinese_namelicenseexist_okcreate_default_configr$   c               <   U R                   nU(       d  U	(       a  [        X)=(       d    U R                  S9nU(       a  SU
S'    UR                  " U4UUUUS.U
D6$ ! [         a    U(       a   ge [
         a"  nU(       a  [        U5      (       a   SnAge SnAff = f)z'Create a repository (legacy signature).)r%   r$   Tr\   rX   rW   rZ   rY   N)r   r	   r    create_repor   	Exceptionr   )r'   repo_idr%   rW   rX   rY   rZ   r[   r\   r$   rO   apiexcs                r(   r_   LegacyHubApi.create_repo~   s     iiHu/I4>>JC .2F*+	??#%)   " 	 	055	s$   A B/
B9BBBc                   UR                  S5      n[        U[        5      (       a#  UR                  5       (       a  [	        U5      US'    U R
                  " U4SS0UD6  U R                  =(       d     U R                  R                  R                  nU SU 3$ ! [        [        4 a"  n[        U5      (       a  [        S5      Uee SnAff = f)zCreate a model repo (legacy signature).

Returns the model repository URL for backward compatibility.
Converts authentication errors to ``ValueError`` for legacy callers.
rW   rX   rV   )Token does not exist, please login first.Nz/models/)get
isinstancerM   isdigitintr_   r   r   _is_auth_related
ValueErrorr    r   r/   r$   )r'   r@   rO   rW   eeps         r(   create_modelLegacyHubApi.create_model   s     ZZ-
j#&&:+=+=+?+?#&z?F< 	XCCFC
 ^^9tyy0099XhZ(( $%56 	"" !LMSTT	s   B C*CCc                  ^ [         R                  R                  T5      (       d  [        ST S35      eSn[	        U4S jU 5       5      (       d&  [
        R                  STSR                  U5      5        UR                  S5      n[        U[        5      (       a#  UR                  5       (       a  [        U5      US'     U R                  R                  U[        R                   UR                  S5      UR                  S5      UR                  S	5      S
9  U R                  R+                  U[        R                   TUR                  SS5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  SS5      UR                  SS5      S9  g! ["         a    [
        R%                  SU5         N[&         a2  n[)        U5      (       d  e [
        R%                  SU5         SnAGNSnAff = f! [,        [.        4 a"  n[1        U5      (       a  [        S5      Uee SnAff = f)z,Upload a model directory (legacy signature).zmodel_dir 'z'' does not exist or is not a directory.)zconfiguration.jsonzconfiguration.yamlzconfiguration.ymlc              3     >#    U  HB  n[         R                  R                  [         R                  R                  TU5      5      v   MD     g 7fN)osrJ   isfilejoin).0rQ   	model_dirs     r(   	<genexpr>*LegacyHubApi.push_model.<locals>.<genexpr>   s0     T|!277>>"'',,y!"<==|s   A
AzNo model configuration file found in '%s'. Expected one of: %s. The upload will proceed, but the directory may not contain a valid model., rW   rZ   rY   r^   z7Repository '%s' already exists, proceeding with upload.Npath_in_repo commit_messagecommit_descriptionr<   allow_patternsignore_patternsmax_workers   	use_cacheT)r|   r~   r   r<   r   r   r   r   rf   )rt   rJ   isdirrl   anyloggerwarningrv   rg   rh   rM   ri   rj   r   r_   r
   r>   r   rA   r`   r   upload_folderr   r   rk   )r'   r@   rx   rO   config_filesrW   rc   rm   s     `     r(   
push_modelLegacyHubApi.push_model   s    ww}}Y''{9+5\]^^XT|TTTNNC 		,' ZZ-
j#&&:+=+=+?+?#&z?F< 	a		%%&nn%zz,7"JJy1!'N!; &  II###ZZ;%zz*:;#)::.B#CJ/%zz*:; &

+< ="JJ}a8 **[$7 $  & aUW_` a+C00UW_``a" $%56 	"" !LMSTT	sJ   AG B,H'  H$'H' )	H$2'HH' H$$H' 'I7IIrX   r%   c               J    U R                   R                  UU=(       d    SUS9$ )zResolve the best endpoint for read operations.

Backward-compatible with the old SDK's ``get_endpoint_for_read()``.
Honors ``MODELSCOPE_ENDPOINT`` (or deprecated ``MODELSCOPE_DOMAIN``)
and ``MODELSCOPE_PREFER_AI_SITE`` env vars.
rV   r   )r   resolve_endpoint_for_read)r'   ra   rX   r%   s       r(   get_endpoint_for_read"LegacyHubApi.get_endpoint_for_read   s.     yy22*7 3 
 	
r+   )rX   r$   re_raiser%   c               <   U R                   nUc  UbX  [        U=(       d     U R                   R                  R                  U=(       d     U R                   R                  R                  S9n UR                  X=(       d    S5      $ ! [         a    U(       a  e  gf = f)zGCheck if a repo exists (legacy signature with endpoint/token override).r#   rV   F)r   r	   r/   r$   r%   repo_existsr`   )r'   ra   rX   r$   r   r%   rb   s          r(   r   LegacyHubApi.repo_exists  s     ii5#4!?TYY%6%6%?%?6tyy0066C	??7,@AA 		s   ,B BB   
   ownersearchsortpage_number	page_sizec          	     H    U R                   R                  " U4UUUUUS.UD6$ )zNList repositories of the given type.

Delegates to :meth:`HubApi.list_repos`.
r   )r   
list_repos)r'   rX   r   r   r   r   r   filterss           r(   r   LegacyHubApi.list_repos  s<     yy##
#
 
 	
r+   r;   c               6    U R                   R                  XUS9$ )zCGet repository information.

Delegates to :meth:`HubApi.get_repo`.
r;   )r   r=   )r'   ra   rX   r<   s       r(   r=   LegacyHubApi.get_repo1  s     yy!!'x!HHr+   c           	        SSK n U R                  R                  U[        R                  UUUS9n[        U5      $ ! [
        [        [        4 a4  nUR                  R                  [        U5      [        USS5      S9UeSnAff = f)zDownload a model snapshot.r   N)rX   r<   	cache_dir	local_dirresponse)r   )requestsr   download_repor
   r>   r   r   r   
exceptions	HTTPErrorrM   getattr)r'   r@   r<   r   r   	_requestsrR   rm   s           r(   download_modelLegacyHubApi.download_modelA  s     	%		gYY,,"..!## - F 6{ 24IJ 	g&&00Q'!ZY]B^0_eff	gs   +< B/B  Bc                r    U R                   R                  U[        R                  UR	                  S5      S9$ )Npayload)r   )r   deploy_repor
   STUDIOrg   r'   	studio_idrO   s      r(   deploy_studioLegacyHubApi.deploy_studioZ  s4    yy$$OOJJy) % 
 	
r+   c                V    U R                   R                  U[        R                  5      $ rs   )r   	stop_repor
   r   r   s      r(   stop_studioLegacyHubApi.stop_studioa  s    yy""9hoo>>r+   c                Z    U R                   R                  " U[        R                  40 UD6$ rs   )r   get_repo_logsr
   r   r   s      r(   get_studio_logsLegacyHubApi.get_studio_logsd  s"    yy&&y(//LVLLr+   c                Z    U R                   R                  " U[        R                  40 UD6$ rs   )r   update_repo_settingsr
   r   r   s      r(   update_studio_settings#LegacyHubApi.update_studio_settingsg  s"    yy--iSFSSr+   c                V    U R                   R                  U[        R                  5      $ rs   )r   list_secretsr
   r   r   s      r(   list_studio_secrets LegacyHubApi.list_studio_secretsj  s    yy%%iAAr+   c                Z    U R                   R                  XU[        R                  5        g rs   )r   
add_secretr
   r   r'   r   keyvaluerO   s        r(   add_studio_secretLegacyHubApi.add_studio_secretm  s    		YUHOODr+   c                Z    U R                   R                  XU[        R                  5        g rs   )r   update_secretr
   r   r   s        r(   update_studio_secret!LegacyHubApi.update_studio_secretp  s    			xGr+   c                X    U R                   R                  X[        R                  5        g rs   )r   delete_secretr
   r   )r'   r   r   rO   s       r(   delete_studio_secret!LegacyHubApi.delete_studio_secrets  s    			@r+   c                N    U R                   R                  R                  US5      $ )zGet model branches and tags as two separate detail lists.

Returns ``(branches_detail, tags_detail)`` where each item is a dict
with at least ``Revision`` and ``CreatedAt`` keys.
rV   )r   legacylist_revisions_detail)r'   r@   rO   s      r(   #get_model_branches_and_tags_details0LegacyHubApi.get_model_branches_and_tags_detailsy  s!     yy55hHHr+   c                    U R                  U5      u  p4U(       a  U Vs/ s H  oUS   PM	     snO/ nU(       a  U Vs/ s H  oUS   PM	     snO/ nXg4$ s  snf s  snf )zGet model branch and tag names.Revision)r   )r'   r@   rO   branches_detailtags_detailxbranchestagss           r(   get_model_branches_and_tags(LegacyHubApi.get_model_branches_and_tags  s]     (,'O'OPX'Y$?N?;?ajM?;TV7B{3{!*{3~ <3s
   AA)release_timestampc          	        SnU R                  U5      u  pxU(       a  U V	s/ s H  oS   PM	     sn	O/ n
U(       a  U V	s/ s H  oS   PM	     sn	O/ nSS jnSS jnUb%  U[        [        R                  " 5       5      U-   :  aD  Uc  SnX*;  a  X+;  a  [        SU SU 35      eU" X5      =(       d    U" Xr5      nU=(       d    SU0$ Ub  X*;   a  U" Xr5      =(       d    SU0$ U(       d.  Ub  US:X  a  U" US5      =(       d    SS0$ [        SU SU 35      eUcD  U Vs/ s H  o" U5      U::  d  M  UPM     nnU(       a
  [	        UUS9$ U" US5      =(       d    SS0$ X+;   a  U" X5      =(       d    SU0$ US:X  a  U" US5      =(       d    SS0$ S	R                  U5      n[        SU SU S
U S35      es  sn	f s  sn	f s  snf )a  Resolve a model revision to a concrete branch/tag detail dict.

Replicates the old ``modelscope.hub.api.HubApi.get_valid_revision_detail``
behavior.  When *release_timestamp* is supplied (the old SDK passes
``modelscope.version.__release_datetime__`` converted to epoch seconds),
the full version-selection logic is used:

* **Dev mode** (``release_timestamp > now + 1 year``): default to
  ``master``, validate existence.
* **Release mode**: pick the newest tag whose ``CreatedAt <=
  release_timestamp``, fall back to ``master`` if none match.

Without *release_timestamp* the simplified rule applies: explicit
*revision* is validated, ``None`` defaults to ``master``.
i3r   c                H    U  H  nUR                  S5      U:X  d  M  Us  $    g )Nr   )rg   )detailsnameitems      r(   _find5LegacyHubApi.get_valid_revision_detail.<locals>._find  s'    88J'4/K   r+   c                    U R                  S5      nUc  g [        [        U5      5      nUS:  a  US-  nU$ ! [        [        4 a     gf = f)zHSafely coerce CreatedAt to epoch seconds (handles str, float, ms, None).	CreatedAtr   l   c(	 i  )rg   rj   float	TypeErrorrl   )tagrawtss      r(   _created_at;LegacyHubApi.get_valid_revision_detail.<locals>._created_at  s[    ''+&C{s_ M!4ZI z* s   8 A
Ar   zThe model: z has no revision: )r   r{   z (valid tags: ))r   
list[dict]r   rM   returnzdict | None)r   r9   r   rj   )r   rj   timer   maxrv   )r'   r@   r<   r3   r$   r   	_ONE_YEARr   r   r   all_branchesall_tagsr   r   detailt
candidatesvalids                     r(   get_valid_revision_detail&LegacyHubApi.get_valid_revision_detail  s   0 '	'+'O'OPX'Y$CR?!*?XZ;F;7;ajM;7B		 $(9C		<Ly<X(X#+0H#k(;MhZ$XYY;1UU?5UF3j(33 H$<3M
H7MM 8x#7_h7QJ;QQ+hZ7I( TUU %0X[KNFW4W![JX:;77(3M
H7MM /IJ3IIx(3M
H7MM		(#k(3EhZ~^c]ddefggq @7X Ys   F7F<G2Gc                ,    U R                  UUUUS9S   $ )z7Resolve a model revision to a concrete revision string.)r<   r3   r$   r   )r  )r'   r@   r<   r3   r$   s        r(   get_valid_revisionLegacyHubApi.get_valid_revision  s2     --	 . 

  	r+   c                L    U R                   R                  R                  U5      $ )u2   Fetch collection data — delegates to legacy API.)r   r   get_collection)r'   collection_idrO   s      r(   r  LegacyHubApi.get_collection  s    yy..}==r+   c                j    U R                   R                  U[        R                  US9n[	        U5      $ )z$Download a skill to local directory.)rX   r   )r   r   r
   SKILLrM   )r'   skill_idr   rO   rR   s        r(   download_skillLegacyHubApi.download_skill  s4    ((nn ) 

 6{r+   2   c           	     8   U R                   nU(       a  [        U=(       d    U R                  US9nUR                  [        R
                  UU[        X0R                  5      S9nUR                   Vs/ s H  n[        U5      PM     snUR                  S.$ s  snf )z List models owned by a user/org.r#   )r   r   r   )Models
TotalCount)r   r	   r    r   r
   r>   min_OPENAPI_MAX_PAGE_SIZEitemsr?   total_count)	r'   owner_or_groupr   r   r$   r%   rb   pagers	            r(   list_modelsLegacyHubApi.list_models	  s     ii("<dnnEJC~~NN #)%@%@A	  
 7;jjAj)!,jA**
 	
As   2B)r  r   r   r$   r%   c                  [         R                  " S[        SS9  U=(       d    Un	U R                  n
U(       a  [	        U=(       d    U R
                  US9n
U
R                  [        R                  U	UUU[        X R                  5      S9$ )a  List datasets owned by a user/org.

.. deprecated::
    Use ``list_repos(owner, repo_type='dataset')`` instead.

Parameters
----------
owner : str, optional
    Filter by owner (aligned with ``list_repos``'s ``owner`` param).
page_size : int, optional
    Items per page. Default is 50.
page_number : int, optional
    1-based page index. Default is 1.
owner_or_group : str, optional
    **Deprecated** alias for ``owner``. Kept for backward compatibility.
sort : str, optional
    Sort key (e.g. ``"downloads"``).
search : str, optional
    Free-text search query.
endpoint : str, optional
    Override API endpoint.
token : str, optional
    Override API token.
zRlist_datasets() is deprecated, use list_repos(owner, repo_type='dataset') instead.r   
stacklevelr#   r   )warningswarnDeprecationWarningr   r	   r    r   r
   DATASETr  r  )r'   r   r   r   r  r   r   r$   r%   actual_ownerrb   s              r(   list_datasetsLegacyHubApi.list_datasets   s    H 	`	
 .ii("<dnnEJC~~#)%@%@A  
 	
r+   c	                *   U SU 3n	U R                   n
U(       a  [        U=(       d    U R                  US9n
U
R                  U	[        R
                  UUUS9  U=(       d)    U R                  =(       d    U
R                  R                  nU SU SU 3$ )z,Create a dataset repository, return its URL.rH   r#   r^   z
/datasets/)r   r	   r    r_   r
   r#  r/   r$   )r'   dataset_name	namespacerY   rZ   rW   descriptionr$   r%   ra   rb   rn   s               r(   create_datasetLegacyHubApi.create_datasetW  s     Kq/ii("<dnnEJC&&!% 	 	
 ??3;;+?+?Z	{!L>::r+   r#   c                   [         R                  " S[        SS9  U R                  nU(       a  [	        U=(       d    U R
                  US9nUR                  U[        R                  US9$ )a  Get dataset information via OpenAPI.

.. deprecated::
    Use ``get_repo(repo_id, repo_type='dataset')`` instead.

Parameters
----------
dataset_id : str
    Dataset identifier (corresponds to ``repo_id`` in ``get_repo``).
revision : str, optional
    Branch or tag to query (aligned with ``get_repo``'s ``revision``).
endpoint : str, optional
    Override API endpoint.
token : str, optional
    Override API token.
zPget_dataset() is deprecated, use get_repo(repo_id, repo_type='dataset') instead.r   r  r#   r;   )	r   r!  r"  r   r	   r    r=   r
   r#  )r'   
dataset_idr<   r$   r%   rb   s         r(   get_datasetLegacyHubApi.get_datasetq  sW    0 	^	

 ii("<dnnEJC||J(8(88|LLr+   c                    U R                   nU(       a  [        U=(       d    U R                  US9nUR                  U[        R
                  5        g)zDelete a model repository.r#   N)r   r	   r    delete_repor
   r>   )r'   r@   r$   r%   rb   s        r(   delete_modelLegacyHubApi.delete_model  s7     ii("<dnnEJC(..1r+   c                    [         R                  " S[        SS9  U R                  nU(       a  [	        U=(       d    U R
                  US9nUR                  U[        R                  5        g)zDelete a dataset repository.zThis function is deprecated due to security reasons, and will be recovered in future versions with proper token authentication.r   r  r#   N)	r   r!  r"  r   r	   r    r2  r
   r#  )r'   r.  r$   r%   rb   s        r(   delete_datasetLegacyHubApi.delete_dataset  sS     	Y		
 ii("<dnnEJC
H$4$45r+   rH   d   )r<   	root_pathrE   r   r   r$   r%   dataset_hub_idc                  U R                   n
U(       a  [        U=(       d    U R                  US9n
U	c;  SU;   a  UR                  SS5      u  pO[	        SU 35      eU R                  XXxS9u  pUUU(       a  SOSUUS.nU
R                  R                  S	S
U	 S3US9nU
R                  R                  U5      n[        U[        5      (       a  UR                  S5      =(       d    / $ [        U[        5      (       a  U$ / $ )z*Get dataset file tree via the datahub API.r#   rH   r   zInvalid repo_id: )r(  r)  r$   r%   TrueFalse)r   Root	Recursive
PageNumberPageSizeGET	datasets/
/repo/treeparamsFiles)r   r	   r    splitrl   get_dataset_id_and_typer   _request
_json_datarh   r9   rg   list)r'   ra   r<   r9  rE   r   r   r$   r%   r:  rb   _owner_name_rF  respdatas                    r(   get_dataset_filesLegacyHubApi.get_dataset_files  s    ii("<dnnEJC!g~ 'c1 5 #4WI!>?? $ < <"x != !N
 !#,'%!"
 zz""5In5EZ*PY_"`zz$$T*dD!!88G$**!$--t525r+   _dataset_id_type_cachec                x   U R                   nU(       a  [        U=(       d    U R                  US9nX!U=(       d    U R                  4n[        R                  R                  U5      nUb  U$ UR                  R                  U SU 3[        R                  5      nUS   n	US   n
X4[        R                  U'   X4$ )z)Get the dataset hub-internal id and type.r#   rH   IdType)
r   r	   r    r   rT  rg   r   get_repo_infor
   r#  )r'   r(  r)  r$   r%   rb   	cache_keycachedrQ  r.  dataset_types              r(   rI  $LegacyHubApi.get_dataset_id_and_type  s     ii("<dnnEJCh.H$..I	4488CMzz''9+Q|n(ExGWGWX$Z
F|:D9S++I6''r+   c           	        U R                   nU(       a  [        U=(       d    U R                  US9nSU0nUR                  R	                  SSU S3US9n	UR                  R                  U	5      n
U
c  [        SU SU S	U S
35      e[        U
[        5      (       a  U
R                  S5      OU
nUc  [        SU SU S	U S
35      eU$ )z&Get the meta file-list of the dataset.r#   r   rB  rC  rD  rE  z'The modelscope dataset [dataset_name = z, namespace = z, version = z] does not existrG  )
r   r	   r    r   rJ  rK  r   rh   r9   rg   )r'   r(  r)  r.  r<   r$   r%   rb   rF  rP  rQ  	file_lists               r(   get_dataset_meta_file_list'LegacyHubApi.get_dataset_meta_file_list  s     ii("<dnnEJCh'zz""5Ij\*LU["\zz$$T*<9, H(khZ?OQ  *4D$)?)?DHHW%T	9, H(khZ?OQ  r+   c                   SSK Jn  UR                  R                  n[        R
                  R                  U[        U 5       U 35      n[        US5       nUR                  S5        SSS5        g! , (       d  f       g= f)z>Dump dataset type marker file for offline formation detection.r   )DatasetFormationswz3*** Automatically-generated file, do not modify ***N)
modelscope.utils.constantrb  formation_mark_extr   rt   rJ   rv   rM   openwrite)r[  meta_cache_dirrb  extdataset_type_file_pathfps         r(   dump_datatype_fileLegacyHubApi.dump_datatype_file  se     	@2288!#n\AR@STWSX>Y!Z(#."HHJK /..s   A11
A?c	           	     L   SSK Jn	Jn
  U R                  nU(       a  [	        U=(       d    U R
                  US9n[        [        5      nU	" U5      nX   nU R                  XTS9  U GH(  nUS   n[        R                  R                  U5      S   nUU;  a  M3  UR                  R                  SSU S	U S
3UUS.S9n[        R                  R                  UU5      n[        R                  " [        R                  R!                  U5      SS9  [        R                  R#                  U5      (       a  UU   R%                  U5        M  ['        US5       nUR)                  UR*                  5        SSS5        UU   R%                  U5        GM+     X4$ ! , (       d  f       N*= f)z@Download meta files and return local paths grouped by extension.r   )rb  DatasetMetaFormatsr#   )r[  rh  rF   rB  rC  rH   z/repo)r   FilePathrE  T)r[   wbN)rd  rb  ro  r   r	   r    r   rL  rl  rt   rJ   splitextr   rJ  rv   makedirsdirnameexistsappendrf  rg  content)r'   r(  r)  r<   rh  r[  r^  r$   r%   rb  ro  rb   local_pathsdataset_formationdataset_meta_format	file_info	file_path	extensionrP  
local_pathrQ   s                        r(   "get_dataset_meta_files_local_paths/LegacyHubApi.get_dataset_meta_files_local_paths  si    	Tii("<dnnEJC'24'8-l;0C\Y"I!&)I((3B7I 33::&&I;a~U;$,)D ' D
 ni@JKK
3dCww~~j))I&--j9j$'1% (	"))*5# #& --	 ('s   F
F#	c                    SU;  a  [        SU< 35      eUR                  SS5      u  p4U=(       d3    U R                  =(       d     U R                  R                  R
                  nU SU SU S3$ )z6Return the base URL prefix for dataset file downloads.rH   z3Invalid repo_id format, expected 'namespace/name': r   /api/v1/datasets//repo?)rl   rH  r    r   r/   r$   )r'   ra   r$   r)  r(  rn   s         r(   get_file_base_pathLegacyHubApi.get_file_base_pathJ  sq     gRSZR]^__")--Q"7	EE499+<+<+E+E&yk<.GGr+   c                    U(       a  U(       a  U(       d  [        S5      eU=(       d3    U R                  =(       d     U R                  R                  R                  n[        SUUUS.5      n	U SU SU SU	 3$ )z.Construct the download URL for a dataset file.z:Args (file_name, dataset_name, namespace) cannot be empty!SDK)Sourcer   rq  Viewr  rH   r  )rl   r    r   r/   r$   r   )
r'   	file_namer(  r)  r<   viewextension_filterr$   rn   rF  s
             r(   get_dataset_file_url!LegacyHubApi.get_dataset_file_urlV  su     IYZZEE499+<+<+E+E$%	
 &yk<.vhOOr+   c           	         U=(       d3    U R                   =(       d     U R                  R                  R                  nU(       a:  [        R
                  R                  U5      S   [        ;   a  U SU SU SU SU 3	nU$ )z7Get dataset file URL, resolving meta files to API URLs.rp  r  rH   z/repo?Revision=z
&FilePath=)r    r   r/   r$   rt   rJ   rs  META_FILES_FORMAT)r'   r  r(  r)  r<   r$   rn   s          r(   get_dataset_file_url_origin(LegacyHubApi.get_dataset_file_url_originn  st     EE499+<+<+E+E)))4R8<MM$/	{!L>YaXbblmvlwxIr+   c                    U R                   nU(       a  [        U=(       d    U R                  US9nUR                  R	                  SSU SU S3SU0S9nUR                  R                  U5      $ )z,Get STS token config for dataset OSS access.r#   rB  rC  rH   	/ststokenr   rE  r   r	   r    r   rJ  rK  )r'   r(  r)  r<   r$   r%   rb   rP  s           r(   get_dataset_access_config&LegacyHubApi.get_dataset_access_config|  sr     ii("<dnnEJCzz""	{!L>;) # 

 zz$$T**r+   c                    U R                   nU(       a  [        U=(       d    U R                  US9nUR                  R	                  SSU SU S3SU0S9nUR                  R                  U5      $ )z-Get STS token config with session-based auth.r#   rB  rC  rH   r  r   rE  r  )	r'   r(  r)  check_cookier<   r$   r%   rb   rP  s	            r(   !get_dataset_access_config_session.LegacyHubApi.get_dataset_access_config_session  sr     ii("<dnnEJCzz""	{!L>;) # 

 zz$$T**r+   c                   U R                   nU(       a  [        U=(       d    U R                  US9nUR                  R	                  U SU 3[
        R                  5      nSSSS.n	U	R                  UR                  SS5      S5      n
UR                  R                  S	S
U SU S3SU0S9nUR                  R                  U5      nU
 SU SU SU 3nXS'   U$ )z*Get STS config for unzipped dataset files.r#   rH   privateinternalpublic)r         
Visibilityr  rB  rC  r  r   rE  z
-unzipped/rO  Dir)
r   r	   r    r   rX  r
   r#  rg   rJ  rK  )r'   r(  r)  r<   zip_file_namer$   r%   rb   rQ  visibility_maprW   rP  data_stsfile_dirs                 r(   &get_dataset_access_config_for_unzipped3LegacyHubApi.get_dataset_access_config_for_unzipped  s     ii("<dnnEJC zz''9+Q|n(ExGWGWX&:(C#''q(A8L
 zz""	{!L>;) # 

 ::((. \I;a~Q}oV"r+   c                8   [         R                  " S5      S:H  nU(       a  U(       a  U(       d  U(       a  g U R                  nU(       a  [        U=(       d    U R                  US9nUR
                  R                  SSU SU S35        g! [         a     gf = f)	z'Report dataset download for statistics.CI_TESTr<  Nr#   POSTrC  rH   z/download/increase)rt   getenvr   r	   r    r   rJ  r`   )r'   r(  r)  use_streamingr$   r%   
is_ci_testrb   s           r(   dataset_download_statistics(LegacyHubApi.dataset_download_statistics  s     YYy)V3
9
m		))Ch&@$..NJJI;a~5GH  		s   AB 
BB)r   r    r-   )r$   r   r%   r   r   None)r%   rM   r   ztuple[str | None, Any])NF)r6   r   r7   boolrs   )r@   rM   r<   r   r   r9   )NNT)r@   rM   r<   r   rN   r   rE   r  rO   r   r   r   )ra   rM   r%   r   rW   zint | str | NonerX   rM   rY   r   rZ   r   r[   r  r\   r  r$   r   rO   r   r   zRepoInfo | None)r@   rM   rO   r   r   rM   )r@   rM   rx   rM   rO   r   r   r  )ra   rM   rX   r   r%   r   r   rM   )ra   rM   rX   r   r$   r   r   r  r%   r   r   r  )rX   str | RepoTyper   r   r   r   r   r   r   rj   r   rj   r   r   r   zPagedResult[RepoInfo])ra   rM   rX   r  r<   r   r   r   )NNN)
r@   rM   r<   r   r   r   r   r   r   rM   )r   rM   rO   r   r   r9   )r   rM   rO   r   r   rL  )
r   rM   r   rM   r   rM   rO   r   r   r  )r   rM   r   rM   rO   r   r   r  )r@   rM   rO   r   r   ztuple[list[dict], list[dict]])r@   rM   rO   r   r   ztuple[list[str], list[str]])r@   rM   r<   r   r3   r   r$   r   r   z
int | Noner   r9   )
r@   rM   r<   r   r3   r   r$   r   r   rM   )r	  rM   rO   r   r   r9   )r  rM   r   r   rO   r   r   rM   )r   r   NN)r  rM   r   rj   r   rj   r$   r   r%   r   r   r9   )Nr  r   )r   r   r   rj   r   rj   r  r   r   r   r   r   r$   r   r%   r   r   r   )r}   zApache License 2.0r   r}   NN)r(  rM   r)  rM   rY   rM   rZ   rM   rW   rj   r*  rM   r$   r   r%   r   r   rM   )
r.  rM   r<   r   r$   r   r%   r   r   r   )r@   rM   r$   r   r%   r   r   r  )r.  rM   r$   r   r%   r   r   r  )ra   rM   r<   rM   r9  rM   rE   r  r   rj   r   rj   r$   r   r%   r   r:  r   r   rL  )
r(  rM   r)  rM   r$   r   r%   r   r   tuple)r(  rM   r)  rM   r.  rM   r<   rM   r$   r   r%   r   r   rL  )r[  rj   rh  rM   r   r  )r(  rM   r)  rM   r<   rM   rh  rM   r[  rj   r^  rL  r$   r   r%   r   r   r  )ra   rM   r$   r   r   rM   )r  rM   r(  rM   r)  rM   r<   r   r  r  r  r  r$   r   r   rM   )r  rM   r(  rM   r)  rM   r<   r   r$   r   r   rM   )r(  rM   r)  rM   r<   r   r$   r   r%   r   r   r9   )r(  rM   r)  rM   r  r  r<   r   r$   r   r%   r   r   r9   )r(  rM   r)  rM   r<   rM   r  rM   r$   r   r%   r   r   r9   )FNN)r(  rM   r)  rM   r  r  r$   r   r%   r   r   r  )8__name__
__module____qualname____firstlineno____doc____annotations__r)   r.   r1   rB   rT   r_   ro   r   r   r   r   r=   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r%  r+  r/  r3  r6  DEFAULT_DATASET_REVISIONrR  rT  rI  r_  staticmethodrl  r  r  r  r  r  r  r  r  __static_attributes__ r+   r(   r   r   &   s[	    L  $ ;; ; 
	;$c(   $  	
   
@ !'+ #'"&+#$$ 	$
 %$ $ !$ $ $  $$ $ $ 
$L)&2v !% 

 	

 
 

. !%#  	
    
6 !!
!
 	

 
 
 
 
 
 

<  $II "I
 I 
I&  $ $ $  	
  
2
?MTBEHA
I
I 
I 
'	
I		 	 
%		  $#Sh )-ShSh Sh 	Sh
 Sh &Sh 
Shp  $#  	
  
$>  
 # 

 
 	

 
 
 

2 !	5
 &*!# 5
5
 5
 	5
 #5
 5
 5
 5
 5
 
5
v +# ;; ; 	;
 ; ; ; ; ; 
;:  $ M
  $  M M  M
  M  M 
 MJ  $ 	
2
2 
2 	
2
 

2  $ 	66 6 	6
 
6, 1# %)&6&6 	&6
 &6 &6 &6 &6 &6 &6 #&6 
&6V $&D%  $ (( ( 	(
 ( 
(:  $   	
    
< L L"  $ +.+. +. 	+.
 +. +. +. +. +. 
+.`  $
H
H 
H 
	
H"  8!%#PP P 	P
 P P P P 
P:  8#  	
   
$  8# ++ + 	+
 + + 
+. #7# ++ + 	+
 + + + 
+4  $   	
    
D $#   	
   
 r+   r   rV  OwnerNamer
   r  Description	DownloadsLikesr   	UpdatedAtLicenseTags)idr   r   rX   rW   r*  	downloadslikes
created_at
updated_atlast_modifiedrZ   r   zdict[str, str]_LEGACY_KEY_MAPc                   [        U S5      (       a  SSKJn  U" U 5      nOZ[        U S5      (       aG  U R                  R	                  5        VVs0 s H  u  p4UR                  S5      (       a  M  X4_M!     nnnO0 $ UR	                  5        VVs0 s H  u  p4[        R                  X35      U_M     snn$ s  snnf s  snnf )z?Convert a RepoInfo to a plain dict with legacy PascalCase keys.__dataclass_fields__r   )asdict__dict__rO  )hasattrdataclassesr  r  r  r&   r  rg   )rA   r  r   kvs        r(   r?   r?     s    t+,,&Tl	z	"	" $ 3 3 5O 5Q\\#=Ntqt 5O	58YY[A[TQO%q([AA P Bs   B4/B4"B:c                   ^ [        U [        5      (       a  g[        U 5      R                  5       m[	        U4S jS 5       5      $ )z=Return True if the exception is authentication/login related.Tc              3  ,   >#    U  H	  oT;   v   M     g 7frs   r  )rw   kwmsgs     r(   ry   #_is_auth_related.<locals>.<genexpr>  s     ]#\RSy#\s   )r.   loggedr%   unauthorizedu	   未登录)rh   r   rM   lowerr   )rc   r  s    @r(   rk   rk     s6    #*++
c(..
C]#\]]]r+   )rA   r   r   r9   )rc   r`   r   r  )%r  
__future__r   rt   r   r   collectionsr   typingr   r   urllib.parser   rb   r	   	constantsr
   errorsr   r   r   r   r   r   utils.loggerr   typesr   r   r   r  r  r   r  r  r?   rk   r  r+   r(   <module>r     s    # 	   # % "     &-	H	# > p ph   # "
B^r+   