Your IP : 18.221.147.141


Current Path : /opt/alt/python312/lib64/python3.12/lib2to3/fixes/__pycache__/
Upload File :
Current File : //opt/alt/python312/lib64/python3.12/lib2to3/fixes/__pycache__/fix_metaclass.cpython-312.opt-1.pyc

�

�Q�f ���dZddlmZddlmZddlmZmZmZd�Z	d�Z
d�Zd�Zd	�Z
d
�ZGd�dej�Zy
)a�Fixer for __metaclass__ = X -> (metaclass=X) methods.

   The various forms of classef (inherits nothing, inherits once, inherits
   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)�syms�Node�Leafc��|jD]�}|jtjk(r
t	|�cS|jtj
k(s�K|js�X|jd}|jtjk(s��|js��|jd}t|t�s��|jdk(s��yy)z� we 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')
    ��
__metaclass__TF)
�children�typer�suite�
has_metaclass�simple_stmt�	expr_stmt�
isinstancer�value)�parent�node�	expr_node�	left_sides    �B/opt/alt/python312/lib64/python3.12/lib2to3/fixes/fix_metaclass.pyrrs��������9�9��
�
�"� ��&�&�
�Y�Y�$�*�*�
*�t�}�}��
�
�a�(�I��~�~����/�I�4F�4F�%�.�.�q�1�	��i��.�!���?�:�� ��c��|jD]!}|jtjk(s�!yt	|j�D]$\}}|jt
jk(s�$ntd��ttjg�}|j|dzdrT|j|dz}|j|j��|j�|j|dzdr�T|j|�|}y)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 ':'!�)rrrr
�	enumerater�COLON�
ValueErrorr�append_child�clone�remove)�cls_noder�ir
�	move_nodes     r�fixup_parse_treer$-s����!�!���9�9��
�
�"��"��X�.�.�/���4��9�9����#��0��5�6�6�
����R� �E�
�
�
�A�a�C�D�
!��%�%�a��c�*�	�
���9�?�?�,�-������
�
�A�a�C�D�
!�
���%� ��Drc�x�t|j�D]$\}}|jtjk(s�$ny|j�t
tjg�}t
tj|g�}|j|drN|j|}|j|j��|j�|j|dr�N|j||�|jdjd}|jdjd}	|	j|_
y)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 after the semi-colon into its own simple_stmt node
    Nr	)rrrr�SEMIr rrrrrr�insert_child�prefix)
rr"�	stmt_node�semi_indr�new_expr�new_stmtr#�	new_leaf1�	old_leaf1s
          r�fixup_simple_stmtr/Gs��
$�I�$6�$6�7���$��9�9��
�
�"��8�	��K�K�M��D�N�N�B�'�H��D�$�$�x�j�1�H�
�
�
�X�Y�
'��&�&�x�0�	����i�o�o�/�0������
�
�X�Y�
'�����8�$��!�!�!�$�-�-�a�0�I��"�"�1�%�.�.�q�1�I� �'�'�I�rc��|jrI|jdjtjk(r|jdj	�yyy)N���)rrr�NEWLINEr )rs r�remove_trailing_newliner3_s@���}�}����r�*�/�/�5�=�=�@��
�
�b�� � �"�A�}rc#�6K�|jD]!}|jtjk(s�!nt	d��tt
|j��D]�\}}|jtjk(s�$|js�1|jd}|jtjk(s�^|js�k|jd}t|t�s��|jdk(s��t|||�t|�|||f����y�w)NzNo class suite!r	r
)rrrr
r�listrrrrrrr/r3)r!rr"�simple_noder�	left_nodes      r�
find_metasr8ds������!�!���9�9��
�
�"��"��*�+�+��y����7�8���;����t�/�/�/�K�4H�4H�#�,�,�Q�/�I��~�~����/�I�4F�4F�%�.�.�q�1�	��i��.�!���?�:�%�d�A�{�;�+�K�8���K�0�0�9�s/�-D�AD�D�
,D�:D�D�'D�7"Dc�~�|jddd�}|r1|j�}|jtjk(rn|r�1|rv|j�}t|t�r1|jtjk7r|jrd|_y|j|jddd��|r�uyy)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
    Nr1�)
r�poprr�INDENTrr�DEDENTr(�extend)r
�kidsrs   r�fixup_indentr@{s����>�>�$�B�$��D�
��x�x�z���9�9����$�����x�x�z���d�D�!�d�i�i�5�<�<�&?��{�{� �����K�K��
�
�d��d�+�,�rc��eZdZdZdZd�Zy)�FixMetaclassTz
    classdef<any*>
    c��t|�syt|�d}t|�D]\}}}|}|j��|jdj
}t
|j�dk(r�|jdj
tjk(r|jd}�n4|jdj�}	ttj|	g�}|jd|�n�t
|j�dk(r-ttjg�}|jd|�n�t
|j�dk(r�ttjg�}|jdttjd��|jd|�|jdttj d��nt#d	��|jdjd}
d
|
_|
j&}|jr1|j)ttj*d��d|
_nd
|
_|jd}d
|jd_d
|jd_|j)|�t-�|js^|j�t|d�}
||
_|j)|
�|j)ttj.d��yt
|j�dkDr�|jdj
tj0k(rt|jdj
tj2k(rIt|d�}
|jd|
�|jdttj.d��yyyy)Nr	����r�)�(zUnexpected class definition�	metaclass�,� r:r�pass�
���r1)rr$r8r rr�lenr�arglistrr�	set_childr'rr�RPAR�LPARrrr(r�COMMAr@r2r<r=)�selfr�results�last_metaclassr
r"�stmt�	text_typerQr�meta_txt�orig_meta_prefixr�	pass_leafs              r�	transformzFixMetaclass.transform�s����T�"�������(��.�N�E�1�d�!�N��K�K�M�/��M�M�!�$�)�)�	��t�}�}���"��}�}�Q��$�$����4��-�-��*�����q�)�/�/�1���t�|�|�f�X�6�����q�'�*�
����
�1�
$��4�<�<��,�G����a��)�
����
�1�
$��4�<�<��,�G����a��e�j�j�#�!6�7����a��)����a��e�j�j�#�!6�7��:�;�;�"�*�*�1�-�6�6�q�9��$���#�?�?������ � ��e�k�k�3�!7�8�!�H�O� �H�O�#�+�+�A�.�	�')�	���1��$�')�	���1��$����^�,��U���~�~��L�L�N��Y��/�I�/�I�����i�(����d�5�=�=�$�7�8�
����
 �1�
$��.�.��$�)�)�U�\�\�9��.�.��$�)�)�U�\�\�9��Y��/�I����r�9�-����r�4��
�
�t�#<�=�	:�:�%rN)�__name__�
__module__�__qualname__�
BM_compatible�PATTERNr^�rrrBrB�s���M��G�L>rrBN)�__doc__r:r�pygramr�
fixer_utilrrrrr$r/r3r8r@�BaseFixrBrdrr�<module>risJ���(��)�)��&�4(�0#�
1�.-�,S>�:�%�%�S>r

?>