
    hy                     l   S SK r S SKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJ	r	  S SK
r
\
R                  " \\\\\\45      r " S
 S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S5      r0 SS_SS_SS_SS_SS_S S!_S"S#_S$S%_S&S'_S(S)_S*S+_S,S-_S.S/_S0S1_S2S3_S4S5_S6S7_S8S9S:.ER2                  rS;S<S=S>S?.R2                  r " S@ SA\5      r " SB SC\5      rSD r " SE SF\5      rSG r SH r! " SI SJ\5      r"\#SK:X  a  S SK$r$\$RJ                  " 5         gg)L    N   )	TypeSlots)Builtin)Nodes)	ExprNodes)Errors)
DebugFlags)Futurec                      ^  \ rS rSrSrU 4S jrS rS rS r\	R                  S 5       rS r\	R                  S	 5       r\	R                  S
 5       rSS jr\	R                  S 5       rSrU =r$ )TreeVisitor   a  
Base class for writing visitors for a Cython tree, contains utilities for
recursing such trees using visitors. Each node is
expected to have a child_attrs iterable containing the names of attributes
containing child nodes or lists of child nodes. Lists are not considered
part of the tree structure (i.e. contained nodes are considered direct
children of the parent node).

visit_children visits each of the children of a given node (see the visit_children
documentation). When recursing the tree using visit_children, an attribute
access_path is maintained which gives information about the current location
in the tree as a stack of tuples: (parent_node, attrname, index), representing
the node, attribute and optional list index that was taken in each step in the path to
the current node.

Example:

