
    `i                     |    d Z ddlZddlZddlZ	 ddlmZ n# e$ r eZY nw xY w G d de          Z	 e	            Z
dS )z
Part of the astor library for Python AST manipulation.

License: 3-clause BSD

Copyright (c) 2012-2015 Patrick Maupin
Copyright (c) 2013-2015 Berker Peksag

Functions that interact with the filesystem go here.

    N)openc                   d    e Zd ZdZedd            Zed             Zed             ZddZd Z	dS )		CodeToAstaw  Given a module, or a function that was compiled as part
    of a module, re-compile the module into an AST and extract
    the sub-AST for the function.  Allow caching to reduce
    number of compiles.

    Also contains static helper utility functions to
    look for python files, to parse python files, and to extract
    the file/line information from a code object.
    Nc              #      K   t           j                            |           s!t           j                            |           V  t          j        |           D ]"\  }}}|||v rd |D             D ]}||fV  	#dS )zReturn all the python files in a source tree

        Ignores any path that contains the ignore string

        This is not used by other class methods, but is
        designed to be used in code that uses this class.
        Nc              3   D   K   | ]}|                     d           |V  dS ).pyN)endswith).0xs     c/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/astor/file_util.py	<genexpr>z*CodeToAst.find_py_files.<locals>.<genexpr>3   s3      AAqzz%/@/@A!AAAAAA    )ospathisdirsplitwalk)srctreeignoresrcpath_fnamesfnames         r   find_py_fileszCodeToAst.find_py_files#   s       w}}W%% 	)'--((((("$''"2"2 	% 	%GQ!f&7&7AAVAAA % %un$$$$%		% 	%r   c                    	 t          |           5 }|                                }ddd           n# 1 swxY w Y   nT# t          $ rG | dk    r t          j                            d           t          j                                        }Y nw xY w|                    dd                              dd          }|                    d          s|dz  }t          j
        ||           S )zParse a python file into an AST.

        This is a very thin wrapper around ast.parse

            TODO: Handle encodings other than the default for Python 2
                        (issue #26)
        Nstdinz
Reading from stdin:

z

)filename)fopenreadIOErrorsysstdoutwriter   replacer	   astparse)r   ffstrs      r   
parse_filezCodeToAst.parse_file6   s   	$u  vvxx                              	$ 	$ 	$J89999>>##DDD		$
 ||FD))11$==}}T"" 	DLDy....s(   > 2> 6> 6> ABBc                     t          | dd          }d}|| j        }|j        }|j        }|                    dd          }||fS )zReturns the file and line number of a code object.

            If the code object has a __file__ attribute (e.g. if
            it is a module), then the returned line number will
            be 0
        __file__Nr   z.pycr   )getattr__code__co_filenameco_firstlinenor&   )codeobjr   linenum	func_codes       r   get_file_infozCodeToAst.get_file_infoL   sT     T22=(I)E.Gfe,,g~r   c                     |pi | _         d S N)cache)selfr8   s     r   __init__zCodeToAst.__init__]   s    [b


r   c                 &   | j         }|                     |          }|                    |          }||S |d         }|                     |          x||df<   }|j        D ])}t          |t          j                  s||||j        f<   *||         S )Nr   )	r8   r5   getr+   body
isinstancer'   FunctionDeflineno)r9   r2   r8   keyresultr   mod_astobjs           r   __call__zCodeToAst.__call__`   s    
  ))3MA&*ooe&<&<<uajG< 	- 	-Cc3?33 ),E5#*%&&Szr   r7   )
__name__
__module____qualname____doc__staticmethodr   r+   r5   r:   rE    r   r   r   r      s          % % % \%$ / / \/*   \ ! ! ! !    r   r   )rI   r'   r#   r   tokenizer   r    ImportErrorobjectr   code_to_astrK   r   r   <module>rP      s   
 
 


 



 				&&&&&&&   EEET T T T T T T Tn ikks    !!