
    Li2^                     t   U d 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 ddlZddlZddlZddlmZ ddlmZ  ej.                  d      Zeee
f   Zeed<    G d d	e      Zd
eee
e
f      dee   de
ddfdZ ddd
e
dee   de
de
fdZ!d
e
deeef   ddfdZ"d
e
dee   dee   de#de$e   ddfdZ%dBdede&defdZ'dCde(de&de
fdZ)de*de&fd Z+d!e
d"eee(f   ddfd#Z, e	jZ                  d$d%&      Z.dd'd(d)d*dd+de
d,e#d-e#d.e#d/e#d0e#d1eee#      defd2Z/de
d,e#d-e#d.e#d/e#d0e#d1ee#   defd3Z0 G d4 d%ejb                        Z1 G d5 d6eejd                        Z3defd7Z4d
eee(f   deee(f   fd8Z5d9edeed:e
f   ged:e
f   f   fd;Z6d<edefd=Z7d>ed?edefd@Z8d>ed?eddfdAZ9y)DzCommon utilities for the SDK.    N)AnyCallable	FrozenSetOptionalUnionget_args
get_origin)alias_generators)	TypeAliaszgoogle_genai._common
StringDictc                       e Zd ZdZy)ExperimentalWarningz"Warning for experimental features.N)__name__
__module____qualname____doc__     R/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/google/genai/_common.pyr   r   &   s    *r   r   datakeysvaluereturnc           	         |yt        |dd       D ]  \  }}|j                  d      r|dd }| K|| vrGt        |t              r&t	        t        |            D cg c]  }i  c}| |<   nt        d| d|       t        |t              r0| .t        | |         D ]  \  }}t        |||dz   d ||            y| | |   D ]  }t        |||dz   d |         y|j                  d      r.|dd	 }| 
|| vri g| |<   | t        | |   d
   ||dz   d |        y| | j                  |i       } " | | j                  |d         }	|	S|sy||	k(  ryt        |	t              r"t        |t              r|	j                  |       yt        d|d    d|	 d| d      |d   dk(  r2t        | t              r"t        |t              r| j                  |       y|| |d   <   yyc c}w )a9  Examples:

  set_value_by_path({}, ['a', 'b'], v)
    -> {'a': {'b': v}}
  set_value_by_path({}, ['a', 'b[]', c], [v1, v2])
    -> {'a': {'b': [{'c': v1}, {'c': v2}]}}
  set_value_by_path({'a': {'b': [{'c': v1}, {'c': v2}]}}, ['a', 'b[]', 'd'], v3)
    -> {'a': {'b': [{'c': v1, 'd': v3}, {'c': v2, 'd': v3}]}}
  N[]zvalue z$ must be a list given an array path    [0]r   z+Cannot set value for an existing key. Key: z; Existing value: z; New value: ._self)	enumerateendswith
isinstancelistrangelen
ValueErrorset_value_by_path
setdefaultgetdictupdate)
r   r   r   ikeykey_name_jdexisting_datas
             r   r*   r*   *   sL    ]
$s)$ &fa
||DSbh		hd2eT"(-c%j(9:1B:$x.ugA#G  
E4	 T%5d8n- 	8DAq
AtAEG}eAh
7	8  > 7aaa!eg67	e	Sbh		hd2X		$x.+T!a%']EB__S"%d5&8 
HHT"X&M  M! mT*z%/FU#9$r( D  -mE7!E
 	
 r(g
t$%ET"X; / ;s   	G$default_valuer7   c          
         |dgk(  r| S t        |      D ]  \  }}| s|c S |j                  d      r4|dd }|| v r'| |   D cg c]  }t        |||dz   d |       c}c S |c S |j                  d      r.|dd }|| v r!| |   rt        | |   d	   ||dz   d |      c S |c S || v r| |   } t        | t              rt        | |      rt        | |      } |c S  | S c c}w )
zExamples:

  get_value_by_path({'a': {'b': v}}, ['a', 'b'])
    -> v
  get_value_by_path({'a': {'b': [{'c': v1}, {'c': v2}]}}, ['a', 'b[]', 'c'])
    -> [v1, v2]
  r"   r   Nr   r   r6   r   r    r   )r#   r$   get_value_by_pathr%   	BaseModelhasattrgetattr)r   r   r7   r/   r0   r1   r4   s          r   r9   r9   t   s#    
gYK$ fa
||DSbh	T	 (^
 aa!egmL
 	

 	e	Sbh	T	d8n N1tAEG}M
 	
 	CydI&74+=tS!56 
