
    6pj!                        S r SSKrSSKJr  SSKJr  SSKrSSKJr  SSKJ	r	J
r
JrJrJrJrJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJr  \" \R6                  S
9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\RF                  4S jr$S r%S\RF                  4S jr&S r' S#S\RF                  S\\(   S\)4S jjr*S r+S \RF                  4S! jr,S" r-g)$u  Error classes — core exceptions delegate to modelscope_hub, legacy aliases retained.

Exception classes from modelscope_hub provide the structured hierarchy.
Legacy aliases maintain isinstance compatibility for existing code.
Error handling functions with unique logic are retained.
    N)
HTTPStatus)Optional)AuthenticationError)APIErrorCacheNotFoundCorruptedCacheExceptionFileIntegrityErrorHubErrorInvalidParameterNetworkErrorNotExistErrorNotSupportedErrorPermissionDeniedErrorRequestTimeoutErrorServerError)	HTTPError)MODELSCOPE_REQUEST_ID)
get_logger)	log_levelc                   8   ^  \ rS rSrSrSS\4U 4S jjjrSrU =r$ )RequestError   u+   Legacy alias — use APIError for new code.messagec                 (   > [         TU ]  " U40 UD6  g Nsuper__init__selfr   argskwargs	__class__s       Q/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope/hub/errors.pyr   RequestError.__init__!   s    +F+      	__name__
__module____qualname____firstlineno____doc__strr   __static_attributes____classcell__r#   s   @r$   r   r      s    5, , ,r&   r   c                   8   ^  \ rS rSrSrSS\4U 4S jjjrSrU =r$ )NotLoginException&   u6   Legacy alias — use AuthenticationError for new code.r   c                 (   > [         TU ]  " U40 UD6  g r   r   r   s       r$   r   NotLoginException.__init__)       +F+r&   r'   r(   r*   r3   s   @r$   r5   r5   &   s    @, , ,r&   r5   c                       \ rS rSrSrSrg)FileDownloadError-   u/   Legacy alias — use NetworkError for new code.r'   Nr+   r,   r-   r.   r/   r1   r'   r&   r$   r;   r;   -   s    9r&   r;   c                       \ rS rSrSrSrg)NotSupportError2   u4   Legacy alias — use NotSupportedError for new code.r'   Nr=   r'   r&   r$   r?   r?   2   s    >r&   r?   c                   8   ^  \ rS rSrSrSS\4U 4S jjjrSrU =r$ )NoValidRevisionError7   u8   Legacy alias — raised when no valid revision is found.r   c                 (   > [         TU ]  " U40 UD6  g r   r   r   s       r$   r   NoValidRevisionError.__init__:   r9   r&   r'   r(   r*   r3   s   @r$   rB   rB   7   s    B, , ,r&   rB   c                       \ rS rSrSrSrg)GitError>   zGit operation failure.r'   Nr=   r'   r&   r$   rG   rG   >   s     r&   rG   responsec                 z    [         U R                  R                  ;   a  U R                  R                  [            $ g)Nr)   )r   requestheadersrI   s    r$   get_request_idrN   F   s1     0 0 8 88''(=>>r&   c                 F    U S   [         R                  :H  =(       a    U S   $ )zCheck the request is ok

Args:
    rsp (Response): The request response body

Returns:
   bool: `True` if success otherwise `False`.
CodeSuccess)r   OKrsps    r$   is_okrU   M   s      v;*--':C	N:r&   c                     SU R                   R                  SS5      ;   a  U R                  5       nU$ U R                  R	                  S5      nU$ )Nzapplication/jsonzcontent-typer)   utf-8)rL   getjsoncontentdecode)rI   r   s     r$   _decode_response_errorr\   Y   sL    X--11."EE--/ N ""))'2Nr&   c                      U R                  5         g ! [         a5  n[        U 5      n[        SU< SU< SU< S[        U 5      < 35      UeS nAff = f)NzRequest z with body: z exception, Response details: z, request id: )raise_for_statusr   r\   rN   )rI   urlrequest_bodyerrorr   s        r$   handle_http_post_errorrb   a   s\    O!!# O(2 ,)ACD JO	OOs    
A0AAraise_on_errorreturnc                    Sn[        U R                  [        5      (       a   U R                  R                  S5      nOU R                  n[        U 5      nSnU R                  S:  ax   U R                  5       n	U	R                  S5      =(       d    U	R                  S5      =(       d    Sn
U	R                  S5      =(       d    SnU
(       a  U(       a  SU S	U
 3OS
U
 3nSU R                  :X  a  SU< SU< SU R                  < U< 3nOSU R                  :X  a  Uc	  SU SU 3nOSU SU 3nOSU R                  s=::  a  S:  a,  O  O)U R                  < SU< SU< SU R                  < U< 3nOBSU R                  s=::  a  S:  a+  O  O(U R                  < SU< SU< SU R                  < U< 3nU(       a!  U(       a  UR                  U5        [        XPS9eU R                  $ ! [         a    U R                  R                  S5      n GNf = f! [        [        4 a2    U R                  (       a  U R                  S S OSnU(       a  SU 3n GNwf = f)Nr)   rW   
iso-8859-1  r   Messagecodez | Server message: [z] z | Server message:   z | Response body:   z404 Not Found: z2 does not exist or is not accessible, Request id: 
 for url:   z6Authentication token does not exist, failed to access z; which may not exist or may be private. Please login first.z6The authentication token is invalid, failed to access . Client Error: , Request id: X   Server Error: , for url: rM   )
isinstancereasonbytesr[   UnicodeDecodeErrorrN   status_coderY   rX   
ValueErrorAttributeErrortextr_   ra   r   )rI   loggercookiesmodel_idrc   http_error_msgru   
request_idserver_message	resp_jsonmsgri   	body_texts                r$   handle_http_responser   l   s2   
 N(//5))	:__++G4F )J Ns"	B I--	*LimmI.FL"C==(.BDIM#7vRu!EUhilhmSn h""" z8<<A 	 
$$	$?H
 SMM[L\^  I
RSTbScd  
$$	*s	*  &*hll 
$$	*s	*  &*hll .^$::###g " 	:__++L9F	:  N+ 	B/7}}ds+"I#5i[!A		Bs$   G* )A7H *%HH>IIc                 N    U S   [         R                  :X  a  g[        U S   5      e)zIf response error, raise exception

Args:
    rsp (_type_): The server response

Raises:
    RequestError: the response error message.

Returns:
    bool: True if request is OK, otherwise raise `RequestError` exception.
rP   Trh   )r   rR   r   rS   s    r$   rc   rc      s&     6{jmm#3y>**r&   http_responsec                     UR                  S5      [        R                  :X  a  gUS   n[        SU  SU SUS    SUS    S	3	5      e)
a-  If response error, raise exception

Args:
    url (str): The request url
    rsp (HTTPResponse): The server response.
    http_response: the origin http response.

Raises:
    RequestError: the http request error.

Returns:
    bool: `True` if request is OK, otherwise raise `RequestError` exception.
rP   T	RequestIdzUrl = z, Request id=z Code = z Message = rh   zC,                Please specify correct dataset_name and namespace.)rX   r   rR   r   )r_   rT   r   r   s       r$   datahub_raise_on_errorr      sf     wwv*--'%
SEzl(3v;-{SVW`SaRb cC DE 	Er&   c                    Sn[        U R                  [        5      (       a   U R                  R                  S5      nOU R                  n[        U 5      nSU R                  :X  a  SnSU R                  < SU< 3  OSU R                  :X  a  S	nOS
U R                  s=::  a  S:  a)  O  O&U R                  < SU< SU< SU R                  < 3nO?SU R                  s=::  a  S:  a(  O  O%U R                  < SU< SU< SU R                  < 3nU(       a8  U R                  nUR                  S:X  a  U< SUR                  < 3n[        XS9eg! [         a    U R                  R                  S5      n GN,f = f)zAttempt to decode utf-8 first since some servers
localize reason strings, for invalid utf-8, fall back
to decoding with iso-8859-1.

Args:
    rsp: The http response.

Raises:
    HTTPError: The http error info.
r)   rW   rf   rk   z7The request resource(model or dataset) does not exist!,zurl: z
, reason: rm   z/Authentication token does not exist or invalid.rg   rj   ro   rp   rl   rq   rr   rs   POSTz, body: rM   N)rt   ru   rv   r[   rw   rN   rx   r_   rK   methodbodyr   )rT   r   ru   r   reqs        r$   raise_for_http_statusr      s'    N#**e$$	5ZZ&&w/F $J
cooR!$&1		J		%#	%OOVZ: 
	%#	%OOVZ: kk::0>IN55	 % " 	5ZZ&&|4F	5s   E %E87E8)T).r/   logginghttpr   typingr   requestsmodelscope_hub.errorsr   r   r   r   r	   r
   r   r   r   r   r   r   r   requests.exceptionsr   modelscope.hub.constantsr   modelscope.utils.loggerr   WARNINGr|   r   r5   r;   r?   rB   rG   ResponserN   rU   r\   rb   boolintr   rc   r   r   r'   r&   r$   <module>r      s       50 0 0 0 * : .	goo	.
,8 ,,+ ,	 	
	' 	
,= ,	x 	X.. 	;X%6%6 O ;?	<$8#4#4 <$ *2$	<$ DG	<$~+$EH4E4E E.%6r&   