
    OjI%                     (   S r SSKJrJrJrJrJr  SSKrSSKrSSK	r	SSK
Jr  \(       a  SSKJr  SSKrSSK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\R6                  rg)z Error classes for the GenAI SDK.    )AnyCallableOptionalTYPE_CHECKINGUnionN   )_common)ReplayResponse)Responsec                     ^  \ rS rSr% Sr\\S'   \\R                  S\
R                  S4   \S'   Sr\\   \S'   Sr\\   \S	'    SS\S
\S\\\R                  S\
R                  S4      4U 4S jjjrS\\S   \\\\4      4   4S jr\S\\\4   SS 4S j5       rS
\S\4S jrS
\S\4S jrS
\S\4S jrS\R6                  4S jr\S\S\
R                  \R                  4   SS4S j5       r\S\S
\S\\S\
R                  \R                  4      SS4S j5       r\S\S\
R                  SS4   SS4S j5       r \S\S
\S\\S\
R                  S4      SS4S j5       r!Sr"U =r#$ )APIError   z'General errors raised by the GenAI API.coder
   AsyncAuthorizedSessionResponseresponseNstatusmessageresponse_jsonc                 p  > [        U[        5      (       a  [        U5      S:X  a  US   nX0l        X l        U R                  U5      U l        U R                  U5      U l        U(       a  UOU R                  U5      U l
        [        TU ]1  U R                   SU R                   SU R                   35        g )Nr   r    . )
isinstancelistlenr   details_get_messager   _get_statusr   	_get_coder   super__init__)selfr   r   r   	__class__s       U/var/www/html/leaf-doctor-v1/venv/lib/python3.13/site-packages/google/genai/errors.pyr    APIError.__init__,   s     -&&3}+=+B#A&mM L$$]3DL""=1DK$.."?DI	G		{!DKK=4<<.AB    return).r   c                 h    U R                   R                  5       nU R                  R                  U44$ )zGReturns a tuple that can be used to reconstruct the error for pickling.)__dict__copyr"   _rebuild)r!   states     r#   
__reduce__APIError.__reduce__D   s-     MM ENN##eX..r%   r+   c                     [         R                  [         5      nUR                  R                  U 5        [        R                  XR                   SUR                   SUR                   35        U$ )z"Rebuilds the error from the state.r   r   )	r   __new__r(   update	Exceptionr    r   r   r   )r+   objs     r#   r*   APIError._rebuildK   sV     

8
$CLLsxxj#**R}EFJr%   c                      UR                  SUR                  S0 5      R                  SS 5      5      nU$ ! [         a     g f = f)Nr   errorgetAttributeError)r!   r   r   s      r#   r   APIError._get_statusS   sQ      
M%%gr266xFf m     36 
AAc                      UR                  SUR                  S0 5      R                  SS 5      5      nU$ ! [         a     g f = f)Nr   r5   r6   )r!   r   r   s      r#   r   APIError._get_message^   sQ    !!
]&&w377	4Hg n  r:   c                 f    UR                  SUR                  S0 5      R                  SS 5      5      $ )Nr   r5   )r7   )r!   r   s     r#   r   APIError._get_codei   s4    !!'2.2264@ r%   c                 N    SU R                   U R                  U R                  S.0$ )zReturns a dictionary representation of the error for replay recording.

