g"`dZddlZddlmZddlmZddlmZGddeZ Gd d e Z y) z2Base class for fixers (optional, but recommended).N)PatternCompiler)pygram)does_tree_importceZdZdZdZdZdZdZdZe jdZ e Z dZdZdZdZdZdZej*ZdZdZd Zd Zd Zdd Zd ZddZdZdZ dZ!y)BaseFixaOptional 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. NrpostFc@||_||_|jy)aInitializer. 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)optionslogcompile_pattern)selfr r s 9/opt/alt/python312/lib64/python3.12/lib2to3/fixer_base.py__init__zBaseFix.__init__/s  c|j5t}|j|jd\|_|_yy)zCompiles self.PATTERN into self.pattern. Subclass may override if it doesn't want to use self.{pattern,PATTERN} in .match(). NT) with_tree)PATTERNrrpattern pattern_tree)rPCs rrzBaseFix.compile_pattern;sE << # "B.0.@.@KO/A/Q +DL$+ $rc||_y)zOSet the filename. The main refactoring tool should call this. N)filename)rrs r set_filenamezBaseFix.set_filenameFs ! rcJd|i}|jj||xr|S)aReturns 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)rmatchrrresultss rrz BaseFix.matchMs)4.||!!$0>"DN HHOO04==@ A  rc|j}|j}d|_d}|j|||fz|r|j|yy)aWarn 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_linenocloneprefixr1)rrreasonlineno for_outputmsgs rcannot_convertzBaseFix.cannot_convertzsV"ZZ\  .  334    V $ rcP|j}|jd||fzy)zUsed 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. z Line %d: %sN)r4r1)rrr7r8s rwarningzBaseFix.warnings(" &&)99:rc|j|_|j|tjd|_d|_y)zSome 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. rTN)r%r itertoolscountr(r.rtreers r start_treezBaseFix.start_trees4// (# q) rcy)zSome 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. NrAs r finish_treezBaseFix.finish_trees r)xxx_todo_changemeN)"__name__ __module__ __qualname____doc__rrrr rr?r@r(setr%orderexplicit run_order _accept_typekeep_line_order BM_compatiblerpython_symbolssymsrrrrr#r,r1r;r=rCrFrErrrrsGGLGHiooa GJ EHILOM  D  Q! =$ ! %;  rrc,eZdZdZdZfdZdZxZS)ConditionalFixz@ Base class for fixers which not execute if an import is found. Nc4tt| |d|_yrH)superrWrC _should_skip)rargs __class__s rrCzConditionalFix.start_trees nd.5 rc|j |jS|jjd}|d}dj|dd}t ||||_|jS)N.)rZskip_onsplitjoinr)rrpkgr+s r should_skipzConditionalFix.should_skipsh    ($$ $ll  %2whhs3Bx ,S$=   r)rIrJrKrLr`rCrd __classcell__)r\s@rrWrWsJG!!rrW) rLr?patcomprr3r fixer_utilrobjectrrWrErrris59%(X fX v!W!r