o
    pkj3c                    @   sv  d Z ddlZddlmZ ddlZddlmZ ddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlZddl Z ddl!Z!ddl"Z#ddl$Z#ddl$m%Z% dd	l&m'Z' dd
l"m(Z) ddl*Z*ddl+m,Z, ddl+m-Z- ddl.Z.ddl/m0Z0 ddl/m1Z1 ddl/m2Z2 ddl3m4Z4 ddl3m5Z5 ddl3m6Z7 ddl3m8Z8 ddl3m9Z9 zddl:m;Z< W n e=y   ddl>m;Z< Y nw dZ?zddl@Z@dZ?W n	 eAy   Y nw zddlBZBW n eAy   dZBY nw er"ddlCmDZD ddlEmFZF ddlGmHZH e
IdZJdZKdZLdZMdZNd ZOd!d"hZPeBdu r>e*jQfne*jQeBjQfZReBdu rMe*jSfne*jSeBjSfZTeBdu r^e*jUe*jVfn	e*jUe*jVeBjUeBjVfZWG d#d$ d$eXZYd%eeZ fd&d'Z[d(e\eZeZf d%dfd)d*Z]d+e4d,e4d%e4fd-d.Z^d(e\eZeZf d/eee_e`f  d%dfd0d1Zad2eZd3eZd%eZfd4d5Zbd6eeZdf d%ee%eZf fd7d8Zcd9e%d%e%fd:d;Zdd<eee_e`f  d%ee_ fd=d>ZeeG d?d@ d@ZfG dAdB dBZ6dCZgdDZhdEZid ZjdZkdFZld+ee8 d%e0jmfdGdHZnG dIdJ dJe*joZpG dKdL dLe*jqZrG dMdN dNZsdOdNd9e#jtjuj%d%eZfdPdQZvdOdNd9e#jtjuj%d%eZfdRdSZwdS )TzBase client for calling HTTP APIs sending and receiving JSON.

The BaseApiClient is intended to be a private module and is subject to change.
    N)	Generator)	dataclass)	AnyAsyncIteratorIteratorOptionalTYPE_CHECKINGTupleUnioncastoverload)urlparse)
urlunparse)Credentials)mtls)
exceptions)	BaseModel)ValidationError   )_common)errors)version)HttpOptions)HttpOptionsOrDict)HttpResponse)HttpRetryOptions)ResourceScope)connectFTAuthorizedSession)CIMultiDictProxy)CaseInsensitiveDictzgoogle_genai._api_clienti   i  @       useuc                   @   s   e Zd ZdZdS )EphemeralTokenAPIKeyErrorz)Error raised when the API key is invalid.N)__name__
__module____qualname____doc__ r+   r+   V/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/google/genai/_api_client.pyr&   {   s    r&   returnc                  C   s:   t jdd} t jdd}| r|rtd | p|pdS )zGets the API key from environment variables, prioritizing GOOGLE_API_KEY.

  Returns:
      The API key string if found, otherwise None. Empty string is considered
      invalid.
  GOOGLE_API_KEYNGEMINI_API_KEYzEBoth GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY.)osenvirongetloggerwarning)env_google_api_keyenv_gemini_api_keyr+   r+   r,   get_env_api_key   s   r7   headersc                 C   s  dt j }dtj  d  }| d| }d| v r,|| d vr,| d| d  | d< nd| v rB|| d vrB| d  d| | d< nd| vrJ|| d< d| v ra|| d vra| d| d  | d< dS d| v rx|| d vrx| d  d| | d< dS d| vr|| d< dS dS )z1Appends the telemetry header to the headers dict.zgoogle-genai-sdk/z
gl-python/r    z
user-agentzx-goog-api-clientN)r   __version__syssplit)r8   library_labellanguage_labelversion_header_valuer+   r+   r,   append_library_version_headers   s*   

r@   optionspatch_optionsc                 C   s   |   }|jpi }|jpi }i |||_tj }|D ]!}|dkr#qt||d }|d ur4t||| qt||t| | q|jd urHt|j |S )Nr8   )
model_copyr8   r   model_fieldskeysgetattrsetattrr@   )rA   rB   copy_optionoptions_headerspatch_options_headershttp_options_keyskeypatch_valuer+   r+   r,   patch_http_options   s&   




rN   timeout_in_secondsc                 C   s*   |rd| vrt t|| d< dS dS dS )z8Populates the server timeout header in the headers dict.zX-Server-TimeoutN)strmathceil)r8   rO   r+   r+   r,   populate_server_timeout_header   s   rS   base_urlpathc                 C   sZ   t | }|jdr|jd d n|j}|dr|dd  n|}t|j|d | dS )N/r   )rU   )r   rU   endswith
startswithr   _replace)rT   rU   parsed_base	base_pathr+   r+   r,   join_url_path   s   
r]   projectc                 C   s0   t jjdgd\}}| s|} | std|| fS )z-Loads google auth credentials and project id.z.https://www.googleapis.com/auth/cloud-platform)scopesz@Could not resolve project using application default credentials.)googleauthdefault
ValueError)r^   credentialsloaded_project_idr+   r+   r,   	load_auth   s   
rf   rd   c                 C   s   ddl m} | |  | S )Nr   )Request)google.auth.transport.requestsrg   refresh)rd   rg   r+   r+   r,   refresh_auth   s   rj   timeoutc                 C   s   | r| d }|S d}|S )z Converts the timeout to seconds.g     @@Nr+   )rk   rO   r+   r+   r,   get_timeout_in_seconds   s
   rl   c                   @   sV   e Zd ZU eeef ed< eed< eed< eeeef ef ed< dZ	e
e ed< dS )HttpRequestr8   urlmethoddataNrk   )r'   r(   r)   dictrP   __annotations__r
   objectbytesrk   r   floatr+   r+   r+   r,   rm     s   
 rm   c                	   @   s  e Zd Z		d deeeef ejddf deeef deee	f fddZ
d!d
dZd	efddZed	efddZd	eeddf fddZd	ee fddZd	eee	ef ddf fddZdeeef d	dfddZd	ee fddZd	ee fddZeded	efddZdS )"r   Nr8   zCIMultiDictProxy[str]r!   response_streambyte_streamc                    s   t  tr	 | _n?t  tr fdd  D | _n-t  }d ur5t  |jjr5dd  	 D | _nt
 jdkrH fdd  D | _d| _|| _|| _d S )Nc                       i | ]}|d   |qS z, )joinget_list.0rL   r8   r+   r,   
