
    GjI%                        d Z ddlmZmZmZmZmZ ddlZddlZddl	Z	ddl
mZ erddlmZ ddlZddlmZ  G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zej6                  Zy)z Error classes for the GenAI SDK.    )AnyCallableOptionalTYPE_CHECKINGUnionN   )_common)ReplayResponse)Responsec                       e Zd ZU dZeed<   eej                  de	j                  df   ed<   dZ
ee   ed<   dZee   ed<   	 dded	edeeej                  de	j                  df      f fd
Zdeed   eeeef      f   fdZedeeef   dd fd       Zd	edefdZd	edefdZd	edefdZdej4                  fdZedede	j                  ej                  f   ddfd       Zeded	edeede	j                  ej                  f      ddfd       Zedede	j                  ddf   ddfd       Zeded	edeede	j                  df      ddfd       Z  xZ!S )APIErrorz'General errors raised by the GenAI API.coder
   AsyncAuthorizedSessionResponseresponseNstatusmessageresponse_jsonc                 ^   t        |t              rt        |      dk(  r|d   }|| _        || _        | j                  |      | _        | j                  |      | _        |r|n| j                  |      | _
        t        | 1  | j                   d| j                   d| j                          y )Nr   r    . )
isinstancelistlenr   details_get_messager   _get_statusr   	_get_coder   super__init__)selfr   r   r   	__class__s       Y/var/www/python/quitsure-support/venv/lib/python3.12/site-packages/google/genai/errors.pyr   zAPIError.__init__,   s     -&3}+=+B#A&mDM DL$$]3DL""=1DK$.."?DI	G		{!DKK=4<<.AB    return).r   c                 h    | j                   j                         }| j                  j                  |ffS )zGReturns a tuple that can be used to reconstruct the error for pickling.)__dict__copyr!   _rebuild)r    states     r"   
__reduce__zAPIError.__reduce__D   s-     MM ENN##eX..r#   r)   c                     t         j                  t               }|j                  j                  |        t        j                  ||j                   d|j                   d|j                          |S )z"Rebuilds the error from the state.r   r   )	r   __new__r&   update	Exceptionr   r   r   r   )r)   objs     r"   r(   zAPIError._rebuildK   sX     

8
$CLLssxxj#**R}EFJr#   c                     	 |j                  d|j                  di       j                  dd             }|S # t        $ r Y y w xY w)Nr   errorgetAttributeError)r    r   r   s      r"   r   zAPIError._get_statusS   sQ      
M%%gr266xFf m     36 	AAc                     	 |j                  d|j                  di       j                  dd             }|S # t        $ r Y y w xY w)Nr   r1   r2   )r    r   r   s      r"   r   zAPIError._get_message^   sQ    !!
]&&w377	4Hg n  r5   c                 f    |j                  d|j                  di       j                  dd             S )Nr   r1   )r3   )r    r   s     r"   r   zAPIError._get_codei   s4    !!'2.2264@ r#   c                 N    d| j                   | j                  | j                  diS )zReturns a dictionary representation of the error for replay recording.

    details is not included since it may expose internal information in the
    replay file.
    r1   r   r   r   r9   )r    s    r"   _to_replay_recordzAPIError._to_replay_recordn   s+     	II||kk
 r#   c                 `   |j                   dk(  ryt        |t        j                        r"	 |j	                          |j                         }nKt        |t        j                        r	 |j                         }n|j                  d   j                  di       }| j                  |j                   ||       y# t
        j                  j                  $ r |j                  }||j                  d}Y Xw xY w# t        j                  j                  $ r |j                  |j                  d}Y w xY w)PRaises an error with detailed error message if the response has an error status.   Nr   r   r   r1   )status_coder   httpxr   readjsondecoderJSONDecodeErrortextreason_phraserequests
exceptionsreasonbody_segmentsr3   raise_error)clsr   r   r   s       r"   raise_for_responsezAPIError.raise_for_response|   s    
 s"(ENN+
  
