
    BVh                     j    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 Z
d Z	 	 	 ddZy)	zCConverting AST to code and Python entities.

Adapted from Tangent.
    N)origin_info)parserc                     	 t        j                  |        y# t        $ r)}|j                  t        j                  k(  rn Y d}~yd}~ww xY w)zRemove a file, if it exists.N)osremoveOSErrorerrnoENOENT)	file_namees     W/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/autograph/pyct/loader.py_remove_filer      s@    IIi	 ww%,,  	s    	A
AA
c                 
   t        j                  ddddd      5 }t        j                  j	                  |j
                  dd       }|j
                  |j                  |        ddd       |rt        j                  fd	       t        j                  j                        }t        j                  j                  |      }|j                  j                  |       |t        j                   |<   |fS # 1 sw Y   xY w)
z/Loads the given source code as a Python module.wz.py__autograph_generated_fileFzutf-8)modesuffixprefixdeleteencodingNc                      t               S )N)r   )r   s   r   <lambda>zload_source.<locals>.<lambda>9   s    L3     )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   s         @r   load_sourcer1   ,   s    "") 
 ''""166#2;/KIGGFO 
OO34		/	/Y	G$>>**40&++&!##++k		% s   A
C99Dc                     t        | t        t        f      s| f} t        j                  | |      }t        ||      \  }}|r"t        j                  | ||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   unparser1   r   create_source_map__file__)nodesr3   include_source_mapr,   r+   r0   _
source_maps           r   load_astr>   C   sh    . 
ED%=	)HE>>%[9&&.1)&!..uffooNJJ 
	##r   )z  FT)__doc__r!   r	   r#   r   r)   r    tensorflow.python.autograph.pyctr   r   r   r1   r>    r   r   <module>rB      s>   
    	 
  8 3
0  % #$r   