<dictcomp>      z)HttpResponse.__init__.<locals>.<dictcomp>c                 S   s   i | ]\}}||qS r+   r+   )r}   rL   valuer+   r+   r,   r   &  s    r    c                    rx   ry   )rz   getallr|   r~   r+   r,   r   (  r      )
isinstancerq   r8   _HTTPX_HEADERS_TYPESrE   r   loaded_requests
structuresr!   itemstyper'   status_coderv   rw   )selfr8   rv   rw   requests_moduler+   r~   r,   __init__  s*   






zHttpResponse.__init__r-   c                 C   s   |   | _| S N)async_segmentssegment_iteratorr   r+   r+   r,   	__aiter__1  s   
zHttpResponse.__aiter__c                    s(   z	| j  I d H W S  ty   tw r   )r   	__anext__StopIterationStopAsyncIterationr   r+   r+   r,   r   5  s   zHttpResponse.__anext__c                 C   s4   t | jtsd S | jr| jd sdS | | jd S )Nr    )r   rv   list_load_json_from_responser   r+   r+   r,   json;  s
   zHttpResponse.jsonc                 c   sh    t | jtr| jD ]}|r| |ni V  q
d S | jd u r%g E d H  d S |  D ]}| |V  q)d S r   )r   rv   r   r   _iter_response_stream)r   chunkr+   r+   r,   segmentsG  s   

zHttpResponse.segmentsc                 C  s   t | jtr| jD ]}|r| |ni V  q
d S | jd u r-g 2 z	3 d H W }|V  q 6 d S |  2 z3 d H W }| |V  q16 d S r   )r   rv   r   r   _aiter_response_stream)r   r   cr+   r+   r,   r   S  s   

zHttpResponse.async_segmentsc                 c   s>    t | jtr| jE d H  d S | jd u rg E d H  d S td)Nz8Byte segments are not supported for streaming responses.)r   rw   r   rc   r   r+   r+   r,   byte_segments`  s   
zHttpResponse.byte_segmentsresponse_payloadc                 C   s0   t | d t| D ]}tt| |||< q	d S )Nr   )delattrdircopydeepcopyrF   )r   r   	attributer+   r+   r,   _copy_to_dictk  s   
zHttpResponse._copy_to_dictc                 c   s$   t  }t| jts"|durt| j|js"tdt| jj dd}d}g }t| jtr4| j	 }n| jj	dd}|D ]C}|sL|rKd
|V  g }q=|d	r]||td	d  q=|D ]}|d
krj|d7 }q_|dkrr|d8 }q_||7 }|dkr|V  d}q=|r|V  |rd
|V  dS dS )z,Iterates over chunks retrieved from the API.NzFExpected self.response_stream to be an httpx.Response object, but got .r   r   T)decode_unicode
data: {r   })r   r   r   rv   _HTTPX_RESPONSE_TYPESResponse	TypeErrorr   r'   
iter_linesrz   rY   appendlen)r   r   r   balancedata_bufferrv   liner   r+   r+   r,   r   q  sV   



z"HttpResponse._iter_response_streamc           	      C  s  t | jtptot | jtj}|stdt| jj dd}d}g }t | jtrzq| j}|	 2 zG3 dH W }|sE|rDd
|V  g }q2|drV||tdd  q2|D ]}|dkrc|d	7 }qX|d
krk|d	8 }qX||7 }|dkry|V  d}q26 |r|V  |rd
|V  W | I dH  dS W | I dH  dS | I dH  w trEt | jtjrGz	 z| jjjtdI dH }W n ty   | jj I dH }Y nw |snL|d }|s|rd
|V  g }q|dr||tdd  q|D ]}|dkr|d	7 }q|d
kr|d	8 }q||7 }|dkr|V  d}q|r&|V  |r7d
|V  W | j  dS W | j  dS | j  w dS dS )z;Asynchronously iterates over chunks retrieved from the API.z`Expected self.response_stream to be an httpx.Response or aiohttp.ClientResponse object, but got r   r   r   Nr   r   r   r   r   T)max_line_lengthutf-8)r   rv   r   has_aiohttpaiohttpClientResponser   r   r'   aiter_linesrz   rY   r   r   aclosecontentreadlineREAD_BUFFER_SIZEdecoderstriprelease)	r   is_valid_responser   r   r   rv   r   r   
line_bytesr+   r+   r,   r     s   


"




(z#HttpResponse._aiter_response_streamresponsec              
   C   s:   zt |W S  t jy } z	td| |d}~ww )zFLoads JSON from the response, or raises an error if the parsing fails.z0Failed to parse response as JSON. Raw response: N)r   loadsJSONDecodeErrorr   UnknownApiResponseError)clsr   er+   r+   r,   r     s   z%HttpResponse._load_json_from_response)NN)r-   r   )r'   r(   r)   r
   rq   rP   httpxHeadersr   rt   r   r   r   propertyr   r   r   r   r   r   rs   r   r   r   r   classmethodr   r+   r+   r+   r,   r     s8    



	

! 7lr      g      ?g      N@)i  i  i  i  i  i  c                    s   | du rt dddS | jdkrd| _t | jpt}| jp t t  fdd}t j| jp0t	| j
p4t| jp8t| jp<td}||d|t ttjd	S )
a  Returns the retry args for the given http retry options.

  Args:
    options: The http retry options to use for the retry configuration. If None,
      the 'never retry' stop strategy will be used.

  Returns:
    The arguments passed to the tenacity.(Async)Retrying constructor.
  Nr   T)stopreraiser   c                    s    t | tjr| j v pt | tS r   )r   r   APIErrorcode_HTTPX_TRANSIENT_EXC)r   retriable_codesr+   r,   <lambda>C  s    
zretry_args.<locals>.<lambda>)initialmaxexp_basejitter)r   retryr   waitbefore_sleep)tenacitystop_after_attemptattempts_RETRY_ATTEMPTShttp_status_codes_RETRY_HTTP_STATUS_CODESretry_if_exceptionwait_exponential_jitterinitial_delay_RETRY_INITIAL_DELAY	max_delay_RETRY_MAX_DELAYr   _RETRY_EXP_BASEr   _RETRY_JITTERbefore_sleep_logr3   loggingINFO)rA   r   r   r   r+   r   r,   
retry_args2  s*   



