�
c��jf; � � � d Z ddlmZ ddlmZmZ ddlmZ ddl m
Z
d� Zd� Zd� Z
d � Zd-d�Zd� Zd
� Zd� Z e� e
� fd�Zd.d�Zd� Zd� Zd-d�Zd� Zd-d�Zd-d�Zd� Zd� Zd� Zd� Zd� Zh d�Z d� Z!da"da#d a$d!a%d"� Z&d#� Z'd$� Z(d%� Z)d&� Z*d'� Z+d(� Z,d)� Z-ej\ ej^ hZ0d-d*�Z1ej^ ej\ ejd hZ3d+� Z4d-d,�Z5y
)/z1Utility functions, node construction macros, etc.� )�token)�Leaf�Node)�python_symbols)�patcompc �l � t t j | t t j
d� |g� S )N�=)r �syms�argumentr r �EQUAL)�keyword�values �+/usr/lib64/python3.12/lib2to3/fixer_util.py�
KeywordArgr s* � ���
�
��$�u�{�{�C�0�%�8�:� :� c �6 � t t j d� S )N�()r r �LPAR� r r �LParenr � � ���
�
�C� � r c �6 � t t j d� S )N�))r r �RPARr r r �RParenr r r c �� � t | t � s| g} t |t � s
d|_ |g}t t j
| t
t j dd�� gz |z � S )zBuild an assignment statement� r ��prefix) �
isinstance�listr r r
�atomr r r )�target�sources r �Assignr% s] � ��f�d�#�����f�d�#���
������ � ��$�u�{�{�C��<�=�=��F�H� Hr Nc �: � t t j | |�� S )zReturn a NAME leafr )r r �NAME)�namer s r �Namer) $ s � ���
�
�D��0�0r c �N � | t t j t � |g� gS )zA node tuple for obj.attr)r r
�trailer�Dot)�obj�attrs r �Attrr/ ( s � ���d�l�l�S�U�D�M�2�3�3r c �6 � t t j d� S )zA comma leaf�,)r r �COMMAr r r �Commar3 , s � �����S�!�!r c �6 � t t j d� S )zA period (.) leaf�.)r r �DOTr r r r, r, 0 s � ��� � �3��r c �� � t t j |j � |j � g� }| r*|j dt t j
| � � |S )z-A parenthesised argument list, used by Call()r )r r
r+ �clone�insert_child�arglist)�args�lparen�rparen�nodes r �ArgListr? 4 sF � �����v�|�|�~�v�|�|�~�>�?�D�����!�T�$�,�,��5�6��Kr c �b � t t j | t |� g� }|�||_ |S )zA function call)r r
�powerr? r )� func_namer; r r> s r �CallrC ; s- � ���
�
�Y���
�6�7�D�
������Kr c �6 � t t j d� S )zA newline literal�
�r r �NEWLINEr r r �NewlinerH B s � ���
�
�t�$�$r c �6 � t t j d� S )zA blank line� rF r r r � BlankLinerK F s � ���
�
�r�"�"r c �: � t t j | |�� S )Nr )r r �NUMBER)�nr s r �NumberrO J s � �����a��/�/r c � � t t j t t j
d� | t t j d� g� S )zA numeric or string subscript�[�])r r
r+ r r �LBRACE�RBRACE)�
index_nodes r � SubscriptrV M s8 � �����t�E�L�L�#�6�)�#�E�L�L�#�6�8� 9� 9r c �: � t t j | |�� S )z
A string leafr )r r �STRING)�stringr s r �StringrZ S s � �����f�V�4�4r c �h � d| _ d|_ d|_ t t j d� }d|_ t t j d� }d|_ ||||g}|rSd|_ t t j d� }d|_ |j t t j ||g� � t t j | t t j |� g� }t t j t t j d� |t t j d� g� S )zuA list comprehension of the form [xp for fp in it if test].
If test is None, the "if test" part is omitted.
rJ r �for�in�ifrQ rR )
r r r r' �appendr r
�comp_if� listmaker�comp_forr" rS rT ) �xp�fp�it�test�for_leaf�in_leaf�
inner_args�if_leaf�inners r �ListComprl W s� � �
�B�I��B�I��B�I��E�J�J��&�H��H�O��5�:�:�t�$�G��G�N��B���,�J������u�z�z�4�(��������$�t�|�|�g�t�_�=�>�����"�d�4�=�=�*�&E�!F�G�E��� � ��U�\�\�3�/���U�\�\�3�/�1�2� 2r c �< � |D ] }|j � � t t j d� t t j | d�� t t j dd�� t t
j |� g}t t
j |� }|S )zO Return an import statement in the form:
from package import name_leafs�fromr r �import)�remover r r' r r
�import_as_names�import_from)�package_name�
name_leafs�leaf�children�imps r �
FromImportrx o sw � � �����
� � �U�Z�Z��(��U�Z�Z��c�:��U�Z�Z��#�6��T�)�)�:�6�8�H� �t����
*�C��Jr c �N � |d j � }|j t j k( r|j � }n)t t j |j � g� }|d }|r|D �cg c] }|j � �� }}t t j
t
t |d � t |d � � t t j |d j � ||d j � g� gz |z � }| j |_ |S c c}w )zfReturns an import statement and calls a method
of the module:
import module
module.name()r- �after� r �lpar�rpar)
r8 �typer
r: r rA r/ r) r+ r )r> �results�namesr- �
newarglistrz rN �news r �
ImportAndCallr� � s� � � �%�.�
�
�
�C�
�x�x�4�<�<���Y�Y�[�
��$�,�,�����
�6�
��G��E��$)�*�E�q�����E��*�
�t�z�z��D��q��N�D��q��N�3��T�\�\��f�o�+�+�-� ��f�o�+�+�-�/�0� 1�1� 49� 9�:�C� ���C�J��J�� +s �6D"c �� � t | t � r"| j t � t � gk( ryt | t � xr� t | j � dk( xr� t | j d t � xrx t | j d t � xrY t | j d t � xr: | j d j dk( xr | j d j dk( S )z(Does the node represent a tuple literal?T� r{ r � r r )r r rv r r �lenr r �r> s r �is_tupler� � s� � ��$���$�-�-�F�H�f�h�3G�"G���t�T�"�
.��D�M�M�"�a�'�
.��4�=�=��+�T�2�
.� �4�=�=��+�T�2�
.� �4�=�=��+�T�2�
.�
�
�
�a� �&�&�#�-�
.� �
�
�a� �&�&�#�-�
/r c �J � t | t � xr� t | j � dkD xrx t | j d t � xrY t | j d t � xr: | j d j
dk( xr | j d j
dk( S )z'Does the node represent a list literal?r r{ �����rQ rR )r r r� rv r r r� s r �is_listr� � s� � ��t�T�"�
/��D�M�M�"�Q�&�
/��4�=�=��+�T�2�
/� �4�=�=��,�d�3�
/� �
�
�a� �&�&�#�-�
/�
�
�
�b�!�'�'�3�.�0r c �\ � t t j t � | t � g� S �N)r r
r" r r r� s r �parenthesizer� � s � ��� � �F�H�d�F�H�5�6�6r >
�all�any�max�min�set�sumr! �tuple�sorted� enumeratec # �P K � t | |� }|r|�� t ||� }|r�yy�w)al Follow an attribute chain.
If you have a chain of objects where a.foo -> b, b.foo-> c, etc,
use this to iterate over all objects in the chain. Iteration is
terminated by getattr(x, attr) is None.
Args:
obj: the starting object
attr: the name of the chaining attribute
Yields:
Each successive object in the chain.
N)�getattr)r- r. �nexts r �
attr_chainr� � s- � �� � �3���D�
��
��t�T�"�� �s �!&�&zefor_stmt< 'for' any 'in' node=any ':' any* >
| comp_for< 'for' any 'in' node=any any* >
z�
power<
( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
trailer< '(' node=any ')' >
any*
>
z`
power<
( 'sorted' | 'enumerate' )
trailer< '(' arglist