Your IP : 52.15.241.87


Current Path : /opt/alt/python311/lib64/python3.11/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/lib2to3/__pycache__/fixer_util.cpython-311.opt-1.pyc

�

c��ff;���dZddlmZddlmZmZddlmZddl	m
Z
d�Zd�Zd�Z
d	�Zd-d�Zd�Zd
�Zd�Ze��e
��fd�Zd.d�Zd�Zd�Zd-d�Zd�Zd-d�Zd-d�Zd�Zd�Zd�Zd�Zd�Zhd�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.ej2hZ3d+�Z4d-d,�Z5d
S)/z1Utility functions, node construction macros, etc.�)�token)�Leaf�Node)�python_symbols)�patcompc�l�ttj|ttjd��|g��S)N�=)r�syms�argumentrr�EQUAL)�keyword�values  �9/opt/alt/python311/lib64/python3.11/lib2to3/fixer_util.py�
KeywordArgrs.����
��$�u�{�C�0�0�%�8�:�:�:�c�6�ttjd��S)N�()rr�LPAR�rr�LParenr�����
�C� � � rc�6�ttjd��S)N�))rr�RPARrrr�RParenrrrc	���t|t��s|g}t|t��s
d|_|g}ttj|t
tjdd���gz|z��S)zBuild an assignment statement� r	��prefix)	�
isinstance�listrrr
�atomrrr)�target�sources  r�Assignr%su���f�d�#�#������f�d�#�#����
������	��$�u�{�C��<�<�<�=�=��F�H�H�HrNc�:�ttj||���S)zReturn a NAME leafr)rr�NAME)�namers  r�Namer)$s����
�D��0�0�0�0rc�V�|ttjt��|g��gS)zA node tuple for obj.attr)rr
�trailer�Dot)�obj�attrs  r�Attrr/(s!����d�l�S�U�U�D�M�2�2�3�3rc�6�ttjd��S)zA comma leaf�,)rr�COMMArrr�Commar3,s�����S�!�!�!rc�6�ttjd��S)zA period (.) leaf�.)rr�DOTrrrr,r,0s����	�3���rc���ttj|���|���g��}|r.|�dttj|����|S)z-A parenthesised argument list, used by Call()r)rr
r+�clone�insert_child�arglist)�args�lparen�rparen�nodes    r�ArgListr?4sW�����v�|�|�~�~�v�|�|�~�~�>�?�?�D��7����!�T�$�,��5�5�6�6�6��Krc�j�ttj|t|��g��}|�||_|S)zA function call)rr
�powerr?r)�	func_namer;rr>s    r�CallrC;s0����
�Y���
�
�6�7�7�D�
������Krc�6�ttjd��S)zA newline literal�
�rr�NEWLINErrr�NewlinerHBs����
�t�$�$�$rc�6�ttjd��S)zA blank line�rFrrr�	BlankLinerKFs����
�r�"�"�"rc�:�ttj||���S)Nr)rr�NUMBER)�nrs  r�NumberrOJs�����a��/�/�/�/rc	��ttjttjd��|ttjd��g��S)zA numeric or string subscript�[�])rr
r+rr�LBRACE�RBRACE)�
index_nodes r�	SubscriptrVMs=�����t�E�L�#�6�6�)�#�E�L�#�6�6�8�9�9�9rc�:�ttj||���S)z
A string leafr)rr�STRING)�stringrs  r�StringrZSs�����f�V�4�4�4�4rc	�p�d|_d|_d|_ttjd��}d|_ttjd��}d|_||||g}|rWd|_ttjd��}d|_|�ttj||g����ttj|ttj	|��g��}ttj
ttjd��|ttj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.
    rJr�for�in�ifrQrR)
rrrr'�appendrr
�comp_if�	listmaker�comp_forr"rSrT)	�xp�fp�it�test�for_leaf�in_leaf�
inner_args�if_leaf�inners	         r�ListComprlWs��
�B�I��B�I��B�I��E�J��&�&�H��H�O��5�:�t�$�$�G��G�N��B���,�J��?�����u�z�4�(�(��������$�t�|�g�t�_�=�=�>�>�>����"�d�4�=�*�&E�&E�!F�G�G�E���	��U�\�3�/�/���U�\�3�/�/�1�2�2�2rc�@�|D]}|����ttjd��ttj|d���ttjdd���t	t
j|��g}t	t
j|��}|S)zO Return an import statement in the form:
        from package import name_leafs�fromrr�import)�removerrr'rr