r   c                       4   e Zd ZdZdeddf fddZd	ddZ  ZS )
SyncHttpxClientzSync httpx client.kwargsr-   Nc                    "   | dd t jdi | dS zInitializes the httpx client.follow_redirectsTNr+   
setdefaultsuperr   r   r   	__class__r+   r,   r   X     zSyncHttpxClient.__init__c                 C   sH   z| j rW dS W n	 ty   Y nw z|   W dS  ty#   Y dS w )zCloses the httpx client.N)	is_closed	Exceptioncloser   r+   r+   r,   __del__]  s   zSyncHttpxClient.__del__r-   Nr'   r(   r)   r*   r   r   r  __classcell__r+   r+   r   r,   r   U      r   c                       r   )
AsyncHttpxClientzAsync httpx client.r   r-   Nc                    r   r   r   r   r   r+   r,   r   m  r   zAsyncHttpxClient.__init__c                 C   sR   z| j rW d S W n	 ty   Y nw zt |   W d S  ty(   Y d S w r   )r   r   asyncioget_running_loopcreate_taskr   r   r+   r+   r,   r  r  s   zAsyncHttpxClient.__del__r  r  r+   r+   r   r,   r  j  r  r  c                   @   sl  e Zd ZU dZdZee ed< dZee	 ed< 						dfdee dee	 dee
jjj dee	 dee	 d	ee fd
dZdefddZdefddZdedefddZedee fddZdefddZe	dgdededeejejf fddZe	dgdededejfddZe	dgdededejfddZdefd d!Zde	fd"d#Z de	fd$d%Z!de"j#fd&d'Z$de%e	ef fd(d)Z&	dhd*e	d+e	d,e'e	e(f d	ee de)f
d-d.Z*	dgd/e)d0ede+fd1d2Z,		did/e)d	ee d0ede+fd3d4Z-	dgd/e)d0ede+fd5d6Z.		did/e)d	ee d0ede+fd7d8Z/dejfd9d:Z0	dhd*e	d+e	d,e'e	e(f d	ee de1f
d;d<Z2	dhd*e	d+e	d,e'e	e(f d	ee de3e1ddf f
d=d>Z4	dhd*e	d+e	d,e'e	e(f d	ee de1f
d?d@Z5	dhd*e	d+e	d,e'e	e(f d	ee def
dAdBZ6ddCdDe%e	e7j8f dEe	dFe9d	ee de+f
dGdHZ:ddCdIe7j8dEe	dFe9d	ee de+f
dJdKZ;e<dddLdMd+e	d	ee dNddOe9de=f
dPdQZ>e<ddLdRd+e	d	ee dNe%e	e?j@e	 e7j8f dOe9ddf
dSdQZ>dddLdMd+e	d	ee dNee%e	e?j@e	 e7j8f  dOe9dee= f
dTdQZ>ddCdDe%e	e7j8f dEe	dFe9d	ee de+f
dUdVZAddCdIe%e7j8eBjCe f dEe	dFe9d	ee de+f
dWdXZDe<dddLdMd+e	d	ee dNddOe9de=f
dYdZZEe<ddLdRd+e	d	ee dNe%e	e?j@e	 e7j8f dOe9ddf
d[dZZEdddLdMd+e	d	ee dNee%e	e?j@e	 e7j8f  dOe9dee= f
d\dZZEd]ejFddfd^d_ZGdjd`daZHdjdbdcZIdjdddeZJdS )kBaseApiClientz8Client for calling HTTP APIs sending and receiving JSON.Nvertexaicustom_base_urlapi_keyrd   r^   locationhttp_optionsc              
   C   s  || _ d | _| j d u rQtjdd }tjdd }d }	|d ur%| dv }	d }
|d ur1| dv }
|	d urB|
d urB|	|
krBtd |	d urJ|	| _ n|
d urQ|
| _ |sU|r\| j s\td|rd|rdtdt	 }t
|trzt	|}W n ty } ztd|d }~ww |rt|t	r|}|jr|jstdtjd	d }tjd
d }t }|p|| _|p|| _|p|| _|| _t	 | _t | _i | _| j r|r|rtd d | _nD|r|s|s|s|rtd d | _d | _n.|s|r|s|rtd d | _n|s|s|s|s|r|rtd d | _|jr$|jnd | _| jsA| jsA| js7d| _n
| jdrAd| _| js\| js\| js\td d\}| _| js\|| _| jrd| jpf| j}|sr| jsrtd| jrz| jr| jdkr| jsd| j_n=| jt v r| jsd| j d| j_n)| jr| jds|r|s|s| j| j_d | _d | _n	d| j d| j_d| j_!n| jstdd| j_d| j_!ddi| j_"| jr| j# | _| jj"d ur| j| jj"d< |rt$| j|| _n| jj"d urt%| jj" | j&| jt'| j d\}}|| _(d | _)| * r-d | _+n| jj,r8| jj,| _+nt-d'i || _+| . rId | _/n| jj0rT| jj0| _/nt1d'i || _/| jj0rg| jj0| _/nt1d'i || _/i | _2| 3 rz5d d l4}| j5| jt'| j d| _6| . rd!| j6d"< | jj7d u rt8d#nt8| jj7| j6d$< d%| j6d&< W n
 t9y   Y nw t:| jj;}| j<| jt'| j d| _=t>j?d'i || _@t>jAd'i || _Bd S )(NGOOGLE_GENAI_USE_ENTERPRISEGOOGLE_GENAI_USE_VERTEXAI)true1zWarning: Both GOOGLE_GENAI_USE_ENTERPRISE and GOOGLE_GENAI_USE_VERTEXAI are set with conflicting values. The value of GOOGLE_GENAI_USE_ENTERPRISE will be used.z-Gemini API does not support project/location.zICredentials and API key are mutually exclusive in the client initializer.zInvalid http_optionsz9base_url must be set when base_url_resource_scope is set.GOOGLE_CLOUD_PROJECTGOOGLE_CLOUD_LOCATIONzoThe user provided Google Cloud credentials will take precedence over the API key from the environment variable.zrThe user provided Vertex AI API key will take precedence over the project/location from the environment variables.zqThe user provided project/location will take precedence over the Vertex AI API key from the environment variable.zyThe project/location from the environment variables will take precedence over the API key from the environment variables.globalz.googleapis.comr^   z<Project or API key must be set when using the Vertex AI API.z"https://aiplatform.googleapis.com/zhttps://aiplatform.z.rep.googleapis.com/zhttps://z-aiplatform.googleapis.com/v1beta1zNo API key was provided. Please pass a valid API key. Learn how to create an API key at https://ai.google.dev/gemini-api/docs/api-key.z*https://generativelanguage.googleapis.com/v1betazContent-Typezapplication/jsonzx-goog-api-keyr  r   Tsslinfmax_allowed_timer   total_attemptsr+   )Cr  r  r0   r1   r2   lowerwarningswarnrc   r   r   rq   model_validater   r   is_duck_type_ofbase_url_resource_scoperT   r7   r^   r  r  _credentials_http_options	threadingLock_sync_auth_lock_async_auth_locksr3   inforX   rf   _MULTI_REGIONAL_LOCATIONSapi_versionr8   striprN   r@   _ensure_httpx_ssl_ctxbool_async_httpx_client_args_authorized_session_use_google_auth_sync_httpx_clienthttpx_clientr   _use_google_auth_async_async_httpx_clienthttpx_async_clientr  _aiohttp_sessions_use_aiohttpr   _ensure_aiohttp_ssl_ctx"_async_client_session_request_argsrk   ru   ImportErrorr   retry_options_ensure_websocket_ssl_ctx_websocket_ssl_ctxr   Retrying_retryAsyncRetrying_async_retry)r   r  r  rd   r^   r  r  env_enterprise_strenv_vertexai_strenv_enterpriseenv_vertexaivalidated_http_optionsr   env_projectenv_locationenv_api_keyhas_sufficient_authclient_argsasync_client_argsr   retry_kwargsr+   r+   r,   r     s  	





















zBaseApiClient.__init__r-   c                 C   s:   t tdsdS t| jot ot o| jjp| jj S )Nshould_use_client_certF)	hasattrr   r0  r  rQ  has_default_client_cert_sourcer&  r5  rN  r   r+   r+   r,   r3    s   
z#BaseApiClient._use_google_auth_syncc              	   C   sr   zdd l }|d}|j}d}W n ttfy   d}Y nw tto7|o7| jo7tt	do7t	
 o7t	 o7| jj S )Nr   google.auth.aio.credentialsTFrQ  )	importlibimport_moduler   r=  AttributeErrorr0  r   r  rR  r   rQ  rS  r&  r8  )r   rU  aio_creds_module_has_google_auth_aior+   r+   r,   r6    s,   
z$BaseApiClient._use_google_auth_asyncsessionc                 C   s:   t |dr
t|jS t |drt |jdrt|jjS dS )z&Returns True if the session is closed.closed_auth_request_closedF)rR  r0  r\  r]  r^  )r   r[  r+   r+   r,   _is_session_closed  s   

z BaseApiClient._is_session_closedc                 C   s<   | j jr| j jS zt }| j|W S  ty   Y dS w )zUReturns the aiohttp client session for the current loop (for backward compatibility).N)r&  aiohttp_clientr  r  r9  r2   RuntimeErrorr   loopr+   r+   r,   _aiohttp_session  s   zBaseApiClient._aiohttp_sessionc           	         s8  | j jr	| j jS t }| j | j|}|dur"| |r"d}W d   n1 s,w   Y  |du r|  rcz ddl	}|
dj}|
dj}G dd d|}||| }W n% tyb   Y nw G dd dtj}G d	d
 d
tj}||dddtd}|r| j || j|< W d   |S 1 sw   Y  |S )z#Returns the aiohttp client session.Nr   rT  z"google.auth.aio.transport.sessionsc                
       sZ   e Zd ZdZd fddZdededed	eeef d
df
ddZe	d
e
fddZ  ZS )zHBaseApiClient._get_aiohttp_session.<locals>._RefreshableAsyncCredentialszJAdapter to use the client's sync credentials in an AsyncAuthorizedSession.clientr
  c                    s   t    || _d S r   )r   r   _client)r   re  r   r+   r,   r     s   

zQBaseApiClient._get_aiohttp_session.<locals>._RefreshableAsyncCredentials.__init__requestro   rn   r8   r-   Nc                    sL   | j  I d H }d| |d< | j jr"| j jjr$| j jj|d< d S d S d S )NBearer Authorizationx-goog-user-project)rf  _async_access_tokenr%  quota_project_id)r   rg  ro   rn   r8   tokenr+   r+   r,   before_request  s   
zWBaseApiClient._get_aiohttp_session.<locals>._RefreshableAsyncCredentials.before_requestc                 S   s   | j jsdS | j jj S NF)rf  r%  expiredr   r+   r+   r,   valid  s   zNBaseApiClient._get_aiohttp_session.<locals>._RefreshableAsyncCredentials.valid)re  r
  )r'   r(   r)   r*   r   r   rP   rq   rn  r   r0  rq  r  r+   r+   r   r,   _RefreshableAsyncCredentials  s     

rr  c                   @   "   e Zd ZefdeddfddZdS )z@BaseApiClient._get_aiohttp_session.<locals>.AiohttpClientSession	_warningsr-   Nc                 S   s0   | j s| dd}| jd ur| j|d< d S d S d S )NzUnclosed client session)client_sessionmessagesource_traceback)r\  _source_traceback)r   rt  contextr+   r+   r,   r    s   
zHBaseApiClient._get_aiohttp_session.<locals>.AiohttpClientSession.__del__r'   r(   r)   r   r   r  r+   r+   r+   r,   AiohttpClientSession      r{  c                   @   rs  )z?BaseApiClient._get_aiohttp_session.<locals>.AiohttpTCPConnectorrt  r-   Nc                 S   sX   | j rd S | js
d S dd | j D }|   | |dd}| jd ur*| j|d< d S d S )Nc                 S   s   g | ]}t |qS r+   )repr)r}   r   r+   r+   r,   
<listcomp>  s    z[BaseApiClient._get_aiohttp_session.<locals>.AiohttpTCPConnector.__del__.<locals>.<listcomp>zUnclosed connector)	connectorconnectionsrv  rw  )r^  _connsvalues_closerx  )r   rt  connsry  r+   r+   r,   r    s   
zGBaseApiClient._get_aiohttp_session.<locals>.AiohttpTCPConnector.__del__rz  r+   r+   r+   r,   AiohttpTCPConnector  r|  r  )limitT)r  	trust_envread_bufsize)r&  r`  r  r  r)  r9  r2   r_  r6  rU  rV  r   AsyncAuthorizedSessionr=  r   ClientSessionTCPConnectorr   )	r   rc  r[  rU  AsyncCredentialsr  rr  r{  r  r+   r+   r,   _get_aiohttp_session  sF   
z"BaseApiClient._get_aiohttp_sessionFrA   c              
      s   d | j }| j}|r| n|r| nd}|du r\|rFttdd}|durFz| }W n tyE } ztd| W Y d}~nd}~ww |du r\tj	t