++
s   Cpathsc                    |j                         D ]  \  }}|j                  d      }|j                  d      }t               }d}t        |      D ]  \  }}	|	dk(  s|} n |dk7  rht	        |      |kD  rZt        |t	        |            D ]B  }||   }	|	dk7  s|	j                  d      r |	j                  d      r2|j                  |	       D t        | ||d|        y)a#  Moves values from source paths to destination paths.

  Examples:
    move_value_by_path(
      {'requests': [{'content': v1}, {'content': v2}]},
      {'requests[].*': 'requests[].request.*'}
    )
      -> {'requests': [{'request': {'content': v1}}, {'request': {'content':
      v2}}]}
  r!   r   *r   r   r   N)	itemssplitsetr#   r(   r'   r$   add_move_value_recursive)
r   r=   source_path	dest_pathsource_keys	dest_keysexclude_keyswildcard_idxr/   r0   s
             r   move_value_by_pathrK      s     !& Ik9##C(K$I 5LLK( 3	
 rc)n|; \3y>2  !l#:cll40e9L


3
  $Y<H-Ir   rG   rH   key_idxrI   c                    |t        |      k\  ry||   }|j                  d      r;|dd }|| v r1t        | |   t              r| |   D ]  }t	        ||||dz   |        yyy|dk(  rt        | t
              rt        | j                               D cg c]  }|j                  d      s||vr| }	}|	D ci c]  }|| |   
 }
}|
j                         D ]F  \  }}g }||d D ]*  }|dk(  r|j                  |       |j                  |       , t        | ||       H |	D ]  }| |=  yy|| v rt	        | |   |||dz   |       yyc c}w c c}w )z>Recursively moves values from source path to destination path.Nr   r   r   r?   r2   )r(   r$   r%   r&   rD   r-   r   
startswithr@   appendr*   )r   rG   rH   rL   rI   r0   r1   itemkkeys_to_movevalues_to_movevnew_dest_keysdks                 r   rD   rD      s    K  
G#\\$3BxH4JtH~t<x. 
$+y'A+|	

 =
 cz$ 		$c"q'< l  -99q47
9n9 !&&( 2$!QGH% 	%B3Y  #  $		%
 	$q12  !G/ 6 d{
s)[)Wq[, 3 :s   E5E		snake_strconvertc                 :    |s| S t        j                  dd |       S )z>Converts a snake_case string to CamelCase, if convert is True.z_([a-zA-Z])c                 @    | j                  d      j                         S )Nr   )groupupper)matchs    r   <lambda>z&maybe_snake_to_camel.<locals>.<lambda>   s    ekk!n.B.B.D r   )resub)rW   rX   s     r   maybe_snake_to_camelra      s    		 Di	PPr   objconvert_keysc                 j   t        | t        j                        rt        | j	                  d      |      S t        | t
              r7| j                         D ci c]  \  }}t        ||      t        |       c}}S t        | t              r| D cg c]  }t        ||       c}S | S c c}}w c c}w )a  Recursively converts a given object to a dictionary.

  If the object is a Pydantic model, it uses the model's `model_dump()` method.

  Args:
    obj: The object to convert.
    convert_keys: Whether to convert the keys from snake case to camel case.

  Returns:
    A dictionary representation of the object, a list of objects if a list is
    passed, or the object itself if it is not a dictionary, list, or Pydantic
    model.
  T)exclude_none)	r%   pydanticr:   convert_to_dict
model_dumpr-   r@   ra   r&   )rb   rc   r0   r   rP   s        r   rg   rg     s     X''(3>>t><lKK#t ))+C 	S,/1GG  #t<?@DOD,/@@J
 As    B*B0
annotationc                    t        |       }t        |       }|t        ury|rt        |      dk7  ry|d   }t        |      }t        |      }|t        ury|rt        |      dk7  ry|\  }}|t
        u xr |t        j                  u S )zChecks if the given annotation is list[dict[str, typing.Any]]

  or typing.List[typing.Dict[str, typing.Any]].

  This maps to Struct type in the API.
  Fr   r      )r	   r   r&   r(   r-   strtypingr   )ri   outer_origin