�import_as_names�import_from)�package_name�
name_leafs�leaf�children�imps     r�
FromImportrxos����������
�
�
�
��U�Z��(�(��U�Z��c�:�:�:��U�Z��#�6�6�6��T�)�:�6�6�8�H��t���
*�
*�C��Jrc�l�|d���}|jtjkr|���}n-t	tj|���g��}|d}|rd�|D��}t	tjt
t|d��t|d����t	tj|d���||d���g��gz|z��}|j	|_	|S)zfReturns an import statement and calls a method
    of the module:

    import module
    module.name()r-�afterc�6�g|]}|�����Sr)r8)�.0rNs  r�
<listcomp>z!ImportAndCall.<locals>.<listcomp>�s ��*�*�*�q������*�*�*r�r�lpar�rpar)
r8�typer
r:rrAr/r)r+r)r>�results�namesr-�
newarglistrz�news       r�
ImportAndCallr��s���%�.�
�
�
 �
 �C�
�x�4�<����Y�Y�[�[�
�
��$�,������
�6�6�
��G��E��+�*�*�E�*�*�*��
�t�z��D��q��N�N�D��q��N�N�3�3��T�\��f�o�+�+�-�-� ��f�o�+�+�-�-�/�0�0�1�1�49�	9�:�:�C���C�J��Jrc���t|t��r'|jt��t	��gkrdSt|t��o�t|j��dko�t|jdt��okt|jdt��oKt|jdt��o+|jdjdko|jdjdkS)z(Does the node represent a tuple literal?T�r~r�rr)r rrvrr�lenrr�r>s r�is_tupler��s����$�����$�-�F�H�H�f�h�h�3G�"G�"G��t��t�T�"�"�
.��D�M�"�"�a�'�
.��4�=��+�T�2�2�
.��4�=��+�T�2�2�
.��4�=��+�T�2�2�	
.�
�
�a� �&�#�-�
.��
�a� �&�#�-�
/rc�4�t|t��o�t|j��dkokt|jdt��oKt|jdt��o+|jdjdko|jdjdkS)z'Does the node represent a list literal?rr~���rQrR)r rr�rvrrr�s r�is_listr��s����t�T�"�"�
/��D�M�"�"�Q�&�
/��4�=��+�T�2�2�
/��4�=��,�d�3�3�
/��
�a� �&�#�-�	
/�
�
�b�!�'�3�.�0rc�l�ttjt��|t	��g��S�N)rr
r"rrr�s r�parenthesizer��s#����	�F�H�H�d�F�H�H�5�6�6�6r>
�all�any�max�min�set�sumr!�tuple�sorted�	enumeratec#�^K�t||��}|r|V�t||��}|�dSdS)alFollow 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��sU�����3����D�
�#��
�
�
��t�T�"�"���#�#�#�#�#rzefor_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<node=any any*> ')' >
    any*
>
Fc�h�tsMtjt��atjt��atjt
��adattt
g}t
|t|d����D]*\}}i}|�||��r
|d|urdS�+dS)a Returns true if node is in an environment where all that is required
        of it is being iterable (ie, it doesn't matter if it returns a list
        or an iterator).
        See test_map_nochange in test_fixers.py for some examples and tests.
        T�parentr>F)	�
pats_builtr�compile_pattern�p0�p1�p2�zipr��match)r>�patterns�patternr�r�s     r�in_special_contextr��s�����
�
$�R�
(�
(��
�
$�R�
(�
(��
�
$�R�
(�
(���
��B��|�H��x��D�(�)C�)C�D�D���������=�=���)�)�	�g�f�o��.E�.E��4�4���5rc��|j}|�|jtjkrdS|j}|jt
jt
jfvrdS|jt
jkr|j	d|urdS|jt
j
ks;|jt
jkr(|�|jtjks|j	d|urdSdS)zG
    Check that something isn't an attribute or function name etc.
    NFr~T)