jdt t
jdd}dttj d	tjd
tjf fdd}||||||fS )a,  Ensures the SSL context is present in the HTTPX client args.

    Creates a default SSL context if one is not provided.

    Args:
      options: The http options to check for SSL context.
      vertexai: Whether Vertex AI is enabled.

    Returns:
      A tuple of sync/async httpx client args.
    verifyNget_default_ssl_context6Failed to get default SSL context from google-auth: %sSSL_CERT_FILESSL_CERT_DIRcafilecapathargsctxr-   c                    sb   | pi   } |  s||  < d| vrd| d< |   }|  D ]}|ttjjjvr.||= q|S )-  Sets the SSL context in the client args if not set.

      Does not override the SSL context if it is already set.

      Args:
        args: The client args to to check for SSL context.
        ctx: The SSL context to set.

      Returns:
        The client args with the SSL context included.
      rk   N)r   r2   inspect	signaturer   Clientr   
parametersr  r  copied_argsrL   r  r+   r,   
_maybe_set\  s   
z7BaseApiClient._ensure_httpx_ssl_ctx.<locals>._maybe_set)rN  rO  r2   rF   r   r   r3   r4   r  create_default_contextr0   r1   certifiwherer   r   
StringDict
SSLContext)rA   r  r  
async_argsr  
get_ctx_fnr   r  r+   r  r,   r/  -  sD   

