
    +jI%                     @   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j        ZdS )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j        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         }|| _        || _        |                     |          | _        |                     |          | _        |r|n| 	                    |          | _
        t                                          | j
         d| j         d| j                    d S )Nr   r    . )
isinstancelistlenr   details_get_messager   _get_statusr   	_get_coder   super__init__)selfr   r   r   	__class__s       W/home/wildlama/visual-decline/.venv/lib/python3.11/site-packages/google/genai/errors.pyr   zAPIError.__init__,   s     -&& '3}+=+=+B+B#A&mDM DL$$]33DL""=11DK?$.."?"?DI	GG	AADKAA4<AABBBBB    return).r   c                 R    | 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)     M  EN#eX..r#   r)   c                     t                               t                     }|j                            |            t                              ||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   sd     

8
$
$CLssxEE#*EEEEFFFJr#   c                     	 |                     d|                     di                                dd                     }|S # t          $ r Y d S w xY w)Nr   errorgetAttributeError)r    r   r   s      r"   r   zAPIError._get_statusS   sl      
M%%gr2266xFF f m    TT   ?A 
AAc                     	 |                     d|                     di                                dd                     }|S # t          $ r Y d S w xY w)Nr   r1   r2   )r    r   r   s      r"   r   zAPIError._get_message^   sl    !!
]&&w3377	4HH g n    TTr5   c                 ~    |                     d|                     di                                dd                     S )Nr   r1   )r3   )r    r   s     r"   r   zAPIError._get_codei   s?    !!'2..2264@@  r#   c                 0    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*     	I|k
 
 r#   c                 *   |j         dk    rdS t          |t          j                  rU	 |                                 |                                }n# t
          j        j        $ r |j        }||j	        d}Y n~w xY wt          |t          j                  r?	 |                                }nJ# t          j        j        $ r |j        |j        d}Y n%w xY w|j        d                             di           }|                     |j         ||           dS )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|   s4   
 s""f(EN++ A
 \) 
 
 
-,
 

 
Hh/	0	0 A
 ! 0 
 
 
}o
 

 ,Q/33GR@@mOOH(-BBBBBs#   (A %A:9A:B- -#CC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   s    4 kC]H===		!	!	!	!c	!	!	!	!	!]H===C]H555r#   zaiohttp.ClientResponsec                   K   t          |t          j                  rq|j        dk    rdS 	 |                                 d{V  |                                }n+# t
          j        j        $ r |j        }||j	        d}Y nw xY w|j        }n@t          |d          rFt          |d          r6|j        dk    rdS |j        d                             di           }|j        }n	 ddl}|}t          |d          r|j        }t          ||j                  rj|j        dk    rdS 	 |                                 d{V }n9# |j        j        $ r' |                                 d{V }||j        d}Y nw xY w|j        }nt)          d	t+          |                     n-# t,          $ r  t)          d	t+          |                     w xY w|                     |||           d{V  dS )
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      (EN++ ,I			$	$
nn \) 
 
 
-,
 

 (kk	?	+	+ I-1 1 I 
		$	$,Q/33GR@@m(kkI #+%{33 	<1;
('*@AA 	K&#--F"4"9"9";";;;;;;;MM*;   .3355555555G",3 MMM +1++IhIIJJ
J   I I IGtH~~GGHHHI 

]H
E
EEEEEEEEEEsA   .A %BB%=F! %E  ?F!  3E63F! 5E66*F! !*Gc                    K   d|cxk    rdk     rn nt          |||          d|cxk    rdk     rn nt          |||           | |||          rO   rP   rS   s       r"   r_   zAPIError.raise_error_async   s      & kC]H===		!	!	!	!c	!	!	!	!	!]H===C]H555r#   )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      sE        //)))n&(    &(3-'8C= C CC C 
n.0	C C C C C C0/Xo&d38n(==>/ / / / d38n     <	s 	s 	 	 	 		 	 	 	 	 	S S    
!3     C+U^X=NNOCC C C ;C@ 66 6 
n!	6 6 6 6 ;6@ 8F

.
"
*,8F 8F 8F 8F ;8Ft 66,/6;C
 %.2JJ
K<6 	6 6 6 ;6 6 6 6 6r#   r   c                       e Zd ZdZdS )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dS )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dS ) 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dS )UnsupportedFunctionErrorz*Raised when the function is not supported.Nrq   rr   r#   r"   rx   rx   #  s        22$r#   rx   c                       e Zd ZdZdS )FunctionInvocationErrorzDRaised when the function cannot be invoked with the given arguments.Nrq   rr   r#   r"   rz   rz   (  s        LL$r#   rz   c                       e Zd ZdZdS )UnknownApiResponseErrorz?Raised when the response from the API cannot be parsed as JSON.Nrq   rr   r#   r"   r|   r|   -  s        G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ZZZZZr6 r6 r6 r6 r6y r6 r6 r6j    (   
    (   
    z   
    z   
    j   
    j    1   r#   