/usr/lib64/python3.9/lib2to3/__pycache__
Edit: /usr/lib64/python3.9/lib2to3/__pycache__/btm_matcher.cpython-39.pyc (4877B)
a
´iß ã @ sl d Z dZddlZddlZddlmZ ddlmZ ddlm Z G dd „ d e
ƒZG d
d„ de
ƒZi a
dd
„ ZdS )aŒ A bottom-up tree matching algorithm implementation meant to speed
up 2to3's matching process. After the tree patterns are reduced to
their rarest linear path, a linear Aho-Corasick automaton is
created. The linear automaton traverses the linear paths from the
leaves to the root of the AST and returns a set of nodes for further
matching. This reduces significantly the number of candidate nodes.z+George Boutsioukis
é N)Údefaultdicté )Úpytree)Úreduce_treec @ s e Zd ZdZe ¡ Zdd„ ZdS )ÚBMNodez?Class for a node of the Aho-Corasick automaton used in matchingc C s" i | _ g | _ttjƒ| _d| _d S )NÚ )Útransition_tableÚfixersÚnextr ÚcountÚidÚcontent©Úself© r ú+/usr/lib64/python3.9/lib2to3/btm_matcher.pyÚ__init__ s zBMNode.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú itertoolsr r r r r r r s r c @ s8 e Zd ZdZdd„ Zdd„ Zdd„ Zdd „ Zd
d„ ZdS )
Ú
BottomMatcherzgThe main matcher class. After instantiating the patterns should
be added using the add_fixer methodc C s0 t ƒ | _tƒ | _| jg| _g | _t d¡| _d S )NZRefactoringTool) ÚsetÚmatchr ÚrootZnodesr ÚloggingÚ getLoggerÚloggerr r r r r s
zBottomMatcher.__init__c C sH | j |¡ t|jƒ}| ¡ }| j|| jd�}|D ]}|j |¡ q2dS )zÒReduces a fixer's pattern tree to a linear path and adds it
to the matcher(a common Aho-Corasick automaton). The fixer is
appended on the matching states and called when they are
reached©ÚstartN)r Úappendr Zpattern_treeZget_linear_subpatternÚaddr )r ÚfixerZtreeZlinearÚmatch_nodesZ
match_noder r r Ú add_fixer% s
zBottomMatcher.add_fixerc C sÄ |s
|gS t |d tƒr`g }|d D ]6}| j||d�}|D ]}| | |dd… |¡¡ q:q$|S |d |jvr„tƒ }||j|d <