
    
!i                    f    S r SSKJr  SSKrSSKrSSKrSSKJr  S
S jrS r	SS jr
SS jrSS	 jrg)zGConvenience functions for writing to and reading from Python variables.    )annotationsN)Anyc                    U R                  5       (       d  [        SR                  U 5      5      e[        R                  " U 5      (       a  [        SR                  U 5      5      eg)z7Validates that the variable name is a valid identifier.z&Invalid Python variable name, got "{}"z$Cannot use Python keywords, got "{}"N)isidentifier
ValueErrorformatkeyword	iskeyword)var_names    _/home/james-whalen/.local/lib/python3.13/site-packages/google/generativeai/notebook/py_utils.pyvalidate_var_namer      sU      ""AHHRSS""?FFxPQQ #    c                 (    [         R                  S   $ )N__main__)sysmodules r   r   get_main_moduler       s    ;;z""r   c                    [        U 5        [        [        5       5      nX;   a  X   $ U [        [        5      ;   a  [        [        5      U    $ [	        SR                  U 5      5      e)z>Retrieves the value of `var_name` from the global environment.z"{}" not found)r   varsr   builtins	NameErrorr   )r   g_varss     r   
get_py_varr   $   sX    h/#$F	T(^	#H~h''
$++H5
66r   c                h     [        U 5        [        U 5      ng! [         a     g[         a     gf = f)z@Returns true if `var_name` is defined in the global environment.FT)r   r   r   r   )r   _s     r   
has_py_varr   /   s=    (#x     s    
1	11c                H    [        U 5        [        [        5       5      nXU '   g)z7Sets the value of `var_name` in the global environment.N)r   r   r   )r   valr   s      r   
set_py_varr    <   s    h/#$F8r   )r   strreturnNone)r   r!   r"   r   )r   r!   r"   bool)r   r!   r   r   r"   r#   )__doc__
__future__r   r   r	   r   typingr   r   r   r   r   r    r   r   r   <module>r(      s4    N "   
 R#7
r   