z#BaseApiClient._ensure_httpx_ssl_ctxc              
         d | j }|r| nd}|du rR|r<ttdd}|dur<z| }W n ty; } ztd| W Y d}~nd}~ww |du rRtjt	j
dt t	j
dd}dttj d	tjd
tjf fdd}|||S )1  Ensures the SSL context is present in the async client args.

    Creates a default SSL context if one is not provided.

    Args:
      options: The http options to check for SSL context.
      vertexai: Whether Vertex AI is enabled.

    Returns:
      An async aiohttp ClientSession._request args.
    r  Nr  r  r  r  r  r  r  r-   c                    sV   | r|   s| p
i  } ||  < |  }| D ]}|ttjjjvr(||= q|S )r  )r2   r   r  r  r   r  _requestr  r  r  r+   r,   r    s   z9BaseApiClient._ensure_aiohttp_ssl_ctx.<locals>._maybe_setrO  r2   rF   r   r   r3   r4   r  r  r0   r1   r  r  r   r   r  r  rA   r  r  r  r  r   r  r+   r  r,   r;  |  s4   


z%BaseApiClient._ensure_aiohttp_ssl_ctxc              
      r  )r  r  Nr  r  r  r  r  r  r  r-   c                    sZ   | r|   s| p
i  } ||  < |  }| D ]}|ttjvr*|dkr*||= q|S )r  r  )r2   r   r  r  
ws_connectr  r  r  r+   r,   r    s   z;BaseApiClient._ensure_websocket_ssl_ctx.<locals>._maybe_setr  r  r+   r  r,   r?    s4   


z'BaseApiClient._ensure_websocket_ssl_ctxc                 C   s&   t o| jjpi dd u o| jjd u S )N	transport)r   r&  rO  r2   r8  r   r+   r+   r,   r:    s   
zBaseApiClient._use_aiohttpc                 C   s>   | j r| jp| j}| jr|s| jS t| jj}|jdd S )Nwss)scheme)	r^   r  r  r  r   r&  rT   rZ   geturl)r   rM  	url_partsr+   r+   r,   _websocket_base_url  s
   
z!BaseApiClient._websocket_base_urlc                 C   sh   | j ' | jst| jd\| _}| js|| _| jr&t| | jW  d   S td1 s-w   Y  dS )z/Retrieves the access token for the credentials.r  N0Could not resolve API token from the environment)r)  r%  rf   r^   get_token_from_credentialsra  )r   r^   r+   r+   r,   _access_token  s   
	zBaseApiClient._access_tokenc                    sV   t  }| j || jvrt  | j|< | j| W  d   S 1 s$w   Y  dS )a  Lazily initializes and returns an asyncio.Lock for async authentication.

    This method ensures that a single `asyncio.Lock` instance is created and
    shared among all asynchronous operations that require authentication
    within the same event loop.
    N)r  r  r)  r*  r(  rb  r+   r+   r,   _get_async_auth_lock!  s   
$z"BaseApiClient._get_async_auth_lockc              	      s   | j s>|  I dH }|4 I dH " | j s)tjt| jdI dH \| _ }| js)|| _W d  I dH  n1 I dH s9w   Y  | j rJt| | j I dH S td)z>Retrieves the access token for the credentials asynchronously.Nr  r  )r%  r  r  	to_threadrf   r^    async_get_token_from_credentialsra  )r   async_auth_lockr^   r+   r+   r,   rk  .  s"   (
z!BaseApiClient._async_access_tokenhttp_methodrU   request_dictc                 C   s  dd |  D }|D ]}||= q|r)t|trt| j|}nt| jt|}n| j}d}| jr<|dkr<|dr<d}| jrb|dsb|sb| jsL| j	rb| j
rU|jtjksbd| j d| j	 d	| }|jd u rmd	| }	n|j d	| }	|jd u s}|jstd
|j}
t|dr|jrt||j |
}| j
r| jr| j	s| jr|jtjkrt|
|}nt|
|	}n| j
r|jtjkrt|
|}| jr| jdrtdt|j}|jd u rtdt|j| t|||j||dS )Nc                 S   s   g | ]	}| d r|qS )rY  )rY   r|   r+   r+   r,   r~  M  s    z0BaseApiClient._build_request.<locals>.<listcomp>Fr2   zpublishers/Tz	projects/z/locations/rV   zBase URL must be set.
extra_bodyzauth_tokens/z4Ephemeral tokens can only be used with the live API.zRequest headers must be set.ro   rn   r8   rp   rk   )rE   r   r   rN   r&  r"  r  rY   r^   r  r  r$  r   
COLLECTIONr-  rT   rc   rR  r  r   recursive_dict_updater  r]   r&   rl   rk   r8   rS   rm   )r   r  rU   r  r  keys_to_deleterL   patched_http_optionsquery_vertex_base_modelsversioned_pathrT   rn   rO   r+   r+   r,   _build_requestE  s   