Hh//	0
 ! ,,Q/33GR@mOOH((-B' \\)) 
--,,

   00 
}}oo

s#    B6 (C4 68C10C146D-,D-r?   c                     d|cxk  rdk  rn nt        |||      d|cxk  rdk  rn nt        |||       | |||      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rL   r?   r   r   s       r"   rK   zAPIError.raise_error   sK    4 kC]H==		!c	!]H==]H55r#   zaiohttp.ClientResponsec                   K   t        |t        j                        rF|j                  dk(  ry	 |j	                          d{    |j                         }|j                  }nt        |d      rHt        |d      r<|j                  dk(  ry|j                  d   j                  di       }|j                  }n	 ddl}|}t        |d      r|j                  }t        ||j                        r6|j                   dk(  ry	 |j                          d{   }|j                   }nt)        d	t+        |             	 | j/                  |||       d{    y7 # t
        j                  j                  $ r |j                  }||j                  d}Y >w xY w7 # |j"                  j$                  $ r+ |j                          d{  7  }||j&                  d}Y w xY w# t,        $ r t)        d	t+        |             w xY w7 w)
r<   r=   Nr>   rJ   r?   r   r1   	_responsezUnsupported response type: )r   r@   r   r?   areadrB   rC   rD   rE   rF   hasattrrJ   r3   aiohttprU   ClientResponser   client_exceptionsContentTypeErrorrI   
ValueErrortypeImportErrorraise_error_async)rL   r   r   r   r?   rX   unwrapped_responses          r"   raise_for_async_responsez!APIError.raise_for_async_response   s     (ENN+				$
nn  ((k	?	+-1 
			$,,Q/33GR@m((kI #+%{31;;
('*@*@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   +HE EE A!H8AG! ;H=F FF $G! 9HHHE 8FHFHF ,GG	GG! GG! !!HHc                    K   d|cxk  rdk  rn nt        |||      d|cxk  rdk  rn nt        |||       | |||      wrO   rP   rS   s       r"   r_   zAPIError.raise_error_async   sO     & kC]H==		!c	!]H==]H55s   AA)N)"__name__
__module____qualname____doc__int__annotations__r   rG   r   r@   r   r   strr   r   r   tupler   dictr*   staticmethodr(   r   r   r   r	   
StringDictr:   classmethodrM   rK   ra   r_   __classcell__)r!   s   @r"   r   r      sv   /)nn&(  &(3-'8C= CC C 
nn.0	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                       e Zd ZdZy)rQ   z%Client error raised by the GenAI API.Nrc   rd   re   rf    r#   r"   rQ   rQ         -r#   rQ   c                       e Zd ZdZy)rR   z%Server error raised by the GenAI API.Nrq   rr   r#   r"   rR   rR     rs   r#   rR   c                       e Zd ZdZy) UnknownFunctionCallArgumentErrorzWRaised when the function call argument cannot be converted to the parameter annotation.Nrq   rr   r#   r"   rv   rv     s    _r#   rv   c                       e Zd ZdZy)UnsupportedFunctionErrorz*Raised when the function is not supported.Nrq   rr   r#   r"   rx   rx   #  s    2r#   rx   c                       e Zd ZdZy)FunctionInvocationErrorzDRaised when the function cannot be invoked with the given arguments.Nrq   rr   r#   r"   rz   rz   (  s    Lr#   rz   c                       e Zd ZdZy)UnknownApiResponseErrorz?Raised when the response from the API cannot be parsed as JSON.Nrq   rr   r#   r"   r|   r|   -  s    Gr#   r|   )rf   typingr   r   r   r   r   r@   rB   rG    r	   replay_api_clientr
   rX   !google.auth.aio.transport.aiohttpr   r   r.   r   rQ   rR   r\   rv   rx   rz   r|   ExperimentalWarningrr   r#   r"   <module>r      s     ' @ @     /Zr6y r6j( 
( 
z 
z 
j 
j  11 r#   