outer_argsinner_annotationinner_origin
inner_argskey_type
value_types           r   _is_struct_typeru     s     J',
#*	s:!+],-,()*	s:!+ $(J	S	5Z6::55r   modelresponsec                    t        |j                               }|D ]P  \  }}| j                  j                         D ci c]  \  }}|j                  | }}}| j                  vr||vr|j	                  |       b|j                  ||      }| j                  |   j                  }t        j                  |      t        u rt        j                  |      d   }t        |t              r(t        j                  |      t        urt        ||       t        |t               s
t        |      r|D ]5  }t        |t              st        t        j                  |      d   |       7 S yc c}}w )zfRemoves extra fields from the response that are not in the model.

  Mutates the response in place.
  r   N)r&   r@   model_fieldsaliaspopr,   ri   rm   r	   r   r   r%   r-   _remove_extra_fieldsru   )	rv   rw   
key_valuesr0   r   
field_info	alias_mapri   rP   s	            r   r|   r|   =  sM    HNN$%* Ejc5 6;5G5G5M5M5O"1#z
#I  %$$$I)=ll3
--S
!C##C(33J $-??:.q1j %6#4#4Z#@#L:u-	E4	 		$ E$dD!
vz:1=t
DE7Es    E1Tr:   )boundrk   d         indent_levelindent_deltamax_len	max_itemsdepthvisitedr   r   r   r   r   r   c          
      J   |
t               }t        |       }||v ry|dk  ryt        t        |      |gz         }d|z  }d||z   z  }	t        | t        j
                        r| j                  j                  }
g }t        t        |       j                        }|D ]g  }t        |       j                  |   }|j                  s(	 t        | |      }|8t        |||z   ||||dz
  |      }|j                  |	 | d|        i |s|
 d	S |
 d
dj!                  |      z   d| dz   S t        | t"              r'd| v r| j%                  dd      }d| dS t        |       S t        | t&              r0t)        |       |kD  rt        | d|dz
         dd  dS t        |       S t        | t*        j,                  j.                        r| sy|dk  r&t)        |        dt)        |       dk7  rdnd }d| dS t)        |       |kD  rdt)        |        dS g }	 t        | j1                         t"              }|D ]O  }| |   }t        |||z   ||||dz
  |      }t        |||z   ||||dz
  |      }|j                  |	 | d|        Q ddj!                  |      z   d| dz   S t        | t        t4        t6        f      rt9        | ||||||      S t        |       }|j%                  dd|	       S # t        $ r Y _w xY w# t2        $ r t        | j1                               }Y w xY w)z-Returns a representation of the given object.Nz<... Circular reference ...>r   z<... Max depth ...> r   r   =z()z(