>>> class SampleNode(object):
...     child_attrs = ["head", "body"]
...     def __init__(self, value, head=None, body=None):
...         self.value = value
...         self.head = head
...         self.body = body
...     def __repr__(self): return "SampleNode(%s)" % self.value
...
>>> tree = SampleNode(0, SampleNode(1), [SampleNode(2), SampleNode(3)])
>>> class MyVisitor(TreeVisitor):
...     def visit_SampleNode(self, node):
...         print("in %s %s" % (node.value, self.access_path))
...         self.visitchildren(node)
...         print("out %s" % node.value)
...
>>> MyVisitor().visit(tree)
in 0 []
in 1 [(SampleNode(0), 'head', None)]
out 1
in 2 [(SampleNode(0), 'body', 0)]
out 2
in 3 [(SampleNode(0), 'body', 1)]
out 3
out 0
c                 >   > [         TU ]  5         0 U l        / U l        g N)super__init__dispatch_tableaccess_path)self	__class__s    Q/var/www/fran/franai/venv/lib/python3.13/site-packages/Cython/Compiler/Visitor.pyr   TreeVisitor.__init__D   s         c                 "   [        UR                  =(       d    / 5      / SQ-   n/ n[        USS 5      nU(       a[  US   nU(       a-  SS KnUR                  R                  UR                  5       5      nUR                  U< SUS   < SUS   < 35        [        U5      nU H  nX;   a  M
  UR                  S5      (       d  UR                  S5      (       a  M8   [        X5      n	U	b  U	S:X  a  MO  [        U	[         5      (       a  S[        U	5      -  n	O"[        U	[        5      (       d  M  [        U	5      n	UR                  U< S	U	< 35        M     UR                   R"                  < S
SR%                  U5      < S3$ ! [         a     M  f = f)N)child_attrsposgil_messagecpp_messagesubexprsr   r   :r      _z[...]/%d = (z,
    ))listr   getattros.pathpathbasenameget_descriptionappenddir
startswithendswithAttributeError
isinstancelen
_PRINTABLEreprr   __name__join)
r   nodeignoredvaluesr   sourceosattribute_namesattrvalues
             r   	dump_nodeTreeVisitor.dump_nodeI   sS   t''-2. 2L LdE4(VF))&*@*@*BCMMAA?@d)#Ds##t}}S'9'9+ }
E4(("SZ/z22UMMtU34# $$  >>22INN64JKK " s   F  
FFc                    SS K nUn/ n[        US5      (       a  UR                  nUR                  R	                  S5      n[        U[        R                  5      (       a^  UR                  nUR                  nUR                  R                  UR                  5      UR                  4n	UR                  XhU	45        UnUR                  n[        US5      (       a  M  X44$ )Nr   tb_framer   )r'   hasattrrA   f_localsgetr0   r   Nodef_codeco_namer(   r)   co_filenamef_linenor+   tb_next)
r   
stacktracer:   last_tracebacknodesframer6   codemethod_namer   s
             r   _find_node_pathTreeVisitor._find_node_pathi   s    #j*--''E>>%%f-D$

++||"llww''(8(89~~'d56!+#++J j*-- &&r   c                 D   S/nU R                    Hb  u  pEn[        XE5      nUc  SnO	Xv   nSU-  nUR                  UR                  R                  < SU< U< SU R                  U5      < 35        Md     U R                  [        R                  " 5       S   5      u  pUn
U	 H4  u  p{nUn
UR                  SUS   US   XR                  U5      4-  5        M6     [        R                  " [        U
S	S 5      U R                  R                  S
R                  U5      X(5      e)N z[%d].r"   r    zFile '%s', line %d, in %s: %sr   r   r   
)r   r&   r+   r   r4   r>   rQ   sysexc_infor   CompilerCrashr5   )r   childetraceparent	attributeindexr6   rK   called_nodes	last_noderP   r   s                r   _raise_compiler_error!TreeVisitor._raise_compiler_errorz   s   (,(8(8$Fu6-D}{LL  ))9et$& ' )9 $(#7#7q8I#J 
	&2"DsILL8AA^^D-A<C C D '3 ""Iud+T^^-D-DIIea- 	-r   c                    [        U5      n[        R                  " U5      nU H$  n[        U SUR                  -   S 5      nUc  M"  Us  $    [        [        U 5      U5        U R                  (       a_  [        U R                  5        [        U R                  S   S   R                  5        [        U R                  S   S   R                  5        [        SU < SU< 35      e)Nvisit_r   zVisitor z does not accept object: )
typeinspectgetmror&   r4   printr   r   __dict__RuntimeError)r   objclsmromro_clshandler_methods         r   find_handlerTreeVisitor.find_handler   s     3innS!G$T8g6F6F+FMN)%% 
 	d4j#$""#$""2&q)--.$""2&q)223dCPQQr   c                 $    U R                  U5      $ r   _visit)r   rm   s     r   visitTreeVisitor.visit   s    {{3r   c                      U R                   [        U5         nU" U5      $ ! [         a+    U R                  U5      nX R                   [        U5      '    N<f = f! [        R
                   a    e [        R                   a    e [         a1  n[        R                  (       a  e U R                  X5         S nAg S nAff = fr   )r   rg   KeyErrorrr   r   CompileError
AbortError	Exceptionr	   debug_no_exception_interceptrb   )r   rm   rq   r[   s       r   rv   TreeVisitor._visit   s    	/@!%!4!4T#Y!? "#&&  @!%!2!23!71?##DI.@ "" 	   	 	/66&&s..	/s2   # A 2AA AA 2B>'B99B>c                     U R                   R                  X#U45        U R                  U5      nU R                   R                  5         U$ r   )r   r+   rv   pop)r   rZ   r]   attrnameidxresults         r   _visitchildTreeVisitor._visitchild   sB     	3 78U#r   c                 &    U R                  XU5      $ r   )_visitchildrenr   r]   attrsexcludes       r   visitchildrenTreeVisitor.visitchildren   s    ""6'::r   c                    Uc  g0 nUR                    H  nUb  XR;  a  M  Ub  XS;   a  M  [        X5      nUc  M'  [        U5      [        L a0  [	        U5       VVs/ s H  u  pxU R                  XXW5      PM     n	nnO7U R                  XaUS5      n	[        U	[        5      (       a   SU< SU< 35       eXU'   M     U$ s  snnf )a.  
Visits the children of the given parent. If parent is None, returns
immediately (returning None).

The return value is a dictionary giving the results for each
child (mapping the attribute name to either the return value
or a list of return values (in the case of multiple children
in an attribute)).
NzCannot insert list here: z in )r   r&   rg   r%   	enumerater   r0   )
r   r]   r   r   r   r<   rZ   r   xchildretvals
             r   r   TreeVisitor._visitchildren   s     >$&&D T%6"tF)E ;$&XabgXh"iXhfc4#3#3At#IXhK"iK"&"2"25$"MK)+t<<reikq>rr<*t '  #js   B=)r   r   NN)r4   
__module____qualname____firstlineno____doc__r   r>   rQ   rb   cythonfinalrr   rw   rv   r   r   r   __static_attributes____classcell__r   s   @r   r   r      s    )T
L@'"-, \\R R   \\/ /$ \\ ; \\ r   r   c                       \ rS rSrSrSS jr\R                  SS j5       r\R                  S 5       r	SS jr
S rS	 rS
rg)VisitorTransform   a  
A tree transform is a base class for visitors that wants to do stream
processing of the structure (rather than attributes etc.) of a tree.

It implements __call__ to simply visit the argument node.

It requires the visitor methods to return the nodes which should take
the place of the visited node in the result tree (which can be the same
or one or more replacement). Specifically, if the return value from
a visitor method is:

- [] or None; the visited node will be removed (set to None if an attribute and
removed if in a list)
- A single node; the visited node will be replaced by the returned node.
- A list of nodes; the visited nodes will be replaced by all the nodes in the
list. This will only work if the node was already a member of a list; if it
was not, an exception will be raised. (Typically you want to ensure that you
are within a StatListNode or similar before doing this.)
Nc                 &    U R                  XU5      $ r   _process_childrenr   s       r   r   VisitorTransform.visitchildren   s    %%fW==r   c                     U R                  XU5      nUR                  5        H4  u  pV[        U5      [        L a  U R	                  U5      n[        XU5        M6     U$ r   )r   itemsrg   r%   _flatten_listsetattr)r   r]   r   r   r   r<   newnodes          r   r   "VisitorTransform._process_children   sU     $$VG<#\\^MDG}$,,W5F'* , r   c                     / nU H>  nUc  M  [        U5      [        L a  UR                  U5        M-  UR                  U5        M@     U$ r   )rg   r%   extendr+   )r   	orig_listnewlistr   s       r   r   VisitorTransform._flatten_list  sB     A}7d?NN1%NN1%  r   c                 j    [        X5      nUb$  U R                  XAX#5      nXTLa  [        XU5        UnU$ r   )r&   r   r   )r   r]   r<   r   rZ   r6   s         r   
visitchildVisitorTransform.visitchild  s>    %##E4=D d+Er   c                 (    U R                  U5        U$ r   r   r   r6   s     r   recurse_to_children$VisitorTransform.recurse_to_children      t$r   c                 $    U R                  U5      $ r   ru   )r   roots     r   __call__VisitorTransform.__call__  s    {{4  r    r   )r   )r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      sK    &> \\  \\	 	!r   r   c                   D   ^  \ rS rSrSrU 4S jrU 4S jrS rS rSr	U =r
$ )CythonTransformi"  z
Certain common conventions and utilities for Cython transforms.

 - Sets up the context of the pipeline in self.context
 - Tracks directives in effect in self.current_directives
c                 .   > [         TU ]  5         Xl        g r   )r   r   context)r   r   r   s     r   r   CythonTransform.__init__)  s    r   c                 p   > SSK J n  [        X5      (       a  UR                  U l        [        TU ]  U5      $ )Nr   )
ModuleNode)r   r0   
directivescurrent_directivesr   r   )r   r6   r   r   s      r   r   CythonTransform.__call__-  s-    *d''&*ooD#w%%r   c                 n    U R                   nUR                  U l         U R                  U5        X l         U$ r   )r   r   r   )r   r6   olds      r   visit_CompilerDirectivesNode,CythonTransform.visit_CompilerDirectivesNode3  s2    %%"&//t$"%r   c                 (    U R                  U5        U$ r   r   r   s     r   
visit_NodeCythonTransform.visit_Node:  r   r   )r   r   )r4   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r   "  s!    & r   r   c                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
ScopeTrackingTransformi?  c                 B    SU l         Xl        U R                  U5        U$ )Nmodule
scope_type
scope_noder   r   s     r   visit_ModuleNode'ScopeTrackingTransform.visit_ModuleNodeD  s!    "t$r   c                     U R                   U R                  4nX l         Xl        U R                  U5        Uu  U l         U l        U$ r   r   )r   r6   r   prevs       r   visit_scope"ScopeTrackingTransform.visit_scopeJ  s?    /$t$+/(r   c                 &    U R                  US5      $ )Ncclassr   r   s     r   visit_CClassDefNode*ScopeTrackingTransform.visit_CClassDefNodeR      h//r   c                 &    U R                  US5      $ )Npyclassr   r   s     r   visit_PyClassDefNode+ScopeTrackingTransform.visit_PyClassDefNodeU  s    i00r   c                 &    U R                  US5      $ )Nfunctionr   r   s     r   visit_FuncDefNode(ScopeTrackingTransform.visit_FuncDefNodeX  s    j11r   c                 &    U R                  US5      $ )Nstructr   r   s     r   visit_CStructOrUnionDefNode2ScopeTrackingTransform.visit_CStructOrUnionDefNode[  r   r   )r   r   N)r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ?  s     
0120r   r   c                   t   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSrU =r$ )EnvTransformi_  z8
This transformation keeps a stack of the environments.
c                 f   > / U l         U R                  XR                  5        [        TU ]  U5      $ r   )	env_stackenter_scopescoper   r   )r   r   r   s     r   r   EnvTransform.__call__c  s,    zz*w%%r   c                 &    U R                   S   S   $ )Nrf   r   r   r   s    r   current_envEnvTransform.current_envh      ~~b!!$$r   c                 &    U R                   S   S   $ )Nrf   r   r   r   s    r   current_scope_nodeEnvTransform.current_scope_nodek  r   r   c                 >    U R                  5       R                  5       $ r   )r   global_scoper   s    r   r   EnvTransform.global_scopen  s    !..00r   c                 <    U R                   R                  X45        g r   )r   r+   )r   r6   r   s      r   r   EnvTransform.enter_scopeq  s    tm,r   c                 8    U R                   R                  5         g r   )r   r   r   s    r   
exit_scopeEnvTransform.exit_scopet  s    r   c                     U R                  U5        U R                  XR                  5        U R                  US UR                  S9  U R                  5         U$ )N)r   r   )visit_func_outer_attrsr   local_scoper   outer_attrsr  r   s     r   r   EnvTransform.visit_FuncDefNodew  sN    ##D)//04tT5E5EFr   c                 6    U R                  XR                  S9  g )N)r   )r   r  r   s     r   r  #EnvTransform.visit_func_outer_attrs~  s    4'7'78r   c                 (    U R                  U5        U$ r   r   r   s     r   visit_GeneratorBodyDefNode'EnvTransform.visit_GeneratorBodyDefNode  r   r   c                 ~    U R                  XR                  5        U R                  U5        U R                  5         U$ r   r   r   r   r  r   s     r   visit_ClassDefNodeEnvTransform.visit_ClassDefNode  1    zz*t$r   c                 ~    U R                  XR                  5        U R                  U5        U R                  5         U$ r   r  r   s     r   r   (EnvTransform.visit_CStructOrUnionDefNode  r  r   c                     UR                   (       a>  U R                  XR                   5        U R                  U5        U R                  5         U$ U R                  U5        U$ r   )
expr_scoper   r   r  r   s     r   visit_ScopedExprNode!EnvTransform.visit_ScopedExprNode  sO    ??T??3""4(OO  ""4(r   c                 V   UR                   (       a  UR                   Vs/ s H  o"S:w  d  M
  UPM     nnU R                  X5        U R                  XR	                  5       R
                  5        U R                  US5        U R                  5         U$ U R                  U5        U$ s  snf )Ndefault)r  )r  r   r   r   r   outer_scoper   r  )r   r6   r<   r   s       r   visit_CArgDeclNodeEnvTransform.visit_CArgDeclNode  s    <<&*&6&6L&6d):KT&6EL""4/T#3#3#5#A#ABt\2OO  ""4( Ms
   	B&B&r   )r4   r   r   r   r   r   r   r   r   r   r  r   r  r  r  r   r  r  r   r   r   s   @r   r   r   _  sN    &