details is not included since it may expose internal information in the
replay file.
r5   r   r   r   r@   )r!   s    r#   _to_replay_recordAPIError._to_replay_recordn   s+     	II||kk
 r%   c                 x   UR                   S:X  a  g[        U[        R                  5      (       a"   UR	                  5         UR                  5       nOP[        U[        R                  5      (       a   UR                  5       nOUR                  S   R                  S0 5      nU R                  UR                   X!5        g! [
        R                  R                   a    UR                  nUUR                  S.n NXf = f! [        R                  R                   a    UR                  UR                  S.n Nf = f)PRaises an error with detailed error message if the response has an error status.   Nr   r   r   r5   )status_coder   httpxr   readjsondecoderJSONDecodeErrortextreason_phraserequests
exceptionsreasonbody_segmentsr7   raise_error)clsr   r   r   s       r#   raise_for_responseAPIError.raise_for_response|   s   
 s"(ENN++
  
Hh//	0	0
 ! ,,Q/33GR@mOOH((-B' \\)) 
--,,

   00 
}}oo

s#    C  3C?  9C<;C<?7D98D9rG   c                     SUs=::  a  S:  a  O  O[        XU5      eSUs=::  a  S:  a  O  O[        XU5      eU " XU5      ea  Raises an appropriate APIError subclass based on the status code.

Args:
  status_code: The HTTP status code of the response.
  response_json: The JSON body of the response, or a dict containing error
    details.
  response: The original response object.

Raises:
  ClientError: If the status code is in the 4xx range.
  ServerError: If the status code is in the 5xx range.
  APIError: For other error status codes.
i  i  iX  ClientErrorServerErrorrT   rG   r   r   s       r#   rS   APIError.raise_error   sE    4 kCH==		!c	!H==H55r%   zaiohttp.ClientResponsec                 J  #    [        U[        R                  5      (       aG  UR                  S:X  a  g UR	                  5       I Sh  vN   UR                  5       nUR                  nO[        US5      (       aN  [        US5      (       a=  UR                  S:X  a  gUR                  S   R                  S0 5      nUR                  nO SSKnUn[        US5      (       a  UR                  n[        XeR                  5      (       a7  UR                   S:X  a  g UR                  5       I Sh  vN nUR                   nO[)        S	[+        U5       35      eU R/                  XBU5      I Sh  vN   g GN(! [
        R                  R                   a    UR                  nUUR                  S.n GNRf = f N! UR"                  R$                   a+    UR                  5       I Sh  vN  nUUR&                  S.n Nf = f! [,         a    [)        S	[+        U5       35      ef = f N7f)
rD   rE   NrF   rR   rG   r   r5   	_responsezUnsupported response type: )r   rH   r   rG   areadrJ   rK   rL   rM   rN   hasattrrR   r7   aiohttpr_   ClientResponser   client_exceptionsContentTypeErrorrQ   
ValueErrortypeImportErrorraise_error_async)rT   r   r   r   rG   rb   unwrapped_responses          r#   raise_for_async_response!APIError.raise_for_async_response   s     (ENN++				$
nn  ((k	?	+	+-1 1 
			$,,Q/33GR@m((kI #+%{331;;
(*@*@AA&&#-"4"9"9";;M +11+8h8HIJ
J 

H
EEEU 	\\)) 
--,,

6 <**;; .33555G",33M  I6tH~6FGHHI Fs   1H#E2 E/E2 A,H#	AG< H#F4 +F2,F4 0G< <H#=G< H#)H!*H#/E2 29F/+H#.F//H#2F4 4-G9!G$"G96G< 8G99G< <"HH#c                    #    SUs=::  a  S:  a  O  O[        XU5      eSUs=::  a  S:  a  O  O[        XU5      eU " XU5      e7frX   rY   r\   s       r#   ri   APIError.raise_error_async   sH     & kCH==		!c	!H==H55s   AA)r   r   r   r   r   )N)$__name__
__module____qualname____firstlineno____doc__int__annotations__r   rO   r   rH   r   r   strr   r   r    tupler   dictr,   staticmethodr*   r   r   r   r	   
StringDictrA   classmethodrU   rS   rk   ri   __static_attributes____classcell__)r"   s   @r#   r   r      s|   /)nn&(  &(3-'8C= CC C 
nn.0	C C0/Xo&d38n(==>/ d38n   	s 	s 		 	 	S S 
!3!3  C+U^^X=N=NNOCC C@ 66 6 
nn!	6 6 6@ 8F

..
"
*,8F 8F 8Ft 66,/6;C
 %..2JJ
K<6 	6 6r%   r   c                       \ rS rSrSrSrg)rZ   i  z%Client error raised by the GenAI API. Nro   rp   rq   rr   rs   r|   r   r%   r#   rZ   rZ         -r%   rZ   c                       \ rS rSrSrSrg)r[   i  z%Server error raised by the GenAI API.r   Nr   r   r%   r#   r[   r[     r   r%   r[   c                       \ rS rSrSrSrg) UnknownFunctionCallArgumentErrori  zWRaised when the function call argument cannot be converted to the parameter annotation.r   Nr   r   r%   r#   r   r     s    _r%   r   c                       \ rS rSrSrSrg)UnsupportedFunctionErrori#  z*Raised when the function is not supported.r   Nr   r   r%   r#   r   r   #  s    2r%   r   c                       \ rS rSrSrSrg)FunctionInvocationErrori(  zDRaised when the function cannot be invoked with the given arguments.r   Nr   r   r%   r#   r   r   (  s    Lr%   r   c                       \ rS rSrSrSrg)UnknownApiResponseErrori-  z?Raised when the response from the API cannot be parsed as JSON.r   Nr   r   r%   r#   r   r   -  s    Gr%   r   )rs   typingr   r   r   r   r   rH   rJ   rO    r	   replay_api_clientr
   rb   !google.auth.aio.transport.aiohttpr   r   r1   r   rZ   r[   rf   r   r   r   r   ExperimentalWarningr   r%   r#   <module>r      s     ' @ @     /Zr6y r6j( 
( 
z 
z 
j 
j  11 r%   