
    ; i                    `    d Z ddlmZ ddlZddlZddlZddlmZ dd	Zd
 Z	ddZ
ddZddZdS )zGConvenience functions for writing to and reading from Python variables.    )annotationsN)Anyvar_namestrreturnNonec                    |                                  s"t          d                    |                     t          j        |           r"t          d                    |                     dS )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)r   s    }/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/google/generativeai/notebook/py_utils.pyvalidate_var_namer      sq      "" TAHHRRSSS"" R?FFxPPQQQR R    c                 &    t           j        d         S )N__main__)sysmodules r   r   get_main_moduler       s    ;z""r   r   c                   t          |            t          t                                }| |v r||          S | t          t                    v rt          t                    |          S t	          d                    |                     )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6h	T(^^	#	#H~~h''
$++H55
6
66r   boolc                    	 t          |            t          |           }n# t          $ r Y dS t          $ r Y dS w xY wdS )z@Returns true if `var_name` is defined in the global environment.FT)r   r   r   r   )r   _s     r   
has_py_varr!   /   sf    (###x     uu   uu 4s   ! 
;	;;valc                d    t          |            t          t                                }||| <   dS )z7Sets the value of `var_name` in the global environment.N)r   r   r   )r   r"   r   s      r   
set_py_varr$   <   s3    h/##$$FF8r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r"   r   r   r   )__doc__
__future__r   r   r   r   typingr   r   r   r   r!   r$   r   r   r   <module>r(      s    N M " " " " " "   



      R R R R# # #7 7 7 7
 
 
 
     r   