
    `i                         d Z ddlZddlZ	 ej        Zn# e$ r
 ej        ZY nw xY w G d de          Zddee	e
eefdZddddd	eej        ee
eefd
Zeej        ee
eefdZ G d dej                  Zd Zd ZdS )a  
Part of the astor library for Python AST manipulation.

License: 3-clause BSD

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

Utilities for node (and, by extension, tree) manipulation.
For a whole-tree approach, see the treewalk submodule.

    Nc                       e Zd ZdZdS )NonExistentz/This is not the class you are looking for.
    N)__name__
__module____qualname____doc__     c/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/astor/node_util.pyr   r      s         Dr
   r    c              #     K    || dd          }|a|D ]} || ||          }	|	|ur|	|fV  |A|                     t          t          |                     t          |          z
             dS dS  || |          r| D ]
}	|	|fV  	dS dS )a  Iterates over an object:

       - If the object has a _fields attribute,
         it gets attributes in the order of this
         and returns name, value pairs.

       - Otherwise, if the object is a list instance,
         it returns name, value pairs for each item
         in the list, where the name is passed into
         this function (defaults to blank).

       - Can update an unknown set with information about
         attributes that do not exist in fields.
    _fieldsN)updatesetvars)
nodenameunknownlistgetattr
isinstance	enumeratemissingfieldsvalues
             r   	iter_noder      s      $ WT9d++F 	" 	"DGD$00EG##Tk!!!NN3tDzz??S[[899999 	D$		  	 	E+ 	 	r
       x   P   c                 N   	
 d	
f
d	 | ||          S )z}Dumps an AST or similar structure:

       - Pretty-prints with indentation
       - Doesn't print line/column/ctx info

    Nr   c                   
 |	z   |r|dz   pd}  |                     } 
|           rd|z  d}}nO|r| |           j         dd}}n5 
|           r| |           j         z   d}}n|t          |           S fd|D             } |d                    |           |} |           |          z   k     rd	|z  S | r; |           | d
                   z   k     r||                     d
          d}dz                      |                                           } |d| |S )N=r   z%s[]()c                 <    g | ]\  }}|d k     ||          S ctxr	   ).0abdumplevels      r   
<listcomp>z+dump_tree.<locals>.dump.<locals>.<listcomp>T   s0    CCCdaU

Q5!!


r
   z, z%sr   ,z,
%s
)r   reprjoinpoplstrip)r   r   indentvaluesprefixsuffixoneliner-   r,   indentationr   r   lenr   maxline	maxmergedspecialtypes          @r   r,   zdump_tree.<locals>.dumpH   s   $"s
(biioo&&:dD!! 	/"T\3FFF 	/(,dd4jj.A.A.ABCFFFZg&& 	/!DDJJ$77FFF!T4:::..CCCCCfCCC$fdiiooovv>3w<<##f++%//'>! 	5CCKK##d1g,,.:: &4F%%%d++2244%vvuuddFF;;r
   )Nr   r	   )r   r   initial_indentr:   r<   r=   r   r>   r   r   r?   r;   r,   s      `````````@r   	dump_treerA   =   sm    < < < < < < < < < < < < < < <( 4dN+++r
   c                 Z    t                      fd | d           S )zStrips an AST by removing all attributes not in _fields.

    Returns a set of the names of all attributes stripped.

    This canonicalizes two trees for comparison purposes.
    c                    t                      }d} 	| |          D ]\  }}d} ||dz              |r( |           rt          t          |                     }                    |           |D ]}t          | |           t	          | d          rGt          | d           d| j        v r0 
| j                  }|                    d           || _        d S d S d S )NT)r   Fr   r(   )r   r   r   delattrhasattrr   remove)r   r5   r   leafsubnode_r   mylistr   r   r   r>   stripstrippeds           r   rK   zstrip_tree.<locals>.stripk   s   %%#)D'::: 	, 	,JGQDE'6F?++++ 	*z$(( *d4jj//    	  	 DD$4 	&D%   $$dl++e$$$%	& 	&$$r
   r   )r   )	r   r   r>   r   r   r?   r;   rK   rL   s	    ````  @@r   
