bg`%dZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZdZdZdZdZd Zd ZGd d ejZd S)aFixer 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) NamesymsNodeLeaf touch_importCallStringComma parenthesizecP|jD]}|jtjkrt |cS|jtjkr`|jrY|jd}|jtjkr7|jr0|jd}t|tr|j dkrdSdS)z we have to check the cls_node without changing it. There are two possiblities: 1) clsdef => suite => simple_stmt => expr_stmt => Leaf('__meta') 2) clsdef => simple_stmt => expr_stmt => Leaf('__meta') r __metaclass__TF) childrentypersuite has_metaclass simple_stmt expr_stmt isinstancervalue)parentnode expr_node left_sides p/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/libfuturize/fixes/fix_metaclass.pyrr&s     9 " " && & & & Y$* * *t} * a(I~//I4F/%.q1 i.. !?::44 5c |jD]}|jtjkrdSt |jD]\}}|jt jkrntdttjg}|j|dzdr]|j|dz}| | | |j|dzd]| ||}dS)zf one-line classes don't get a suite in the parse tree so we add one to normalize the tree NzNo class suite and no ':'!) rrrr enumeraterCOLON ValueErrorr append_childcloneremove)cls_noderir move_nodes rfixup_parse_treer)9s ! 9 " " FF # X.//774 9 # # E $5666 R E  AaCDD !%ac*  9??,,---  AaCDD ! %   DDDrcnt|jD]\}}|jtjkrndS|t tjg}t tj |g}|j|drW|j|}| | ||j|dW| |||jdjd}|jdjd} | j |_ dS)z if 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 rrrSEMIr%rrrrr#r$ insert_childprefix) rr' stmt_nodesemi_indrnew_exprnew_stmtr( new_leaf1 old_leaf1s rfixup_simple_stmtr4Ss. $I$677$ 9 " " E # KKMMMDNB''HD$xj11H  XYY '&x0 ioo//000  XYY ' 8$$$!!$-a0I"1%.q1I 'Irc|jrA|jdjtjkr#|jddSdSdS)N)rrrNEWLINEr%)rs rremove_trailing_newliner8ksQ }#r*/5=@@ b  """""##@@rc#K|jD]}|jtjkrnt dt t |jD]\}}|jtjkr|jr}|jd}|jtjkr[|jrT|jd}t|tr2|j dkr't|||t||||fVdS)NzNo class suite!rr)rrrrr"listr rrrrrr4r8)r&rr' simple_noder left_nodes r find_metasr=ps!,, 9 " " E #*+++y7788 1 1;  t/ / /K4H /#,Q/I~//I4F/%.q1 i..1!+;;;%dA{;;;+K888K0000 1 1rcp|jddd}|r,|}|jtjkrn|,|ru|}t |t r%|jtjkr|jrd|_dS| |jddd|sdSdS)z If 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) rpoprrINDENTrrDEDENTr-extend)rkidsrs r fixup_indentrEs >$$B$ D xxzz 9 $ $   -xxzz dD ! ! -di5<&?&?{ "! F KK ddd+ , , , -----rceZdZdZdZdZdS) FixMetaclassTz classdef c t|sdSt|d}t|D]\}}}|}||jdj}t |jdkr|jdjtjkr|jd}nN|jd } ttj| g}| d|nt |jdkr1ttjg}| d|nt |jdkrttjg}| dttjd| d|| dttjdnt#d |jdjd} d | _| j} t)d d ||jdjd } d | _| g} |jrt |jdkr'|jd }d|_nt+| }d|_t-t/dt1dt3|t3ttjttjdttjdgdgd}| t3|g|t-t/d |j| t?||jso|t|d}| |_| || ttj!ddSt |jdkr|jdjtj"krx|jdjtj#krZt|d}| d|| dttj!ddSdSdSdS)Nr)(zUnexpected class definition metaclassz future.utilswith_metaclassr?r rz 'NewBase'{})r-pass r6)$rr)r=r%rrlenrarglistr$r set_childr,rrRPARLPARr"rr-r r r rr r atomLBRACERBRACErCreplacerEr#r7rArB)selfrresultslast_metaclassrr'stmt text_typerYrmeta_txtorig_meta_prefixrP argumentsbasebases pass_leafs r transformzFixMetaclass.transformsT""  F(..  NE1d!N KKMMMMM!$)  t}   " "}Q$ 44-*q)//11t|fX66q'****   1 $ $4<,,G   a ) ) ) )   1 $ $4<,,G   aej$!7!7 8 8 8   a ) ) )   aej$!7!7 8 8 8 8:;; ;"*1-6q9$#? _&7>>>"+A.7:@@BB  K   .7#$$))'*0022" %W]]__55# DLL;''GGGG elD114 d3K3KL# +       eggt_ - - - "7> : : :      U~ ? LLNNNY00I/I    i ( ( (   d5=%88 9 9 9 9 9  1 $ $.$)U\99.$)U\99Y00I   r9 - - -   r4 u#=#= > > > > > % $9999rN)__name__ __module__ __qualname__ BM_compatiblePATTERNrlrrrGrGs4MGb?b?b?b?b?rrGN)__doc__lib2to3rlib2to3.pygramrlib2to3.fixer_utilrrrrr r r r r rr)r4r8r=rEBaseFixrGrrrrrxs><                       &4(((0### 111.---,i?i?i?i?i?:%i?i?i?i?i?r