,

)z"""z\"\"\"   r   z...'z{} items z{<... z at Max depth ...>}z
<dict len=>)r0   z: z{
})	frozensetidr&   r%   rf   r:   	__class__r   sortedtypery   reprr<   AttributeError_pretty_reprrO   joinrl   replacebytesr(   collectionsabcMappingr   	TypeErrortuplerB   _format_collection)rb   r   r   r   r   r   r   obj_idindentnext_indent_strcls_namer@   fields
field_namer~   r   
value_represcapeditem_count_strsorted_keysrQ   rT   k_reprv_reprraw_reprs                            r   r   r   i  s    _kGc7&w)
QY d7mvh./'&<,67/X''(}}%%HEDI**+F B
9))*5j__Z( 

#l2#	j llo&zl!J<@A-B0 z_Zsejj//Bvha.@@#ss{E;/g7)39#u
3x'S'!)_%cr*+4009#{../ zc(5CA2(FGn~&&:;;
3x)#c(1%%E%388:3/k  ;
a&a
#l2#	f 
#l2#	f llo&vhb9:);* UZZ&&2fXR88#eS)*!!  CyHDB&7"899i  Z  %$k%s$   K-K= -	K:9K:="L"!L"c                   t        | t              rd}| }nXt        | t              rd}t        |       }n:t        | t              rt        |       }| rd}nd}nt	        dt        |              |s|d   |d   z   S |dk  r/t        |       dd	t        |      dk7  z   }	|d    d
|	 d|d    S d|z  }
d||z   z  }g }t        t        |      |      }t        |      D ]1  }||   }|j                  |t        |||z   ||||dz
  |      z          3 t        |      |kD  r#|j                  | d
t        |      |z
   d       |d    ddj                  |      z   d|
 |d    z   S )z(Formats a collection (list, tuple, set).)[])(r   ){r   )zset(r   zUnsupported collection type: r   r   r   r   z<... z at Max depth ...>r   r   z more items ...>r   r   )r%   r&   r   rB   r)   r   r(   minr'   rO   r   r   )rb   r   r   r   r   r   r   bracketsinternal_objr   r   r   elementsnum_to_showr/   elems                   r   r   r     s    THL#uH9L#s9L
hh
4T#YK@
AA	A;!$$ aZL)*%S5F5I0J/KLNqk]%//A(1+OO&<,67/(C%y1+ a?DOO
%4%!)
		
 	"OO
5\!2Y!> ??OP QK=	ejj2	2s6(8A;-5P	PPr   c                        e Zd Z ej                  ej                  dddddddej                  f	      Z	de
f fdZedej                  e   d	ee
ef   d
ee
ef   defd       Zdee
ef   fdZ xZS )r:   Tr   forbidbase64)	alias_generatorpopulate_by_namefrom_attributesprotected_namespacesextraarbitrary_types_allowedser_json_bytesval_json_bytesignored_typesr   c                 V    	 t        |       S # t        $ r t        |          cY S w xY wN)r   	Exceptionsuper__repr__)selfr   s    r   r   zBaseModel.__repr__4  s0     $  W s   
 ((clsrw   kwargsc                    |d uxr5 d|v xr/ |d   d uxr& t        |d   t              xr d|d   v xr |d   d   }|st        | |       | j                  |      }|S )Nconfiginclude_all_fields)r%   r-   r|   model_validate)r   rw   r   should_skip_removing_fieldsvalidated_responses        r   _from_responsezBaseModel._from_response:  s     	d 	3	38D(	3 vh'.	3 !F8$44		3
 812   '3)++H5r   c                 (    | j                  dd      S )NTjson)re   mode)rh   )r   s    r   to_json_dictzBaseModel.to_json_dictV  s    ??6?::r   )r   r   r   rf   
ConfigDictr
   to_camelrm   TypeVarmodel_configrl   r   classmethodTyper   r-   objectr   r   __classcell__r   s   @r   r:   r:   %  s    $$$&//"^^%,    ;;q> S&[! 3;	
 	 6;Df- ;r   c                   6     e Zd ZdZededef fd       Z xZS )CaseInSensitiveEnumzCase insensitive enum.r   r   c                 B   	 | |j                            S # t        $ r 	 | |j                            cY S # t        $ r\ t        j                  | d| j
                          	 t        |   | |      }t        |      |_	        ||_
        |cY cY S #  Y Y Y y xY ww xY ww xY w)Nz is not a valid )r\   KeyErrorlowerwarningswarnr   r   __new__rl   _name__value_)r   r   unknown_enum_valr   s      r   	_missing_zCaseInSensitiveEnum._missing_]  s     5;;=!! 
/~>?	 #W_S%8
$'J

!%*

"!
!	
sG    	B5B-B#(BBBBBBBB)r   r   r   r   r   r   r   r   r   s   @r   r   r   Z  s&    C C  r   r   c                      t         j                   j                         j                  d      } t        j                         j
                  dd }|  d| S )z]Composes a timestamped unique name.

  Returns:
      A string representing a unique name.
  z%Y%m%d%H%M%Sr   r   r2   )datetimenowstrftimeuuiduuid4hex)	timestamp	unique_ids     r   timestamped_unique_namer   q  sL     ##%..~>)jjlq#);a	{	##r   c                    i }t        | t              s| S | j                         D ]:  \  }}t        |t              r(t	        j
                  |      j                  d      ||<   ?t        |t        j                        r|j                         ||<   mt        |t              rt        |      ||<   t        |t              rt        d |D              r5|D cg c]&  }t	        j
                  |      j                  d      ( c}||<   t        d |D              r#|D cg c]  }|j                          c}||<   |D cg c]  }t        |       c}||<   6|||<   = |S c c}w c c}w c c}w )a  Converts unserializable types in dict to json.dumps() compatible types.

  This function is called in models.py after calling convert_to_dict(). The
  convert_to_dict() can convert pydantic object to dict. However, the input to
  convert_to_dict() is dict mixed of pydantic object and nested dict(the output
  of converters). So they may be bytes in the dict and they are out of
  `ser_json_bytes` control in model_dump(mode='json') called in
  `convert_to_dict`, as well as datetime deserialization in Pydantic json mode.

  Returns:
    A dictionary with json.dumps() incompatible type (e.g. bytes datetime)
    to compatible type (e.g. base64 encoded string, isoformat date string).
  asciic              3   <   K   | ]  }t        |t                y wr   )r%   r   .0rT   s     r   	<genexpr>z.encode_unserializable_types.<locals>.<genexpr>  s     1aZ5!1s   c              3   P   K   | ]  }t        |t        j                           y wr   )r%   r   r  s     r   r  z.encode_unserializable_types.<locals>.<genexpr>  s     =!Z8,,-=s   $&)r%   r-   r@   r   r   urlsafe_b64encodedecoder   	isoformatencode_unserializable_typesr&   all)r   processed_datar0   r   rT   s        r   r	  r	  |  sB    ').	D$	KJJL "jc5%"44U;BB7KnS	E8,,	-!OO-nS	E4	 7>nS	E4	 	151	1AF
<=F$$Q'..w7
s 
=u=	=6;<q{{}<sGLM!:1=Ms!nS#"$ 

 =Ms   +E%E*E/message.c                 P     dt         dt        f   dt         dt        f   f fd}|S )z&Experimental warning, only warns once.func.r   c                 t     dt        j                         dt        dt        dt        f fd       }|S )NFargsr   r   c                  T    sdt        j                  t        d        | i |S )NTrk   )r  category
stacklevel)r   r   r   )r  r   r  r  warning_dones     r   wrapperz8experimental_warning.<locals>.decorator.<locals>.wrapper  s4     (	

 4"6""r   )	functoolswrapsr   )r  r  r  r  s   ` @r   	decoratorz'experimental_warning.<locals>.decorator  s?    L__T	#s 	#c 	#c 	# 	# Nr   )r   r   )r  r  s   ` r   experimental_warningr    s0    
hsCx( Xc3h-? " 
r   key_strc                 B    | j                  dd      j                         S )z?Normalizes a key for case-insensitive and snake/camel matching.r2   r   )r   r   )r  s    r   _normalize_key_for_matchingr    s    	b	!	'	'	))r   target_dictupdate_dictc                    i }| j                         D ci c]  }t        |      | }}|j                         D ]  \  }}t        |      }||v r||   }n|}t        |t              r2t        | j                  |      t              rt        | |   |      ||<   _t        |t              r%t        | j                  |      t              r|||<   |||<    |S c c}w )a  Aligns the keys of update_dict to the case of target_dict keys.

  Args:
      target_dict: The dictionary with the target key casing.
      update_dict: The dictionary whose keys need to be aligned.

  Returns:
      A new dictionary with keys aligned to target_dict's key casing.
  )r   r  r@   r%   r-   r,   align_key_caser&   )r  r  aligned_update_dictr0   target_keys_mapr   normalized_update_keyaligned_keys           r   r   r     s     %'7B7G7G7I03!#&+/   %%' /jc57</#$9:kk%:$d$ *8
k
"E*+& 
E4	 Z$d& */+&).+&)/* 
3s   Cc                 p   t        | |      }|j                         D ]  \  }}|| v r3t        | |   t              r t        |t              rt	        | |   |       =|| v rRt        | |   t        |            s:t        j                  d| dt        | |          dt        |       d       || |<   || |<    y)a  Recursively updates a target dictionary with values from an update dictionary.

  We don't enforce the updated dict values to have the same type with the
  target_dict values except log warnings.
  Users providing the update_dict should be responsible for constructing correct
  data.

  Args:
      target_dict (dict): The dictionary to be updated.
      update_dict (dict): The dictionary containing updates.
  zType mismatch for key 'z'. Existing type: z, new type: z. Overwriting.N)r   r@   r%   r-   recursive_dict_updater   loggerwarning)r  r  r!  r0   r   s        r   r&  r&    s    $ '{K@'--/ jc5{{3'.ud#K,e4		J{3/?e$Mnn#C5 );s#$%\$u+nN k#k#r   )T)F):r   r   collections.abcr   r   enumr  loggingr_   rm   r   r   r   r   r   r   r	   r   r   rf   r
   typing_extensionsr   	getLoggerr'  r-   rl   r   __annotations__Warningr   r&   r*   r9   rK   intrB   rD   boolra   r   rg   r   ru   r|   r   r   r   r   r:   Enumr   r   r	  r  r  r   r&  r   r   r   <module>r3     s    $       	  R R R    % '			1	2S#X
I &+' +G
4S>
"G*.s)G<?G	GV 9='
'#Y'25''T!IS !Ic3h !ID !IH5
5c5 Cy5 	5
 c(5 
5pQC Q$ Q# Q t  66 6 6B&E &EtCK/@ &ET &ER FNN3k* (,{:	{: {: 	{:
 {: {: {: in%{: 	{:|;Q	;Q ;Q 	;Q
 ;Q ;Q ;Q s^;Q 	;Q|2;"" 2;j#tyy .$ $#d3;&7 #Df<M #LxS!"HS#X$6672* * *
&&*4&&R!!*4!	!r   