
    5pjiS              
         % S r SSKJr  SSKrSSKJrJr  SSKJrJ	r	J
r
  \(       a  SSKJr  SrS\S	'   \" 1 S
k5      rS\S'   \R"                  " SR%                  \5      \R&                  5      rS\S'   SrSPS jrSQS jr " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\\5      r " S S \5      r  " S! S"\5      r! " S# S$\5      r" " S% S&\\#5      r$ " S' S(\$\%5      r& " S) S*\5      r' " S+ S,\5      r( " S- S.\5      r) " S/ S0\)5      r* " S1 S2\)5      r+ " S3 S4\5      r,\r- \r. \r/ \\\\\\!S5.r0S6\S7'   \\ \ \ S8.r1S6\S9'   SRS: jr2S;S<S<S=S>S?S@SASBSC.	r3SD\SE'   SSSF jr4STSG jr5SUSH jr6\" SI \1Ro                  5        5       5      r8SJ\SK'   \" 1 SLk5      r9S\SM'   SVSN jr:/ SOQr;g)WaU  Exception hierarchy for the ModelScope Hub SDK.

Error codes follow the ModelScope global error-code specification
(``modelscope-errorcode`` registry).  Format: ``E{severity}{seq}``.

Severity layers::

    1 = Infrastructure (network, storage, timeout, rate-limiting, cache)
    2 = Data (file integrity, format, missing data)
    3 = Invocation (auth, permission, parameter validation, resource lookup)
    9 = Unknown / catch-all

The hierarchy is intentionally shallow and protocol-agnostic so callers can
catch broad categories (e.g. :class:`APIError`) without coupling to HTTP
status codes.
    )annotationsN)TYPE_CHECKINGAny)parse_qsurlparse
urlunparse)Response)	tokensecretpasswordcookieauthorization
credentialsessionapi_keyapikeyztuple[str, ...]_SENSITIVE_KEYWORDS>   keyr
   r   r   r   r   r   r   