%%1-9
 
r   r   c                   >   ^  \ rS rSrSrU 4S jrS rS rS rSr	U =r
$ )NodeRefCleanupMixini  aW  
Clean up references to nodes that were replaced.

NOTE: this implementation assumes that the replacement is
done first, before hitting any further references during
normal tree traversal.  This needs to be arranged by calling
"self.visitchildren()" at a proper place in the transform
and by ordering the "child_attrs" of nodes appropriately.
c                 .   > [         TU ]  " U6   0 U l        g r   )r   r   _replacements)r   argsr   s     r   r   NodeRefCleanupMixin.__init__  s    $r   c                     UR                   nX R                  ;  a  U R                  U5        U R                  R                  X"5      Ul         U$ r   )argr!  r   rD   )r   r6   r%  s      r   visit_CloneNode#NodeRefCleanupMixin.visit_CloneNode  sB    hh(((s#%%))#3r   c                     UR                   nUb  X R                  ;  a  U R                  U5        UR                   nUb   U R                  R                  X"5      Ul         U$ r   )
expressionr!  r   rD   )r   r6   exprs      r   visit_ResultRefNode'NodeRefCleanupMixin.visit_ResultRefNode  sU    <4'9'99t$??D"0044T@DOr   c                 "    X R                   U'   U$ r   r!  )r   r6   replacements      r   replaceNodeRefCleanupMixin.replace  s    #.4 r   r.  )r4   r   r   r   r   r   r&  r+  r0  r   r   r   s   @r   r  r    s!      r   r  <__lt__z<=__le__z==__eq__z!=__ne__z>=__ge__>__gt__+__add__&__and__/__div__z//__floordiv__z<<
__lshift__%__mod__*__mul__|__or__z**__pow__z>>
__rshift__-__sub____xor____contains__)^in__not____inv____neg____pos__)not~rJ  r:  c                   `    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rSrg)MethodDispatcherTransformi  a  
Base class for transformations that want to intercept on specific
builtin functions or methods of builtin types, including special
methods triggered by Python operators.  Must run after declaration
analysis when entries were assigned.

Naming pattern for handler methods is as follows:

* builtin functions: _handle_(general|simple|any)_function_NAME

* builtin methods: _handle_(general|simple|any)_method_TYPENAME_METHODNAME
c                 t   U R                  U5        UR                  nUR                  R                  (       d  U$ UR                  n[        U[        R                  5      (       d  U$ UR                  nU(       a!  [        U[        R                  5      (       d  U$ UR                  nU R                  XXT5      $ r   )r   r   rg   is_pyobjectpositional_argsr0   r   	TupleNodekeyword_argsDictNoder"  _dispatch_to_handler)r   r6   r   	arg_tupler\  r"  s         r   visit_GeneralCallNode/MethodDispatcherTransform.visit_GeneralCallNode  s    t$==}}((K((	)Y%8%899K((
<9K9K L LK~~((LLr   c                 $   U R                  U5        UR                  nUR                  R                  (       a:  UR                  n[        U[        R                  5      (       d  U$ UR                  nOUR                  nU R                  XUS 5      $ r   )
r   r   rg   rY  r_  r0   r   r[  r"  r^  )r   r6   r   r_  r"  s        r   visit_SimpleCallNode.MethodDispatcherTransform.visit_SimpleCallNode  sn    t$====$$Ii)<)<==>>D99D((tDDr   c                 l    UR                   (       a  U R                  U5        U$ U R                  U5      $ r   )cascader   _visit_binop_noder   s     r   visit_PrimaryCmpNode.MethodDispatcherTransform.visit_PrimaryCmpNode  s-    <<""4(K%%d++r   c                 $    U R                  U5      $ r   )rg  r   s     r   visit_BinopNode)MethodDispatcherTransform.visit_BinopNode  s    %%d++r   c           
         U R                  U5        [        UR                  5      nU(       a  UR                  UR                  pCUS:X  a  XCpCO>US:X  a8  [
        R                  U R                  5       R                  R                  ;   a  SnUR                  nUR                  (       a  UR                  nOSnU R                  US SUUS X4/S 5      nU$ )NrM  r?  __truediv__objectF)r   'find_special_method_for_binary_operatoroperatoroperand1operand2r
   divisionr   r   future_directivesrg   is_builtin_typename_dispatch_to_method_handler)r   r6   special_method_namerr  rs  obj_type	type_names          r   rg  +MethodDispatcherTransform._visit_binop_node  s    t$EdmmT!%h"n4%-($	1??d&6&6&8&@&@&R&RR*7'}}H''$MM	$	33#T5)dX0$8D r   c           
         U R                  U5        [        UR                  5      nU(       aQ  UR                  nUR                  nUR
                  (       a  UR                  nOSnU R                  US SUUS U/S 5      nU$ )Nro  F)r   &find_special_method_for_unary_operatorrq  operandrg   rv  rw  rx  )r   r6   ry  r  rz  r{  s         r   visit_UnopNode(MethodDispatcherTransform.visit_UnopNode1  sv    t$DT]]SllG||H''$MM	$	33#T5)dWIt-D r   c                     UR                  5       (       d  g U(       a  SOSn[        U SU SU 3S 5      nUc  [        U SU 3S 5      nU$ )Ngeneralsimple_handle_r!   _handle_any_)isasciir&   )r   
match_name
has_kwargs	call_typehandlers        r   _find_handler'MethodDispatcherTransform._find_handlerB  sW    !!##!+I	$(9+Qzl CTJ?dl:,$?FGr   c                    UR                   S   nUR                  nUR                  (       a7  UR                  (       a#  [	        UR                  R
                  5      S:  a  U$ OyUR                  (       af  UR                  R                  (       aK  UR                  R                  (       a-  [	        UR                  R                  R
                  5      S:  a  U$ OU$ U R                  XX45      $ )Nr   r   )	cf_staterhsis_nameentryr1   cf_assignmentsis_attributerm   r^  )r   r6   r   arg_listkwargs
assignmentr=   s          r   _delegate_to_assigned_value5MethodDispatcherTransform._delegate_to_assigned_valueM  s    &&q)
==;;#ekk&@&@"AA"E #F EII$5$599??c%))//*H*H&IA&M 'N K((+ 	+r   c                 <   UR                   (       Ga  UR                  (       d  U$ UR                  nUR                  =(       d8    XPR                  5       R	                  5       R                  UR                  5      L nU(       d  UR                  (       a-  UR                  R                  (       a  U R                  XX45      $ U(       a  UR                  (       a  UR                  (       a  UR                  R                  R                  (       ab  UR                  R                  US   R                  L a<  U R                  UR                  S SUR                  R                  R                  XX4S9$ U$ U R!                  SUR                   3U5      nUc  U R#                  XR                  X#U5      $ U(       a	  U" XX45      $ U" XU5      $ UR$                  (       Ga>  UR&                  nUR                  R(                  (       a  UR*                  n	OfUR,                  (       aS  UR                  (       aB  UR                  R.                  nU(       a  UR                  (       d  U$ UR,                  n	USS  nOU$ U	R                  n
SnU
R                  (       ao  U
[0        R2                  L aG  U	R                   (       a6  U(       a/  US   R                  R(                  (       a  U	R                  nS n	SnOU
R                  nUS:X  a  SnOS	nU R                  XXXX45      $ U$ )
Nr   T)self_argis_unbound_methodr{  r6   r   r  r  	function_r   Fstrunicodero  )r  r  
is_builtinr   builtin_scopelookup_hererw  r  	is_singler  
is_cmethodr   parent_typerv  rg   rx  r  _handle_functionr  r^   rY  rm   r   as_variabler   	type_type)r   r6   r   r  r  r  r  function_handler	attr_namer  rz  r  r{  s                r   r^  .MethodDispatcherTransform._dispatch_to_handler]  s    >>NNE   W))+99;GGVV  $$):):)D)D  ;;: : 0 0U[[U[[E\E\ElEl{{..(1+2B2BB#??!JJ&+kk&=&=&B&B!%8  @  \ \ #11HMM?+V 5',,T==(V\]]'II'AA""" **I}}((#<<x~~ 22E$4$4K99#AB<}}H %''w000X5E5E(W_`aWbWgWgWsWs !)I#H(,% (I% )I$	33%62 2 Kr   c	           	      $   U R                  SU SU 3U5      n	U	cF  U[        R                  ;   d  US;   a  U R                  SU 3U5      n	U	c  U R                  XTXXsU5      $ Ub  U/[	        U5      -   nU(       a  U	" XVXsU5      n
U
$ U	" XVXs5      n
U
$ )Nmethod_r!   )__new__r   slot)r  r   special_method_names_handle_methodr%   )r   r  r  r  r{  r6   r   r  r  method_handlerr   s              r   rx  5MethodDispatcherTransform._dispatch_to_method_handler  s     ++i[)-v7!Y;;; $<<!%!3!39+&"0%**Y9 9  zDN2H#VEF
  $=Fr   c                     U$ zFallback handlerr   )r   r6   function_namer   r  r  s         r   r  *MethodDispatcherTransform._handle_function  s    r   c                     U$ r  r   )r   r6   r{  r  r   r  r  r  s           r   r  (MethodDispatcherTransform._handle_method  s	     r   r   N)r4   r   r   r   r   r`  rc  rh  rk  rg  r  r  r  r^  rx  r  r  r   r   r   r   rW  rW    sG    M
E,,*"	+ BH0r   rW  c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )RecursiveNodeReplaceri  zM
Recursively replace all occurrences of a node in a subtree by
another node.
c                 >   > [         TU ]  5         XsU l        U l        g r   )r   r   	orig_nodenew_node)r   r  r  r   s      r   r   RecursiveNodeReplacer.__init__  s    (1%r   c                     XR                   L a  U R                  $ UR                  U R                   L a  U R                  Ul        U$ r   )r  r  r%  r   s     r   r&  %RecursiveNodeReplacer.visit_CloneNode  s6    >>!== 88t~~%}}DHr   c                 \    U R                  U5        XR                  L a  U R                  $ U$ r   )r   r  r  r   s     r   r    RecursiveNodeReplacer.visit_Node  s)    t$>>!== Kr   )r  r  )
r4   r   r   r   r   r   r&  r   r   r   r   s   @r   r  r    s    < r   r  c                 *    [        X5      nU" U 5        g r   )r  )treeold_noder  
replace_ins       r   recursively_replace_noder    s    &x:Jtr   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )
NodeFinderi  z*
Find out if a node appears in a subtree.
c                 <   > [         TU ]  5         Xl        SU l        g )NF)r   r   r6   found)r   r6   r   s     r   r   NodeFinder.__init__  s    	
r   c                 z    U R                   (       a  g XR                  L a  SU l         g U R                  US S 5        g )NT)r  r6   r   r   s     r   r   NodeFinder.visit_Node  s/    ::YYDJdD1r   )r  r6   )	r4   r   r   r   r   r   r   r   r   r   s   @r   r  r    s    
2 2r   r  c                 R    [        U5      nUR                  U 5        UR                  $ r   )r  rw   r  )r  r6   finders      r   tree_containsr    s"    F
LL<<r   c                 J    U u  p#nUc  [        X#U5        gU[        X#5      U'   g)zcReplaces a node. ptr is of the form used on the access path stack
(parent, attrname, listidx|None)
N)r   r&   )ptrr=   r]   r   listidxs        r   replace_noder    s,     !$Fg%(-2!'*r   c                   P    \ rS rSrSrSS jrS rS rSS jrS r	S	 r
S
 rS rSrg)	PrintTreei  zPrints a representation of the tree to standard output.
Subclass and override repr_of to provide more information
about nodes. Nc                     [         R                  U 5        SU l        Uc  Ub  U=(       d    SU=(       d    S4U l        g S U l        g )NrT   r   i   @)r   r   _indent_line_range)r   startends      r   r   PrintTree.__init__  s>    T" %
CL59D#Dr   c                 .    U =R                   S-  sl         g )Nz  r  r   s    r   indentPrintTree.indent  s    r   c                 ,    U R                   S S U l         g )Nr  r   s    r   unindentPrintTree.unindent  s    ||CR(r   c                 D    [        SU-  5        U R                  U5        U$ )NzParse tree dump at phase '%s')rj   rw   )r   r  phases      r   r   PrintTree.__call__  s!    -56

4r   c                     U R                  U5        U R                  5         U R                  U5        U R                  5         U$ r   )_print_noder  r   r  r   s     r   r   PrintTree.visit_Node  s5    4 r   c           	         U R                  U5        U R                  5         UR                  S   nU R                  b*  U R                  S   Us=::  a  U R                  S   ::  a<  O  O9[	        U R
                  < SS< SU R                  UR                  5      < 35        U R                  5         U R                  UR                  5        U R                  5         U R                  5         U$ )Nr   r   - r%  : )
r  r  r   r  rj   r  repr_ofr%  r   r  )r   r6   lines      r   r&  PrintTree.visit_CloneNode$  s    xx{#t'7'7':d'YdFVFVWXFY'Y$,,t||DHH7MNO488$r   c           	      d   UR                   S   nU R                  b*  U R                  S   Us=::  a  U R                  S   ::  am  O  g [        U R                  5      S:X  a  SnOU R                  S   u  pEnUb  SXV4-  nOUn[	        U R
                  < SU< SU R                  U5      < 35        g g )Nr   r   z(root)rf   z%s[%d]r  r  )r   r  r1   r   rj   r  r  )r   r6   r  rw  r]   r<   r   s          r   r  PrintTree._print_node0  s    xx{#t'7'7':d'YdFVFVWXFY'Y4##$)$($4$4R$8!c?#tk1DD$,,dll46HIJ (Zr   c           	         Uc  gUR                   R                  n[        U[        R                  5      (       a-  US[        UR                  5      < SUR                  < S3-  nU$ [        U[        R                  5      (       a  USUR                  -  -  nU$ [        U[        R                  5      (       a)  USUR                  5       < S[        USS 5      < S3-  nU$ [        U[        R                  5      (       a-  US[        UR                  5      < S	UR                  < S3-  nU$ [        U[        R                  [        R                   45      (       a-  US[        UR                  5      < S
UR"                  < S3-  nU$ [        U[        R$                  5      (       a  UR                  nUS[        U5      -  -  nU$ UR&                  (       ak  UR&                  nUS   R)                  5       nSU;   a  UR+                  S5      S   nSU;   a  UR+                  S5      S   nUSU< SUS   < SUS   < S3-  nU$ )Nz(none)z(type=z, name="z")z(name="%s")z(name="z	", type="rg   z, attribute="z, value=r$   z	(type=%s)r   r>  rf   \z(pos=(r   r   r    z)))r   r4   r0   r   NameNoder3   rg   rw  r   DefNodeCFuncDefNodedeclared_namer&   AttributeNoder^   	ConstNodePyConstNoder=   ExprNoder   r*   split)r   r6   r   tr   r(   s         r   r  PrintTree.repr_of=  s   <^^,,F$	 2 233d499otyyQQ, M+ D%--00/DII55( M' D%"4"455&&('$*EG G$ M! D)"9"9::4		?DNN[[ M D9#6#6	8M8M"NOO4		?DJJOO M D)"4"455II+Q// M hh1v--/$;::c?2.D4<::d+B/Dc!fc!fEEMr   )r  r  r   r   )r4   r   r   r   r   r   r  r  r   r   r&  r  r  r   r   r   r   r  r    s0    $)
Kr   r  __main__)&rW   rh   rT   r   r   r   r   r   r	   r
   r   declaretuplebytesr  intfloatcomplexr2   r   r   r   r   r   r  rD   rp  r~  rW  r  r  r  r  r  r  r4   doctesttestmodr   r   r   <module>r     s             ^^EE3UG#DE
F FR=!{ =!@& :0_ 0@E? EP   F+(+(+ 	(+ 	(	+
 	(+ (+ )+ )+ )+ 	.+ 	,+ )+ )+ (+ 	)+  	,!+" )#+$ 
'+( #) (0 	*
 # 'W Wt, .
2 2"3W Wr zOO r   