
    9ib%                         S r SSKJr  SSKJr  SSKJrJrJrJ	r	J
r
JrJrJrJr  S rS rS rS rS	 rS
 r " S S\R*                  5      rg)a  Fixer for __metaclass__ = X -> (future.utils.with_metaclass(X)) methods.

The various forms of classef (inherits nothing, inherits once, inherints
many) don't parse the same in the CST so we look at ALL classes for
a __metaclass__ and if we find one normalize the inherits to all be
an arglist.

For one-liner classes ('class X: pass') there is no indent/dedent so
we normalize those into having a suite.

Moving the __metaclass__ into the classdef can also cause the class
body to be empty so there is some special casing for that as well.

This fixer also tries very hard to keep original indenting and spacing
in all those corner cases.
    )
fixer_base)token)	NamesymsNodeLeaftouch_importCallStringCommaparenthesizec                    U R                    H  nUR                  [        R                  :X  a  [	        U5      s  $ UR                  [        R
                  :X  d  MN  UR                   (       d  Ma  UR                   S   nUR                  [        R                  :X  d  M  UR                   (       d  M  UR                   S   n[        U[        5      (       d  M  UR                  S:X  d  M    g   g)zwe have to check the cls_node without changing it.
There are two possibilities:
  1)  clsdef => suite => simple_stmt => expr_stmt => Leaf('__meta')
  2)  clsdef => simple_stmt => expr_stmt => Leaf('__meta')
r   __metaclass__TF)
childrentyper   suitehas_metaclasssimple_stmt	expr_stmt
isinstancer   value)parentnode	expr_node	left_sides       _/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/libfuturize/fixes/fix_metaclass.pyr   r   &   s     99

" &&YY$***t}}}a(I~~/I4F4F4F%..q1	i..!?:       c                 8   U R                    H#  nUR                  [        R                  :X  d  M#    g   [	        U R                   5       H%  u  p!UR                  [
        R                  :X  d  M%    O   [        S5      e[        [        R                  / 5      nU R                   US-   S (       aZ  U R                   US-      nUR                  UR                  5       5        UR                  5         U R                   US-   S (       a  MZ  U R                  U5        Ung)zYone-line classes don't get a suite in the parse tree so we add
one to normalize the tree
NzNo class suite and no ':'!   )r   r   r   r   	enumerater   COLON
ValueErrorr   append_childcloneremove)cls_noder   ir   	move_nodes        r   fixup_parse_treer)   9   s     !!99

" " X../99# 0 566 R E


AaCD
!%%ac*	9??,- 

AaCD
!
! % Dr   c                    [        UR                  5       H%  u  p4UR                  [        R                  :X  d  M%    O   gUR                  5         [        [        R                  / 5      n[        [        R                  U/5      nUR                  US (       aT  UR                  U   nUR                  UR                  5       5        UR                  5         UR                  US (       a  MT  U R                  X5        UR                  S   R                  S   nUR                  S   R                  S   n	U	R                  Ul        g)zif there is a semi-colon all the parts count as part of the same
simple_stmt.  We just want the __metaclass__ part so we move
everything efter the semi-colon into its own simple_stmt node
Nr   )r    r   r   r   SEMIr%   r   r   r   r   r#   r$   insert_childprefix)
r   r'   	stmt_nodesemi_indr   new_exprnew_stmtr(   	new_leaf1	old_leaf1s
             r   fixup_simple_stmtr4   S   s
   
 $I$6$6799

" 8 	KKMDNNB'HD$$xj1H


XY
'&&x0	ioo/0 

XY
'
' $!!!$--a0I""1%..q1I ''Ir   c                     U R                   (       aJ  U R                   S   R                  [        R                  :X  a  U R                   S   R	                  5         g g g )N)r   r   r   NEWLINEr%   )r   s    r   remove_trailing_newliner8   k   s@    }}r*//5==@b  " A}r   c              #   j  #    U R                    H#  nUR                  [        R                  :X  d  M#    O   [	        S5      e[        [        UR                   5      5       H  u  p#UR                  [        R                  :X  d  M%  UR                   (       d  M8  UR                   S   nUR                  [        R                  :X  d  Mg  UR                   (       d  Mz  UR                   S   n[        U[        5      (       d  M  UR                  S:X  d  M  [        XU5        [        U5        XU4v   M     g 7f)NzNo class suite!r   r   )r   r   r   r   r"   listr    r   r   r   r   r   r4   r8   )r&   r   r'   simple_noder   	left_nodes         r   
find_metasr=   p   s     !!99

" " *++ y78t///K4H4H4H#,,Q/I~~/I4F4F4F%..q1	i..!+;;%d{;+K8K00 9s/   ,D3AD3D3+D3D3"D3?D3"D3c                    U R                   SSS2   nU(       a8  UR                  5       nUR                  [        R                  :X  a  O	U(       a  M8  U(       a  UR                  5       n[        U[        5      (       a7  UR                  [        R                  :w  a  UR                  (       a  SUl        gUR                  UR                   SSS2   5        U(       a  M  gg)zIf an INDENT is followed by a thing with a prefix then nuke the prefix
Otherwise we get in trouble when removing __metaclass__ at suite start
Nr6    )
r   popr   r   INDENTr   r   DEDENTr-   extend)r   kidsr   s      r   fixup_indentrE      s     >>$B$D
xxz99$ $ xxzdD!!dii5<<&?{{!KKdd+, $r   c                   "    \ rS rSrSrSrS rSrg)FixMetaclass   Tz
    classdef<any*>
    c                 	   [        U5      (       d  g [        U5        S n[        U5       H  u  pEnUnUR                  5         M     UR                  S   R
                  n[        UR                  5      S:X  a  UR                  S   R
                  [        R                  :X  a  UR                  S   nGO6UR                  S   R                  5       n	[        [        R                  U	/5      nUR                  SU5        O[        UR                  5      S:X  a-  [        [        R                  / 5      nUR                  SU5        O[        UR                  5      S:X  a  [        [        R                  / 5      nUR                  S[        [        R                  S5      5        UR                  SU5        UR                  S[        [        R                   S5      5        O[#        S	5      eUR                  S   R                  S   n
S
U
l        U
R&                  n[)        SSU5        UR                  S   R                  S   R                  5       nSUl        U/nUR                  (       a  [        UR                  5      S:X  a%  UR                  S   R                  5       nSUl        O[+        UR                  5       5      nSUl        [-        [/        S5      [1        S5      [3        5       U[3        5       [        [        R4                  [        [        R6                  S5      [        [        R8                  S5      /SS9/SS9nUR;                  [3        5       U/5        UR=                  [-        [/        SUR&                  S9U5      5        [?        W5        UR                  (       d^  UR                  5         [        US5      nUUl        URA                  U5        URA                  [        [        RB                  S5      5        g [        UR                  5      S:  a  UR                  S   R
                  [        RD                  :X  au  UR                  S   R
                  [        RF                  :X  aI  [        US5      nUR                  SU5        UR                  S[        [        RB                  S5      5        g g g g )Nr                  )(zUnexpected class definition	metaclasszfuture.utilswith_metaclassr?   r    r   z	'NewBase'{})r-   pass
r6   )$r   r)   r=   r%   r   r   lenr   arglistr$   r   	set_childr,   r   r   RPARLPARr"   r   r-   r	   r   r
   r   r   r   atomLBRACERBRACErC   replacerE   r#   r7   rA   rB   )selfr   resultslast_metaclassr   r'   stmt	text_typerZ   r   meta_txtorig_meta_prefixrQ   	argumentsbasebases	pass_leafs                    r   	transformFixMetaclass.transform   s   T"" (.NEd!NKKM / MM!$))	 t}}" }}Q$$4--* q)//1t||fX6q'*1$ 4<<,Ga)1$ 4<<,Gaejj$!78a)aejj$!78:;; "**1-66q9$#?? 	_&7>"++A.77:@@B		K	7##$)''*002"
 %W]]_5#DL;'GG		ellD14d3KL#
+ 
  egt_-"7>>:
 	
 	U ~~LLNY0I/Ii(d5==%89 1$..$))U\\9..$))U\\9Y0Ir9-r4u#=>	 : : %r    N)__name__
__module____qualname____firstlineno__BM_compatiblePATTERNrm   __static_attributes__ro   r   r   rG   rG      s    MGb?r   rG   N)__doc__lib2to3r   lib2to3.pygramr   lib2to3.fixer_utilr   r   r   r   r	   r
   r   r   r   r   r)   r4   r8   r=   rE   BaseFixrG   ro   r   r   <module>r|      sS   <        &4(0#
1.-,i?:%% i?r   