Your IP : 3.14.134.195
�
�Q�f" � �` � d Z ddlZddlmZ ddlmZ ddlmZ G d� de� Z G d � d
e � Z
y)z2Base class for fixers (optional, but recommended).� N� )�PatternCompiler)�pygram)�does_tree_importc �� � e Zd ZdZdZdZdZdZdZ e j d� Z e� Z
dZdZdZdZdZdZej* Zd� Zd� Zd � Zd
� Zd� Zdd�Zd
� Zdd�Zd� Zd� Z d� Z!y)�BaseFixa Optional base class for fixers.
The subclass name must be FixFooBar where FooBar is the result of
removing underscores and capitalizing the words of the fix name.
For example, the class name for a fixer named 'has_key' should be
FixHasKey.
Nr �postF� c �@ � || _ || _ | j � y)a Initializer. Subclass may override.
Args:
options: a dict containing the options passed to RefactoringTool
that could be used to customize the fixer through the command line.
log: a list to append warnings and other messages to.
N)�options�log�compile_pattern)�selfr r
s �9/opt/alt/python312/lib64/python3.12/lib2to3/fixer_base.py�__init__zBaseFix.__init__/ s � � ���������� c � � | j �5t � }|j | j d�� \ | _ | _ yy)z�Compiles self.PATTERN into self.pattern.
Subclass may override if it doesn't want to use
self.{pattern,PATTERN} in .match().
NT)� with_tree)�PATTERNr r �pattern�pattern_tree)r �PCs r r zBaseFix.compile_pattern; sE � � �<�<�#� �"�B�.0�.@�.@����KO� /A� /Q�+�D�L�$�+� $r c � � || _ y)zOSet the filename.
The main refactoring tool should call this.
N)�filename)r r s r �set_filenamezBaseFix.set_filenameF s � �
!��
r c �J � d|i}| j j ||� xr |S )a Returns match for a given parse tree node.
Should return a true or false object (not necessarily a bool).
It may return a non-empty dict of matching sub-nodes as
returned by a matching pattern.
Subclass may override.
�node)r �match�r r �resultss r r z
BaseFix.matchM s) � � �4�.���|�|�!�!�$��0�<�W�<r c � � t � �)a� Returns the transformation for a given parse tree node.
Args:
node: the root of the parse tree that matched the fixer.
results: a dict mapping symbolic names to part of the match.
Returns:
None, or a node that is a modified copy of the
argument node. The node argument may also be modified in-place to
effect the same change.
Subclass *must* override.
)�NotImplementedErrorr s r � transformzBaseFix.transformY s
� � "�#�#r c � � |}|| j v r0|t t | j � � z }|| j v r�0| j j |� |S )z�Return a string suitable for use as an identifier
The new name is guaranteed not to conflict with other identifiers.
)�
used_names�str�next�numbers�add)r �template�names r �new_namezBaseFix.new_namei sR � �
���d�o�o�%��c�$�t�|�|�"4�5�5�D� �d�o�o�%������D�!��r c � � | j r/d| _ | j j d| j z � | j j |� y )NFz### In file %s ###)� first_logr
�appendr )r �messages r �log_messagezBaseFix.log_messaget s: � ��>�>�"�D�N��H�H�O�O�0�4�=�=�@�A������� r c � � |j � }|j � }d|_ d}| j |||fz � |r| j |� yy)a Warn the user that a given chunk of code is not valid Python 3,
but that it cannot be converted automatically.
First argument is the top-level node for the code in question.
Optional second argument is why it can't be converted.
� zLine %d: could not convert: %sN)�
get_lineno�clone�prefixr1 )r r �reason�lineno�
for_output�msgs r �cannot_convertzBaseFix.cannot_convertz sV � � ���"���Z�Z�\�
��
��.�������
�3�3�4�����V�$� r c �P � |j � }| j d||fz � y)z�Used for warning the user about possible uncertainty in the
translation.
First argument is the top-level node for the code in question.
Optional second argument is why it can't be converted.
zLine %d: %sN)r4 r1 )r r r7 r8 s r �warningzBaseFix.warning� s( � � ���"������&�&�)9�9�:r c � � |j | _ | j |� t j d� | _ d| _ y)z�Some fixers need to maintain tree-wide state.
This method is called once, at the start of tree fix-up.
tree - the root node of the tree to be processed.
filename - the name of the file the tree came from.
r TN)r% r � itertools�countr( r. �r �treer s r �
start_treezBaseFix.start_tree� s4 � � �/�/������(�#� ���q�)�����r c � � y)z�Some fixers need to maintain tree-wide state.
This method is called once, at the conclusion of tree fix-up.
tree - the root node of the tree to be processed.
filename - the name of the file the tree came from.
N� rA s r �finish_treezBaseFix.finish_tree� s � �
r )�xxx_todo_changeme�N)"�__name__�
__module__�__qualname__�__doc__r r r r r r? r@ r( �setr% �order�explicit� run_order�_accept_type�keep_line_order�
BM_compatibler �python_symbols�symsr r r r r# r, r1 r; r= rC rF rE r r r r s� � �� �G��G��L��G��H��i�o�o�a� �G���J��E��H��I��L� �O��M�
� � �D�
� Q�!�
=�$� �!�
%�;�
�
r r c �, � � e Zd ZdZdZ� fd�Zd� Z� xZS )�ConditionalFixz@ Base class for fixers which not execute if an import is found. Nc �4 �� t t | �
|� d | _ y rH )�superrW rC �_should_skip)r �args� __class__s �r rC zConditionalFix.start_tree� s �� �
�n�d�.��5� ��r c �� � | j �| j S | j j d� }|d }dj |d d � }t |||� | _ | j S )N�.���)rZ �skip_on�split�joinr )r r �pkgr+ s r �should_skipzConditionalFix.should_skip� sh � ����(��$�$�$��l�l� � ��%���2�w���h�h�s�3�B�x� ��,�S�$��=���� � � r )rI rJ rK rL r` rC rd �
__classcell__)r\ s @r rW rW � s �� �J� �G�!�!r rW )rL r? �patcompr r3 r �
fixer_utilr �objectr rW rE r r �<module>ri s5 �� 9� � %� � (�X
�f� X
�v!�W� !r