auth_tokencredentialsaccess_tokenm_session_idr   zfrozenset[str]_SENSITIVE_QUERY_KEYS|zre.Pattern[str]_SENSITIVE_BODY_KEYSz***c                    [        U 5      nUR                  (       d  U $ [        UR                  SS9n/ nUR	                  5        HX  u  pEUR                  5       [        ;   a  UR                  U S[         35        M9  U H  nUR                  U SU 35        M     MZ     [        UR                  SR                  U5      S95      $ ! [         a    U s $ f = f)z,Strip sensitive query parameters from a URL.T)keep_blank_values=&)query)r   	Exceptionr    r   itemslowerr   append	_REDACTEDr   _replacejoin)urlparsedparamsclean_partskvalsvs          Q/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope_hub/errors.py_redact_urlr0   A   s    # <<
flld;FK<<>779--!Ai[12""aS!:. 	 " fooCHH[,AoBCC  
s   C	 	CCc                F   [        U [        5      (       aO  U R                  5        VVs0 s H1  u  pU[        R	                  U5      (       a  [
        O
[        U5      _M3     snn$ [        U [        5      (       a  U  Vs/ s H  n[        U5      PM     sn$ U $ s  snnf s  snf )z8Deep-redact sensitive keys in a response body structure.)
isinstancedictr"   r   searchr%   _redact_bodylist)bodyr,   r.   items       r/   r5   r5   T   s    $`d`j`j`lm`lX\XY 4 ; ;A > >9LQROS`lmm$/34ttT"t44K n4s   8B>Bc                  f   ^  \ rS rSr% SrSrS\S'   SrS\S'   S	rS
\S'   SU 4S jjr	SS jr
SrU =r$ )HubError`   a  Base class for every error raised by :mod:`modelscope_hub`.

Attributes
----------
error_code : str | None
    ModelScope global error code (e.g. ``"E1020"``).
retryable : bool
    Whether the caller should retry the operation.
suggestion : str
    Human-readable remediation hint.
E9001
str | None
error_codeFbool	retryablez3Unexpected error. Please retry or report the issue.str
suggestionc                0   > [         TU ]  U5        Xl        g N)super__init__message)selfrG   kwargs	__class__s      r/   rF   HubError.__init__q   s    !    c                h    U R                   (       a  SU R                    S3OSnU U R                   3$ )N[z]  )r>   rG   )rH   prefixs     r/   __str__HubError.__str__u   s0    ,0OO1T__%R($,,((rL   )rG   )rG   rA   rI   r   returnNonerS   rA   )__name__
__module____qualname____firstlineno____doc__r>   __annotations__r@   rB   rF   rQ   __static_attributes____classcell__rJ   s   @r/   r:   r:   `   s7    
 %J
$ItKJK) )rL   r:   c                  z   ^  \ rS rSrSrSrSrSrSSSSSS.             SU 4S jjjrSS	 jr	SS
 jr
SrU =r$ )APIError}   z.Error returned by the ModelScope Hub HTTP API.r<   Fz7Unexpected API error. Please retry or report the issue.Nstatus_code
request_idresponse_bodyr(   methodc               `   > [         TU ]  U5        X l        X0l        X@l        XPl        X`l        g rD   )rE   rF   rc   rd   re   r(   rf   )rH   rG   rc   rd   re   r(   rf   rJ   s          r/   rF   APIError.__init__   s-     	!&$*rL   c                X   / nU R                   (       a  UR                  SU R                    S35        U R                  b  UR                  SU R                   S35        UR                  U R                  5        U R                  (       a  UR                  SU R                   S35        U R                  5       nU(       a  UR                  SU 35        SR                  U5      n/ nU R                  (       a=  UR                  SU R                  =(       d    S S[        U R                  5       35        U R                  bI  [        [        U R                  5      5      n[        U5      S	:  a  US S	 S
-   nUR                  SU 35        U(       a  US-   SR                  U5      -   $ U$ )NrN   ]z(request_id=)z|  z  Request: GET  ...z  Response: 
)r>   r$   rc   rG   rd   _format_body_detailr'   r(   rf   r0   re   rA   r5   len)rH   partsdetailheadlinedebug_linesbody_strs         r/   rQ   APIError.__str__   sa   ??LL1T__-Q/0'LL1T--.a01T\\"??LL<'8:;))+LL2fX'88E?!#88T[[-AE,B!KPTPXPXDYCZ[\)<(:(:;<H8}s"#DS>E1hZ89d?TYY{%;;;rL   c                   U R                   c  g[        U R                   [        5      (       a  [        U R                   5      n/ nUR	                  S5      =(       d    UR	                  S5      nUb  UR                  SU 35        S HQ  nUR	                  U5      nUc  M  [        U5      n[        U5      S:  a  USS S-   nUR                  U SU 35        MS     U(       a  S	R                  U5      $ gU R                  R                  S
5      (       a1  [        U R                   5      n[        U5      S:  a  USS S-   nSU 3$ g)zDExtract additional detail from response_body not already in message.NCodecodezcode=)Datadatart   Detailerrorsi,  ro   r   z, HTTP rn   zbody=)re   r2   r3   r5   getr$   rA   rr   r'   rG   
startswith)rH   	safe_bodyextrasr{   r   valval_strrw   s           r/   rq   APIError._format_body_detail   s/   %d(($//$T%7%78I "F==(AIMM&,ADdVn-EmmC(?!#hG7|c)")$3-%"7MMSE7)"45 F yy((<<""7++4--.H8}s"#DS>E18*%%rL   )rf   rd   re   rc   r(   )rG   rA   rc   
int | Nonerd   r=   re   
Any | Noner(   r=   rf   r=   rS   rT   rU   )rS   r=   )rV   rW   rX   rY   rZ   r>   r@   rB   rF   rQ   rq   r\   r]   r^   s   @r/   r`   r`   }   s    8JIJJ #'!%$(!  	
  "   
 "2 rL   r`   c                  $    \ rS rSrSrSrSrSrSrg)AuthenticationError   z5Raised on HTTP 401 -- missing or invalid credentials.E3001Fz9Authentication failed. Please verify your token is valid. N	rV   rW   rX   rY   rZ   r>   r@   rB   r\   r   rL   r/   r   r      s    ?JILJrL   r   c                  $    \ rS rSrSrSrSrSrSrg)PermissionDeniedError   z7Raised on HTTP 403 -- authenticated but not authorised.E3002Fz4Permission denied. Please verify your access rights.r   Nr   r   rL   r/   r   r      s    AJIGJrL   r   c                  $    \ rS rSrSrSrSrSrSrg)NotExistError   z5Raised on HTTP 404 -- target resource does not exist.E3020FzThe requested resource does not exist, or it is private and requires authentication. Use `ms login` or pass --token to authenticate.r   Nr   r   rL   r/   r   r      s    ?JI	J rL   r   c                  $    \ rS rSrSrSrSrSrSrg)InvalidParameter   zRaised on HTTP 400, or locally when caller-supplied arguments are invalid.

Inherits :class:`ValueError` so existing ``except ValueError`` handlers
continue to work during the transition period.
E3021Fz3Invalid request parameters. Please check and retry.r   Nr   r   rL   r/   r   r      s     JIFJrL   r   c                  $    \ rS rSrSrSrSrSrSrg)AlreadyExistsError   zGResource already exists (e.g., repo name is taken).

Error code: E3026
E3026Fz5Resource already exists. Use exist_ok=True to ignore.r   Nr   r   rL   r/   r   r      s    
 JIHJrL   r   c                  l   ^  \ rS rSrSrSrSrSrSSSSSSS.               SU 4S	 jjjrS
r	U =r
$ )RateLimitError   z=Raised on HTTP 429 -- client should back off and retry later.E1021Tz?Rate limit exceeded. Please reduce request frequency and retry.  N)rc   rd   re   r(   rf   retry_afterc          	     6   > [         TU ]  UUUUUUS9  Xpl        g )Nrb   )rE   rF   r   )	rH   rG   rc   rd   re   r(   rf   r   rJ   s	           r/   rF   RateLimitError.__init__  s1     	#!' 	 	
 'rL   )r   )rG   rA   rc   r   rd   r=   re   r   r(   r=   rf   r=   r   zint | float | NonerS   rT   )rV   rW   rX   rY   rZ   r>   r@   rB   rF   r\   r]   r^   s   @r/   r   r      s    GJIRJ #&!%$(!*.''  	'
 ' "' ' ' (' 
' 'rL   r   c                  $    \ rS rSrSrSrSrSrSrg)ServerErrori  z/Raised on HTTP 5xx -- upstream service failure.E1002Tz4Server is currently unavailable. Please retry later.r   Nr   r   rL   r/   r   r     s    9JIGJrL   r   c                  $    \ rS rSrSrSrSrSrSrg)NetworkErrori(  zRaised when the request could not reach the server (E1020).

Also inherits :class:`ConnectionError` so existing
``except ConnectionError`` handlers continue to catch SDK network errors.
E1020Tz;Unable to connect to the server. Please check your network.r   Nr   r   rL   r/   r   r   (  s     JINJrL   r   c                  $    \ rS rSrSrSrSrSrSrg)RequestTimeoutErrori4  zRaised when a request times out (E1001).

Inherits :class:`NetworkError` so ``except NetworkError`` catches
timeouts, and :class:`TimeoutError` so ``except TimeoutError`` catches
them as well.
E1001Tz7Request timed out. Please check your network and retry.r   Nr   r   rL   r/   r   r   4  s     JIJJrL   r   c                  $    \ rS rSrSrSrSrSrSrg)StorageErroriA  zCRaised when blob storage operations (upload/download) fail (E1003).E1003TzHFile upload/download failed (storage service error). Please retry later.r   Nr   r   rL   r/   r   r   A  s    MJI[JrL   r   c                  $    \ rS rSrSrSrSrSrSrg)FileIntegrityErroriI  zMRaised when a downloaded or uploaded file fails integrity validation (E2020).E2020Tz8File SHA256 checksum mismatch. Will retry automatically.r   Nr   r   rL   r/   r   r   I  s    WJIKJrL   r   c                  $    \ rS rSrSrSrSrSrSrg)
CacheErroriR  z7Base for local cache filesystem or metadata corruption.E1022FzELocal cache directory error. Please check disk space and permissions.r   Nr   r   rL   r/   r   r   R  s    AJIXJrL   r   c                  4   ^  \ rS rSrSrSSU 4S jjjrSrU =r$ )CacheNotFoundiZ  z4Cache directory does not exist or cannot be created.c                :   > [         TU ]  " U/UQ70 UD6  X l        g rD   )rE   rF   	cache_dir)rH   msgr   argsrI   rJ   s        r/   rF   CacheNotFound.__init__]  s    .t.v."rL   )r   rD   )
r   rA   r   r=   r   r   rI   r   rS   rT   )rV   rW   rX   rY   rZ   rF   r\   r]   r^   s   @r/   r   r   Z  s    ># #rL   r   c                      \ rS rSrSrSrg)CorruptedCacheExceptionib  z4Unexpected structure in the ModelScope cache-system.r   N)rV   rW   rX   rY   rZ   r\   r   rL   r/   r   r   b  s    >rL   r   c                  $    \ rS rSrSrSrSrSrSrg)NotSupportedErrorig  zLRaised when the requested operation is not supported in the current context.E3023Fz@This operation is not supported. Please check the documentation.r   Nr   r   rL   r/   r   r   g  s    VJISJrL   r   )  i  i  i  i  r   zdict[int, type[APIError]]_STATUS_MAP)l   L)	 l   }*	 l   	L)	 l   O)	 _BUSINESS_CODE_MAPc                    [        U [        5      (       d  gU R                  S5      nUc  U R                  S5      nUc  g [        U5      $ ! [        [
        4 a     gf = f)zDReturn the numeric business code carried by a response body, if any.Nrz   r{   )r2   r3   r   int	TypeError
ValueError)r7   raws     r/   _business_coder     s`    dD!!
((6
C
{hhv
{3xz" s   
A AAz?Repository name already exists. Please choose a different name.zUser not logged in.zFailed to update model.z,Invalid parameter: tag name cannot be empty.zModel does not exist.zDataset does not exist.zFailed to create studio.zMDeletion is restricted to web console. Visit https://modelscope.cn to delete.)	u-   该名称已被注册使用，请重新命名u   用户未登录zuser not logged inu   更新模型失败u'   参数错误：版本名称不能为空u   模型不存在u   数据集不存在u   创建空间失败zzthe current token no longer supports deletion operations. Please go to the site page : https://www.modelscope.cn to deletezdict[str, str]	_CN_TO_ENc                d    U (       d  U $ [         R                  5        H  u  pX;   d  M  Us  $    U $ )z3Translate known Chinese server messages to English.)r   r"   )r   cnens      r/   _translate_messager     s.    
//#9I $ JrL   c                   U R                   R                  S5      =(       d    U R                   R                  S5      nSnU R                  nU(       aL  UR                  (       a;  UR                  (       a*  SU R
                   SUR                   SUR                   3nOSU R
                   3n U R                  5       n[        U[        5      (       a  S	 HR  nUR                  U5      n[        U[        5      (       d  M+  UR                  5       (       d  MB  UR                  5       n  O   UR                  S
5      =(       d2    UR                  S5      =(       d    UR                  S5      =(       d    Un[        U5      X4$ ! [         as    U R                  =(       d    Sn[        U[        5      (       a9  UR                  5       (       a$  UR                  5       R                  5       S   SS n[        U5      X4s $ f = f)zFBest-effort extraction of (message, request_id, body) from a response.zx-request-idzX-Request-IdNr   z on rl   r   rn   )rG   Messager   MsgerrorErrorrt   r~   rd   	requestId	RequestId)headersr   requestrf   path_urlrc   jsonr   textr2   rA   strip
splitlinesr   r3   )responserd   r7   reqrG   r   values          r/   _extract_payloadr     s   !!%%n5]9I9I9M9Mn9]JD 

C
szzcll(../tCJJ<qO(../0=}} $]CHHSME%%%%++--++-	 ^
 XXl+ktxx/DkQ\H]kak
g&
88  =}}$dC  TZZ\\jjl--/24C8G!'*J<<	=s   /F A:H ?H c                  ^ U R                   nUS:  a  g[        U 5      u  p#nU R                  nU R                  =(       d    U(       a  UR                  OSnU(       a  UR                  OSnUS:  a  [
        nO[        R                  U[        5      nSn	US:  a%  [        U5      n
U
b  [        R                  U
5      OSn	U	b  U	nOU[        L a  [        U[        5      (       a  UR                  S5      =(       dJ    UR                  S5      =(       d2    UR                  S5      =(       d    UR                  S5      =(       d    SR                  5       m[        U4S	 j[          5       5      (       a  ["        n[        UUUUUS
9nU[$        L a4  U R&                  R                  S5      nSnU(       a   [)        U5      nXS'   U" U40 UD6e! [*         a      [-        U5      n N%! [*         a      N2f = ff = f)a  Inspect ``response`` and raise the most specific exception on failure.

Parameters
----------
response:
    A :class:`requests.Response` instance returned by the SDK transport.

Raises
------
APIError
    Or a subclass thereof when ``response.status_code`` indicates failure.
r   Nrn   r   rG   r   r   rO   c              3  ,   >#    U  H	  oT;   v   M     g 7frD   r   ).0kwmsg_texts     r/   	<genexpr>#raise_for_status.<locals>.<genexpr>  s     A(@"X~(@   rb   zRetry-Afterr   )rc   r   r   r(   rf   r   r   r   r`   r   r   r   r2   r3   r#   any_ALREADY_EXISTS_KEYWORDSr   r   r   r   r   float)r   statusrG   rd   r7   r   r(   rf   exc_clsbusiness_clsr{   rI   retry_after_rawr   r   s                 @r/   raise_for_statusr     s    !!F| 0 :G 

Cll@#sww4C'*F}"-//&(3 +/L|d#7;7G)--d3T	$	$D$)?)?HHY'j488I+>j$((5/jUYU]U]^cUdjhjqqsA(@AAA(G!F . "**..}=*.!/2 !,}
'
$V
$$  "'"8K! s*   3G 
G5G##
G1-G50G11G5c              #  @   #    U  H  u  pU[         L d  M  Uv   M     g 7frD   )r   )r   r{   excs      r/   r   r   2  s       24YT?Q8QDD4s   	zfrozenset[int]_ALREADY_EXISTS_CODES>   existalready	   已存在   已被注册   名称不可用not availablecan not be usedr   c                  ^ [        U [        5      (       a  g[        U 5      R                  5       m[	        U4S j[
         5       5      (       a  g[        U SS5      n[        U[        5      (       aB  UR                  S5      =(       d    UR                  S5      n Ub  [        U5      [        ;   a  ggg! [        [        4 a     gf = f)a  Detect "repo already exists" errors.

With the introduction of :class:`AlreadyExistsError`, this is now
primarily a simple ``isinstance`` check. The keyword/code fallback
is retained for backward compatibility with legacy exceptions that
pre-date the structured error hierarchy.
Tc              3  ,   >#    U  H	  oT;   v   M     g 7frD   r   )r   r   r   s     r/   r   'is_repo_exists_error.<locals>.<genexpr>O  s     
8797r   re   Nrz   r{   F)r2   r   rA   r#   r   r   getattrr3   r   r   r   r   r   )r   r7   r{   r   s      @r/   is_repo_exists_errorr  C  s     #)**
c(..
C

87
8883.D$xx3488F#3	CI1F$F  :& 		s   B5 5CC)r`   r:   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   NotFoundErrorPermissionErrorValidationErrorr  r   )r(   rA   rS   rA   )r7   r   rS   r   )r7   r   rS   r   )r   rA   rS   rA   )r   r	   rS   z"tuple[str, str | None, Any | None])r   r	   rS   rT   )r   BaseExceptionrS   r?   )<rZ   
__future__r   retypingr   r   urllib.parser   r   r   requestsr	   r   r[   	frozensetr   compiler'   
IGNORECASEr   r%   r0   r5   r!   r:   r`   r   r   r   r   r   r   r   r   ConnectionErrorr   TimeoutErrorr   r   r   r   r   r   r   r  r  r  r   r   r   r   r   r   r   r"   r   r   r  __all__r   rL   r/   <module>r     sd  " # 	 % 7 7!

( _ 
 )2) ~ " )+

HH !MM) o  	D&)y ):Jx J\M( MHH HH 	Gx 	GI) I'X '<H( H	O8_ 	O
K, 
K\8 \L LY Y#J #?j ?
T T  0" 3 ( 8 
					*& * %###1 -   6w,/3/].34 	X	>  9<B%V )2 2,2242 ) ~  ,5
, . 
2rL   