strip_treerM   _   s[     uuH& & & & & & & & & &$ 
E$OOOOr
   c                   "    e Zd ZdZd ZefdZdS )ExplicitNodeVisitorz[This expands on the ast module's NodeVisitor class
    to remove any implicit visits.

    c                 >    d}t          || j        j        z            )Nz&No defined handler for node of type %s)AttributeError	__class__r   )r   msgs     r   abort_visitzExplicitNodeVisitor.abort_visit   s    6S4>#::;;;r
   c                 X    d|j         j        z   }t          | ||          } ||          S )zVisit a node.visit_)rR   r   r   )selfr   abortmethodvisitors        r   visitzExplicitNodeVisitor.visit   s0    DN33$..wt}}r
   N)r   r   r   r   rT   r[   r	   r
   r   rO   rO      sF         
< < < !,      r
   rO   c                  \    G d dt                     } t          t                                                    D ]q}t	          |          t          k    rt          |t          j                  r<	 t          t          |j	                  | gz             |_	        a# t          $ r Y mw xY wrdS )aP  This ugly little monkey-patcher adds in a helper class
    to all the AST node types.  This helper class allows
    eq/ne comparisons to work, so that entire trees can
    be easily compared by Python's comparison machinery.
    Used by the anti8 functions to compare old and new ASTs.
    Could also be used by the test library.


    c                       e Zd Zd Zd ZdS )+allow_ast_comparison.<locals>.CompareHelperc                     t          |           t          |          k    ot          |           t          |          k    S Nr?   r   rW   others     r   __eq__z2allow_ast_comparison.<locals>.CompareHelper.__eq__   s/    ::e,JdtE{{1JJr
   c                     t          |           t          |          k    pt          |           t          |          k    S r`   ra   rb   s     r   __ne__z2allow_ast_comparison.<locals>.CompareHelper.__ne__   s/    ::e,IT

d5kk0IIr
   N)r   r   r   rd   rf   r	   r
   r   CompareHelperr^      s:        	K 	K 	K	J 	J 	J 	J 	Jr
   rg   N)objectr   astr6   r?   
issubclassASTtupler   	__bases__	TypeError)rg   items     r   allow_ast_comparisonrp      s    J J J J J J J J S		  ""  ::dCG$$ 	!&tDN';';}o'M!N!N   	 s   0*B
B('B(c                    t           j        j        | |fg}|j        }|j        }t
          t          f}t          }t          }t          }|r |            \  	  d          }	 d          }
d |	D             }	|	d |
D             k    rdS  |fd|	D                        n8# |$ r0  |          |u r | |                     Y k    rY Y dS w xY w|dS )z This is optimized to compare two AST trees for equality.
        It makes several assumptions that are currently true for
        AST trees used by rtrip, and it doesn't examine the _attributes.
    r   c                     g | ]
}|d k    |S r'   r	   r)   xs     r   r.   z fast_compare.<locals>.<listcomp>   s    ...1::!:::r
   c                     g | ]
}|d k    |S r'   r	   rs   s     r   r.   z fast_compare.<locals>.<listcomp>   s    222AqEzzazzzr
   Fc              3   H   K   | ]} |           |          fV  d S r`   r	   )r)   fnamegetan1n2s     r   	<genexpr>zfast_compare.<locals>.<genexpr>   s<      FF%DDUOOTT"e__5FFFFFFr
   T)
ri   rk   __getattribute__r3   extendrn   rQ   zip_longestr?   r   )tree1tree2workr3   r}   	exceptionzipltype_list_f1f2rx   ry   rz   s              @@@r   fast_comparer      s\    7#DEND
(C[F>)IDEE
 GB	Gb)$$Bb)$$B /.R...B2222222uFFFFFFF2FFFFFFF  	 	 	uRyyE!!ttB||$$$Rxx55	  G$ 4s   B+ +'C C C )r   ri   	itertoolsr~   rQ   izip_longestrh   r   r   r   r   r   r   rk   r?   r;   rA   rM   NodeVisitorrO   rp   r   r	   r
   r   <module>r      s[    


    )'KK ) ) )(KKK)	 	 	 	 	& 	 	 	 TZ!;   > bfR!37JTs	, , , ,H #CGZd   D    #/   "  8" " " " "s    ##