�prev_siblingr�rr6r�r
�funcdef�classdef�	expr_stmtrv�
parameters�
typedargslistr2)r>�prevr�s   r�is_probably_builtinr��s�����D���D�I���2�2��u�
�[�F�
�{�t�|�T�]�3�3�3��u�
�{�d�n�$�$����);�t�)C�)C��u�
�{�d�o�%�%�
�[�D�.�
.�
.�
�
�$�)�u�{�":�":��O�A��$�&�&��u��4rc���|�_|jtjkrAt|j��dkr)|jd}|jt
jkr|jS|j}|�_dS)zFind the indentation of *node*.Nr�rrJ)	r�r
�suiter�rvr�INDENTrr�)r>�indents  r�find_indentationr�sd��
�
��9��
�"�"�s�4�=�'9�'9�A�'=�'=��]�1�%�F��{�e�l�*�*��|�#��{���
��2rc��|jtjkr|S|���}|jdc}|_ttj|g��}||_|Sr�)r�r
r�r8r�r)r>r�r�s   r�
make_suiter�sR���y�D�J������:�:�<�<�D��+�t��F�D�K����d�V�$�$�E��E�L��Lrc��|jtjkr-|j}|st	d���|jtjk�-|S)zFind the top level namespace.z,root found before file_input node was found.)r�r
�
file_inputr��
ValueErrorr�s r�	find_rootr�&sJ���)�t��
&�
&��{���	M��K�L�L�L��)�t��
&�
&��Krc�\�t|t|��|��}t|��S)z� Returns true if name is imported from package at the
        top level of the tree which node belongs to.
        To cover the case of an import like 'import foo', use
        None for the package and 'foo' for the name. )�find_bindingr��bool)�packager(r>�bindings    r�does_tree_importr�/s'��
�4��4���'�:�:�G���=�=�rc�@�|jtjtjfvS)z0Returns true if the node is an import statement.)r�r
�import_namerrr�s r�	is_importr�7s���9��)�4�+;�<�<�<rc	�F�d�}t|��}t|||��rdSdx}}t|j��D]E\}}||��s�t|j|d���D]\}}||��sn�||z}|dkr]t|j��D]H\}}|jt
jkr.|jr'|jdjtjkr|dz}n�I|�Ott
j
ttjd��ttj|d���g��}	n+t|ttj|d���g��}	|	t��g}
|�|tt
j|
����dS)z\ Works like `does_tree_import` but adds an import statement
        if it was not imported. c�n�|jtjko |jot	|jd��S)Nr~)r�r
�simple_stmtrvr�r�s r�is_import_stmtz$touch_import.<locals>.is_import_stmt>s4���	�T�-�-�,�$�-�,��$�-��*�+�+�	-rNr~rrorr)r�r�r�rvr�r
r�rrXrr�rr'rxrHr9)r�r(r>r��root�
insert_pos�offset�idx�node2�import_rvs           r�touch_importr�;s���-�-�-��T�?�?�D����t�,�,������J���t�}�-�-���	��T��~�d�#�#�	��&�t�}�S�T�T�':�;�;�	�	�M�F�E�!�>�%�(�(�
���
��6�\�
�
��Q���"�4�=�1�1�	�	�I�C���	�T�-�-�-�$�-�-��}�Q��$���4�4� �1�W�
�������t�'����X�&�&����T�#�.�.�.�*
�����
�W�t�E�J��S�'I�'I�'I�&J�K�K������#�H����j�$�t�'7��"B�"B�C�C�C�C�Crc
�P�|jD�]}d}|jtjkrNt	||jd��r|cSt|t
|jd��|��}|r|}�n�|jtjtjfvr/t|t
|jd��|��}|r|}�nK|jtj	kr�t|t
|jd��|��}|r|}�nt|jdd���D]U\}}|jtjkr;|j
dkr0t|t
|j|dz��|��}|r|}�Vn�|jtvr|jdj
|kr|}nmt|||��r|}nY|jtjkrt|||��}n2|jtjkrt	||jd��r|}|r|s|cSt%|��r|cS��dS)	z� Returns the node which binds variable name, otherwise None.
        If optional argument package is supplied, only imports will
        be returned.
        See test cases for examples.Nrr�r�r��:�r~)rvr�r