zBaseApiClient._build_requesthttp_requeststreamc           	      C   s  d }| j r2| js| jr2| js2d|   |jd< | jr&| jjr&| jj|jd< |jr/t	
|jnd }n|jrJt|jtsG|jrDt	
|jnd }n|j}|  rt|j}| jd u rpddlm} || jdd| _t }| j| | jjrd|v rd	|v r|d
d}n|dd}| jj|j |||j|j|d}n| jj|j|j||j|jd}| jj||d}tj !| t"|j|r|S |j#gS )Nrh  ri  rj  r   r   r   max_refresh_attemptsgoogleapis.comsandboxsandbox.googleapis.commtls.sandbox.googleapis.commtls.googleapis.comro   rn   rp   r8   rk   r  ro   rn   r   r8   rk   r  )$r  r^   r  r  r  r8   r%  rl  rp   r   dumpsr   rt   r3  rP   rn   r2  rh   r   r   default_client_cert_sourceconfigure_mtls_channel_is_mtlsreplacerg  ro   upperrk   r4  build_requestsendr   r   raise_for_responser   text)	r   r  r  rp   rn   r   client_cert_sourcer   httpx_requestr+   r+   r,   _request_once  sf   

	
zBaseApiClient._request_oncec                 C   s^   |r't |trtdi |n|}|jr't|j}tjdi |}|| j||S | | j||S Nr+   )	r   rq   r   r>  r   r   rA  r  rB  r   r  r  r  parameter_modelrP  r   r+   r+   r,   r    s   
zBaseApiClient._requestc                    s  d }| j r*| js| jr*| js*d|  I d H  |jd< | jr*| jjr*| jj|jd< |jr@t	|jt
s=t|jd}n|j}|r4|  r|  I d H }|j}|  rzt }||I d H  |jrzd|v rzd|v rt|dd}n|dd	}z|jd|j||j|tj|jd
d| jI d H }W n] tjtjtjtj t!j"fy } zGt#$dt%&dd I d H  t'(d|  | j)| j*t+| j d| _|  I d H }|jd|j||j|tj|jd
d| jI d H }W Y d }~nd }~ww t,j-.|I d H  t/|dr|j0}t1|j|S | j2j3|j|j||j|jd}	| j2j4|	|dI d H }
t,j-.|
I d H  t1|
j|
S |  r(|  I d H }|j}|  rot }||I d H  |jrod|v rod|v ri|dd}n|dd	}z:|jd|j||j|tj|jd
d| jI d H }t,j-.|I d H  |}t/|dr|j0}t1|j|5 I d H gW S  tjtjtjtj t!j"fy' } zgt#$dt%&dd I d H  t'(d|  | j)| j*t+| j d| _|  I d H }|jd|j||j|tj|jd
d| jI d H }t,j-.|I d H  |}t/|dr|j0}t1|j|5 I d H gW  Y d }~S d }~ww | j2j|j|j|j||jdI d H }
t,j-.|
I d H  t1|
j|
j5gS )Nrh  ri  rj  r   r  r  r  r  r  totalr  r   r   	   z!Retrying due to aiohttp error: %sr  	_responser  r  ro   rn   r8   r   rk   r+   )6r  r^   r  r  rk  r8   r%  rl  rp   r   rt   r   r  encoder:  r  rn   r6  r   r  r  r  r  rg  ro   r   ClientTimeoutrk   r<  ClientConnectorErrorClientConnectorDNSErrorClientOSErrorServerDisconnectedErrorauth_exceptionsTransportErrorr  sleeprandomrandintr3   r+  r;  r&  r0  r   r   raise_for_async_responserR  r  r   r7  r  r  r  )r   r  r  rp   r[  rn   r  r   r   r  client_responseunwrapped_responseunwrapped_retry_responser+   r+   r,   _async_request_once  s4  





%z!BaseApiClient._async_request_oncec                    sl   |r+t |trtdi |n|}|jr+t|j}tjdi |}|| j||I d H S | | j||I d H S r  )	r   rq   r   r>  r   r   rC  r  rD  r  r+   r+   r,   _async_request  s   

zBaseApiClient._async_requestc                 C   s$   t | jtr| j }|S | j}|S r   )r   r&  r   
model_dump)r   copiedr+   r+   r,   get_read_only_http_options  s
   
z(BaseApiClient.get_read_only_http_optionsc                 C   sB   |  ||||}| j||dd}|jr|jd nd}t|j|dS )NFr  r   r   r8   body)r  r  rv   SdkHttpResponser8   )r   r  rU   r  r  r  r   response_bodyr+   r+   r,   rg    s   zBaseApiClient.requestc           
   	   c   s    |  ||||}| j||dd}| D ]=}t|}z|dr6t|}	tj	|	
di 
d|	| W n tjjyI   td|  Y nw t|j|dV  qd S )NTr  	{"error":errorr   1Failed to decode chunk that contains an error: %sr  )r  r  r   r   r  rY   r   r   r   raise_errorr2   decoderr   r3   debugr  r8   )
r   r  rU   r  r  r  session_responser   
chunk_dump
chunk_jsonr+   r+   r,   request_streamed  s0   


zBaseApiClient.request_streamedc                    sJ   |  ||||}| j||ddI d H }|jr|jd nd}t|j|dS )NFr  r  r  r   r   r  )r  r  rv   r  r8   )r   r  rU   r  r  r  resultr  r+   r+   r,   async_request  s   zBaseApiClient.async_requestc                    s:   |  ||||}| j||ddI d H   fdd}| S )NTr	  c               	     s    2 zD3 d H W } t | }z|dr+t |}tj|di d| I d H  W n t jj	y>   t
d|  Y nw t j|dV  q6 d S )Nr  r   r   r  r  )r   r  rY   r   r   r   raise_error_asyncr2   r  r   r3   r  r  r8   )r   r  r  r   r+   r,   async_generator  s(   



z=BaseApiClient.async_request_streamed.<locals>.async_generator)r  r  )r   r  rU   r  r  r  r  r+   r  r,   async_request_streamed
  s   z$BaseApiClient.async_request_streamedr  	file_path
