o
    2h                     @   sp   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mZ ddlm	Z	 dd Z
dd Z			
	dddZdS )zCConverting AST to code and Python entities.

Adapted from Tangent.
    N)origin_info)parserc              
   C   sH   zt |  W dS  ty# } z|jtjkrn W Y d}~dS d}~ww )zRemove a file, if it exists.N)osremoveOSErrorerrnoENOENT)	file_namee r   b/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/loader.py_remove_file   s   r   c                    s   t jdddddd}tj|jdd }|j ||  W d   n1 s(w   Y  |r8t fd	d
 t	j
| }t	j
|}|j| |tj|< | fS )z/Loads the given source code as a Python module.wz.py__autograph_generated_fileFzutf-8)modesuffixprefixdeleteencodingNc                      s   t  S )N)r   r   r	   r   r   <lambda>9   s    zload_source.<locals>.<lambda>)tempfileNamedTemporaryFiler   pathbasenamenamewriteatexitregister	importlibutilspec_from_file_locationmodule_from_specloaderexec_modulesysmodules)sourcedelete_on_exitfmodule_namespecmoduler   r   r   load_source,   s&   

r.     FTc                 C   sT   t | ttfs
| f} tj| |d}t||\}}|r#t| ||j}nd}|||fS )a  Loads the given AST as a Python module.

  Compiling the AST code this way ensures that the source code is readable by
  e.g. `pdb` or `inspect`.

  Args:
    nodes: Union[ast.AST, Iterable[ast.AST]], the code to compile, as an AST
      object.
    indentation: Text, the string to use for indentation.
    include_source_map: bool, whether return a source map.
    delete_on_exit: bool, whether to delete the temporary file used for
      compilation on exit.

  Returns:
    Tuple[module, Text, Dict[LineLocation, OriginInfo]], containing:
    the module containing the unparsed nodes, the source code corresponding to
    nodes, and the source map. Is include_source_map is False, the source map
    will be None.
  )indentationN)	
isinstancelisttupler   unparser.   r   create_source_map__file__)nodesr0   include_source_mapr)   r(   r-   _
source_mapr   r   r   load_astC   s   
r;   )r/   FT)__doc__r   r   r    r   r&   r    tensorflow.python.autograph.pyctr   r   r   r.   r;   r   r   r   r   <module>   s   