�for_stmt�_findr�r��if_stmt�
while_stmt�try_stmtr�r�COLONr�	_def_syms�_is_import_bindingr�r�r�)r(r>r��child�retrN�i�kids        rr�r�is3��
��"�"�����:���&�&��T�5�>�!�,�-�-�
������T�:�e�n�R�.@�#A�#A�7�K�K�A��M��#��
�Z�D�L�$�/�:�
:�
:��T�:�e�n�R�.@�#A�#A�7�K�K�A��M��#��
�Z�4�=�
(�
(��T�:�e�n�Q�.?�#@�#@�'�J�J�A��
&����'���q�r�r�(:�;�;�&�&�F�A�s��x�5�;�.�.�3�9��3C�3C�(��z�%�.��1��:M�/N�/N�PW�X�X���
�A�c��	&�
�Z�9�
$�
$����):�)@�D�)H�)H��C�C�
��t�W�
5�
5�	��C�C�
�Z�4�+�
+�
+��t�U�G�4�4�C�C�
�Z�4�>�
)�
)��T�5�>�!�,�-�-�
����	��
��
�
�
���~�~�
��
�
�
���4rc���|g}|rl|���}|jdkr)|jtvr|�|j��n"|jt
jkr
|j|kr|S|�ldS)N�)�popr��_block_syms�extendrvrr'r)r(r>�nodess   rr�r��s}��
�F�E�
���y�y�{�{���9�s�?�?�t�y��;�;��L�L���'�'�'�'�
�Y�%�*�
$�
$���t�);�);��K����4rc�.�|jtjkr�|s�|jd}|jtjkr`|jD]V}|jtjkr|jdj|kr|cS�2|jtjkr|j|kr|cS�W�n{|jtjkr1|jd}|jtjkr
|j|kr|S�n5|jtjkr
|j|kr|S�n|jtj	kr�|r2t|jd�����|krdS|jd}|rtd|��rdS|jtj
krt||��r|S|jtjkr0|jd}|jtjkr
|j|kr|Sn;|jtjkr
|j|kr|S|r|jtjkr|SdS)z� Will return node if node will import name, or node
        will import * from package.  None is returned otherwise.
        See test cases for examples. rr�r�Nr��as)r�r
r�rv�dotted_as_names�dotted_as_namerrr'rr�str�stripr�rq�import_as_name�STAR)r>r(r�rwr��lastrNs       rr�r��s��
�y�D�$�$�$�W�$��m�A����8�t�+�+�+���
 �
 ���:��!4�4�4��~�a�(�.�$�6�6�#����7��Z�5�:�-�-�%�+��2E�2E��K�K�K��
 ��X��,�
,�
,��<��#�D��y�E�J�&�&�4�:��+=�+=����
�X���
#�
#��	�T�(9�(9��K��	
��d�&�	&�	&��	�s�4�=��+�,�,�2�2�4�4��?�?��4��M�!����	�u�T�1�~�~�	��4�
�V�t�+�
+�
+��d�A���
+��K�
�V�t�*�
*�
*��J�q�M�E��z�U�Z�'�'�E�K�4�,?�,?����
�V�u�z�
!�
!�a�g��o�o��K�
�	���5�:�-�-��K��4rr�)NN)6�__doc__�pgen2r�pytreerr�pygramrr
rJrrrrr%r)r/r3r,r?rCrHrKrOrVrZrlrxr�r�r�r��consuming_callsr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r+r�r�r�rrr�<module>r�s���7�7���������������*�*�*�*�*�*�������:�:�:�!�!�!�!�!�!�	H�	H�	H�1�1�1�1�4�4�4�"�"�"� � � � ����&�&�(�(���������%�%�%�#�#�#�0�0�0�0�9�9�9�5�5�5�5�2�2�2�2�0���&���8
/�
/�
/�0�0�0�7�7�7�.�.�.��#�#�#�&	�������
����&���.������������=�=�=�*D�*D�*D�Z�]�D�L�)�	�(�(�(�(�T�|�T�]�D�L�9�����'�'�'�'�'�'r

?>