upload_urlupload_sizec                C   s^   t |tjr| j||||dS t|d}| j||||dW  d   S 1 s(w   Y  dS )a%  Transfers a file to the given URL.

    Args:
      file_path: The full path to the file or a file like object inherited from
        io.BytesIO. If the local file path is not found, an error will be
        raised.
      upload_url: The URL to upload the file to.
      upload_size: The size of file content to be uploaded, this will have to
        match the size requested in the resumable upload request.
      http_options: The http options to use for the request.

    returns:
          The HttpResponse object from the finalize request.
    r  rbN)r   ioIOBase
_upload_fdopen)r   r  r  r  r  filer+   r+   r,   upload_file-  s   $zBaseApiClient.upload_filer  c                C   s  d}|r|n| j }t|tr|dnt|dd}|r.t|}t|}t|j|j|j	d}	 |
t}	d}
|	r<t|	}
d}|
| |krH|d7 }t|trR|dn|j}|du rgt| j trc| j jn| j j}t|}t|trv|d	i nt|d	i p}i }|rt|ni }||t|t|
d
 t|| d}|tk r| jjd|||	|d}|jdrntt|  }|d7 }t| |tk s||
7 }|jddkrn	||krtdq/tj| |jddkrtdt|j|jgdS )a  Transfers a file to the given URL.

    Args:
      file: A file like object inherited from io.BytesIO.
      upload_url: The URL to upload the file to.
      upload_size: The size of file content to be uploaded, this will have to
        match the size requested in the resumable upload request.
      http_options: The http options to use for the request.

    returns:
          The HttpResponse object from the finalize request.
    r   rT   Nr  netlocTupload
, finalizerk   r8   zX-Goog-Upload-CommandzX-Goog-Upload-OffsetzContent-LengthPOSTr  x-goog-upload-statusr   activeFAll content has been uploaded, but the upload status is not finalized.final6Failed to upload file: Upload status is not finalized.rv   ) r&  r   rq   r2   rF   r   r   rZ   r  r  read
CHUNK_SIZEr   rk   rl   updaterP   rS   MAX_RETRY_COUNTr4  rg  r8   INITIAL_RETRY_DELAYDELAY_MULTIPLIERtimer  rc   r   r   r  r   r  )r   r  r  r  r  offsetrT   r[   parsed_upload
file_chunk
chunk_sizeupload_commandrk   rO   user_headersupload_headersretry_countr   delay_secondsr+   r+   r,   r  M  s   





9zBaseApiClient._upload_fdi   )r  destinationr1  r7  r1  c                C      d S r   r+   r   rU   r  r7  r1  r+   r+   r,   download_file     	zBaseApiClient.download_file)r  r1  c                C   r8  r   r+   r9  r+   r+   r,   r:    r;  c                   sH   durt  ttjfst dstdt  d| jd|i |d}d}|jr9t |jt	s6t
|j}n|j}dtt	 ddf fd	d
}|  rt|j}| jdu rlddlm}	 |	| jdd| _t }
| j|
 | jjrd|v rd|v r|dd}n|dd} dur| jj|j |||j|jdd}ztj| ||j |d W |!  dS |!  w | jj|j |||j|jd}tj| t"t	|j#S  dur| j$j%|j|j||j|jd}| j$j&|dd}ztj| ||j'|d W |!  dS |!  w | j$j|j|j||j|jd}tj| t"t	|( S )aU  Downloads the file data.

    Args:
      path: The request path with query params.
      http_options: The http options to use for the request.
      destination: Optional local file path or writable stream.
      chunk_size: The chunk size in bytes to stream.

    Returns:
      The file bytes if destination is None, otherwise None.
    NwriteUnsupported destination type: <. Expected str, os.PathLike, or a writable file-like object.r2   rU   r  r  chunksr-   c                    s   t  ttjfr*t d}| D ]}|| qW d    d S 1 s#w   Y  d S  d ur=t dr?| D ]} | q5d S d S d S Nwbr<  )r   rP   r0   PathLiker  r<  rR  )r@  fr   r7  r+   r,   _write_chunks  s   "z2BaseApiClient.download_file.<locals>._write_chunksr   r   r   r  r  r  r  r  r  Tr  r1  ro   rn   rp   r8   rk   r  r  ))r   rP   r0   rC  rR  rc   r   r  rp   rt   r   r  r   r3  rn   r2  rh   r   r%  r   r  r  r  r  rg  ro   r  r8   rk   r   r   r  iter_contentr   r   r   r4  r  r  
iter_bytesr'  )r   rU   r  r7  r1  r  rp   rF  rn   r   r  r   r  r+   rE  r,   r:    s   

	




c             	      s   t |tjr| j||||dI dH S t|}|dI dH }|4 I dH  | j||||dI dH W  d  I dH  S 1 I dH sCw   Y  dS )a  Transfers a file asynchronously to the given URL.

    Args:
      file_path: The full path to the file. If the local file path is not found,
        an error will be raised.
      upload_url: The URL to upload the file to.
      upload_size: The size of file content to be uploaded, this will have to
        match the size requested in the resumable upload request.
      http_options: The http options to use for the request.

    returns:
          The HttpResponse object from the finalize request.
    r  Nr  )r   r  r  _async_upload_fdanyioPathr  )r   r  r  r  r  r  fdr+   r+   r,   async_upload_file=  s   

0zBaseApiClient.async_upload_filec                   sZ  d}|r|n| j }t|tr|dnt|dd}|r/t|}t|}t|j|j|j	d}| 
 r-|  I dH }		 t|tjrH|t}
n|tI dH }
d}|
rXt|
}d}|| |krd|d7 }t|trn|dn|j}|du rt| j tr| j jn| j j}t|}t|tr|d	i nt|d	i pi }|rt|ni }||t|t|d
 t|| d}d}|tk r|	jd||
|tj|ddI dH }|jdrntt|  }|d7 }t|I dH  |tk s||7 }|dur|jddkrn
||krtdq<t j!"|I dH  |dur |jddkr tdt#|j|$ I dH gdS 	 t|tjr;|t}
n|tI dH }
d}|
rLt|
}d}|| |krY|d7 }t|trd|dn|j}|du r{t| j trw| j jn| j j}t|}t|tr|d	i nt|d	i pi }|rt|ni }||t|t|d
 t|| d}d}|tk r| j%jd||
