
    9i(                     &   S SK r S SKJr  S SKJr  S SKJrJr  S SKrS SK	J
r
  S SKJr  S SKJr  \" \ R                  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 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rS\R:                  4S  jrS! rS\R:                  4S" jr S# r! S+S\R:                  S$\\"   S%\#4S& jjr$S' r%S(\R:                  4S) jr&S* r'g),    N)
HTTPStatus)Path)OptionalUnion)	HTTPError)MODELSCOPE_REQUEST_ID)
get_logger)	log_levelc                       \ rS rSrSrg)NotSupportError    N__name__
__module____qualname____firstlineno____static_attributes__r       U/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/hub/errors.pyr   r          r   r   c                       \ rS rSrSrg)NoValidRevisionError   r   Nr   r   r   r   r   r      r   r   r   c                       \ rS rSrSrg)NotExistError   r   Nr   r   r   r   r   r      r   r   r   c                       \ rS rSrSrg)RequestError   r   Nr   r   r   r   r   r      r   r   r   c                       \ rS rSrSrg)GitError!   r   Nr   r   r   r   r"   r"   !   r   r   r"   c                       \ rS rSrSrg)InvalidParameter%   r   Nr   r   r   r   r%   r%   %   r   r   r%   c                       \ rS rSrSrg)NotLoginException)   r   Nr   r   r   r   r(   r(   )   r   r   r(   c                       \ rS rSrSrg)FileIntegrityError-   r   Nr   r   r   r   r+   r+   -   r   r   r+   c                       \ rS rSrSrg)FileDownloadError1   r   Nr   r   r   r   r.   r.   1   r   r   r.   c                   X   ^  \ rS rSr% Sr\\\4   \S'   S\S\\\4   4U 4S jjr	Sr
U =r$ )CacheNotFound5   z8Exception thrown when the ModelScope cache is not found.	cache_dirmsgc                 :   > [         TU ]  " U/UQ70 UD6  X l        g )N)super__init__r3   )selfr4   r3   argskwargs	__class__s        r   r7   CacheNotFound.__init__:   s    .t.v."r   )r3   )r   r   r   r   __doc__r   strr   __annotations__r7   r   __classcell__)r;   s   @r   r1   r1   5   s6    BS$Y#C #E#t),< # #r   r1   c                       \ rS rSrSrSrg)CorruptedCacheException?   zFException for any unexpected structure in the ModelScope cache-system.r   N)r   r   r   r   r=   r   r   r   r   rB   rB   ?   s    Pr   rB   responsec                 z    [         U R                  R                  ;   a  U R                  R                  [            $ g)N )r   requestheadersrD   s    r   get_request_idrJ   C   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_okrQ   J   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-typerF   utf-8)rH   getjsoncontentdecode)rD   messages     r   _decode_response_errorrY   V   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   rY   rJ   )rD   urlrequest_bodyerrorrX   s        r   handle_http_post_errorr_   ^   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U R                  :X  a  SU-  nOSU R                  :X  a  Uc  SU S3nOS	U S
3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(       a!  U(       a  UR                  U5        [        XPS9eU R                  $ ! [         a    U R                  R                  S5      n GNf = f)NrF   rS   
iso-8859-1  z%The request model: %s does not exist!  z<Authentication token does not exist, failed to access model z; which may not exist or may be private. Please login first.z<The authentication token is invalid, failed to access model .     Client Error: , Request id: 
 for url: X   Server Error: , for url: rI   )

isinstancereasonbytesrW   UnicodeDecodeErrorrJ   status_coder\   r^   r   )rD   loggercookiesmodel_idr`   http_error_msgrp   
request_ids           r   handle_http_responsery   i   sK   
 N(//5))	:__++G4F )J
h"""@HM	$$	$?Nxj YM M 
  \\d[eefgN	$$	*s	*  &*hllD 
$$	*s	*  &*hllD.^$::###5 " 	:__++L9F	:s   E   %E)(E)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.
rL   TMessage)r   rN   r   rO   s    r   r`   r`      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.
rL   T	RequestIdzUrl = z, Request id=z Code = z Message = r{   zC,                Please specify correct dataset_name and namespace.)rT   r   rN   r   )r\   rP   r|   rx   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.
rF   rS   rc   rd   z7The request resource(model or dataset) does not exist!,zurl: z
, reason: re   z/Authentication token does not exist or invalid.rg   rh   ri   rj   rk   rl   rm   rn   POSTz, body: rI   N)ro   rp   rq   rW   rr   rJ   rs   r\   rG   methodbodyr   )rP   rw   rp   rx   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)(logginghttpr   pathlibr   typingr   r   requestsrequests.exceptionsr   modelscope.hub.constantsr   modelscope.utils.loggerr	   WARNINGrt   	Exceptionr   r   r   r   r"   r%   r(   r+   r.   r1   rB   ResponserJ   rQ   rY   r_   boolintry   r`   r   r   r   r   r   <module>r      s2      "  ) : .	goo	.	i 		9 		I 		9 		y 		y 			 		 			 	#I #Qi QX.. 	;X%6%6 O ;?	#$8#4#4 #$ *2$	#$ DG	#$L+$EH4E4E E.%6r   