||dI dH }|dur|jr|jdrntt|  }|d7 }t&| |tk s||7 }|dur|jddkrn||krtdq.t j!"|I dH  |dur$|jddkr$tdt#|j|j$gdS )a  Transfers a file asynchronously to the given URL.

    Args:
      file: A file like object inherited from io.BytesIO.
      upload_url: The URL to upload the file to.
      upload_size: The size of file content to be uploaded, this will have to
        match the size requested in the resumable upload request.
      http_options: The http options to use for the request.

    returns:
          The HttpResponse object from the finalized request.
    r   rT   Nr  Tr  r  rk   r8   r  r   r  rH  zX-Goog-Upload-Statusr   r"  r#  r$  r%  r&  r  r!  )'r&  r   rq   r2   rF   r   r   rZ   r  r  r:  r  r  r  r'  r(  r   rk   rl   r)  rP   rS   r*  rg  r   r  r8   r+  r,  r  r  rc   r   r   r  r   r  r7  r-  )r   r  r  r  r  r.  rT   r[   r/  r[  r0  r1  r2  rk   rO   r3  r4  r5  r   r6  r  r+   r+   r,   rK  ^  s.  






D










G

zBaseApiClient._async_upload_fdc                      d S r   r+   r9  r+   r+   r,   async_download_file)	     	z!BaseApiClient.async_download_filec                   rP  r   r+   r9  r+   r+   r,   rQ  4	  rR  c             	      s   durt  ttjfst dstdt  d| jd|i |d}d}|jr=t |jt	s:t
|jd}n|j}dtt	 d	df fd
d}|  r|  I dH }|j}	|  rt }
||
I dH  |jrd|	v rd|	v rz|	dd}	n|	dd}	|jd|j|	|j|tj|jdd| jI dH } durz&tj |I dH  t|dr|j!}n|}||j"#|I dH  W |$  dS |$  w ztj |I dH  t%t	|& I dH W |$  S |$  w  dur-| j'j(|j|j||j|jd}| j'j)|ddI dH }ztj |I dH  ||j*|dI dH  W |+ I dH  dS |+ I dH  w | j'j|j|j|j||jdI dH }tj |I dH  t%t	|& S )ad  Downloads the file data asynchronously.

    Args:
      path: The request path with query params.
      http_options: The http options to use for the request.
      destination: Optional local file path or writable stream.
      chunk_size: The chunk size in bytes to stream.

    Returns:
      The file bytes if destination is None, otherwise None.
    Nr<  r=  r>  r2   r?  r   r@  r-   c                    s   t  ttjfr0t d}| 2 z3 d H W }|| q6 W d    d S 1 s)w   Y  d S  d urTt drV| 2 z3 d H W } |}t|rP|I d H  q;6 d S d S d S rA  )	r   rP   r0   rC  r  r<  rR  r  isawaitable)r@  rD  r   resrE  r+   r,   rF  e	  s   "


z8BaseApiClient.async_download_file.<locals>._write_chunksr  r  r  r  r  r  r  r  r  Tr  rG  r  r+   ),r   rP   r0   rC  rR  rc   r   r  rp   rt   r   r  r  r   r:  r  rn   r6  r   r  r  r  r  rg  ro   r8   r   r  rk   r<  r   r   r  r  r   iter_chunkedr   r   r'  r7  r  r  aiter_bytesr   )r   rU   r  r7  r1  r  rp   rF  r[  rn   r  r   raw_responser  r  r+   rE  r,   rQ  ?	  s   






response_modelc                 C   r8  r   r+   )r   rX  r+   r+   r,   _verify_response	  s   zBaseApiClient._verify_responsec                 C   s0   | j js| jr| j  | jr| j  dS dS )zCloses the API client.N)r&  r5  r4  r   r2  r   r+   r+   r,   r   	  s
   
zBaseApiClient.closec              	      s   | j js| j I dH  | jrV| j jsXzt }W n ty%   d}Y nw t	| j
 D ],\}}||kr=| I dH  q-| rUz
t| | W q- tyT   Y q-w q-dS dS dS )zCloses the API async client.N)r&  r8  r7  r   r9  r`  r  r  ra  r   r   r   
is_runningrun_coroutine_threadsafe)r   current_looprc  r[  r+   r+   r,   r   	  s*   zBaseApiClient.aclosec                 C   sV   z
| j js	|   W n	 ty   Y nw zt |   W dS  ty*   Y dS w )zCloses the API client when the object is garbage collected.

    ADK uses this client so cannot rely on the genai.[Async]Client.__del__
    for cleanup.
    N)r&  r5  r   r   r  r  r	  r   r   r+   r+   r,   r  	  s   zBaseApiClient.__del__)NNNNNN)Fr   ro  r  )Kr'   r(   r)   r*   r  r   r0  rr   r  rP   r`   ra   rd   r   r   r   r3  r6  r   r_  r   rd  r  staticmethodr   r	   r   r  r/  r;  r?  r:  r  r  r  r(  r  r
   rk  rq   rs   rm   r  r   r  r  r  r  r  r  rg  r   r  r  r  r  r  intr  r  r   rt   r:  r0   rC  rO  rL  	AsyncFilerK  rQ  r   rY  r   r   r  r+   r+   r+   r,   r
  ~  sd  
 
  
dN@C
	

n
B

 1




"



)
&
c

}
'
 L

}

	r
  re  c                 C   s(   |j s|js
t| |jstd|jS )=Refreshes the authentication token for the given credentials.r  )rp  rm  rj   ra  )re  rd   r+   r+   r,   r  	  s
   r  c              	      s   |j s|js9|  I dH }|4 I dH  |j s|js$tt|I dH  W d  I dH  n1 I dH s4w   Y  |js@td|jS )r`  Nr  )rp  rm  r  r  r  rj   ra  )re  rd   r  r+   r+   r,   r  	  s   (r  )xr*   r  collections.abcr   r   dataclassesr   r  r  r   r   rQ   r0   r  r  r;   r'  r-  typingr   r   r   r   r   r	   r
   r   r   urllib.parser   r   r   rL  r  google.authr`   google.auth.credentialsr   google.auth.transportr   r   r  r   pydanticr   r   r   r   r   r   r   typesr   r   r   r  r   r   websockets.asyncio.clientr   r  ModuleNotFoundErrorwebsockets.clientr   r   r=  httpx2rh   r   	multidictr    requests.structuresr!   	getLoggerr3   r(  r   r*  r+  r,  r,  r   r   r   r   TimeoutExceptionConnectErrorr   rc   r&   rP   r7   rq   r@   rN   ru   r^  rS   r]   rf   rj   rl   rm   r   r   r   r   r   r   r  r   r  r   AsyncClientr  r
  ra   rd   r  r  r+   r+   r+   r,   <module>   s(  ,

 


"
  
#               
