/usr/lib64/python3.9/lib2to3/__pycache__
NameSizeModeActions
btm_matcher.cpython-39.opt-1.pyc48770644editdlrm
btm_matcher.cpython-39.opt-2.pyc33060644editdlrm
btm_matcher.cpython-39.pyc48770644editdlrm
btm_utils.cpython-39.opt-1.pyc61480644editdlrm
btm_utils.cpython-39.opt-2.pyc46360644editdlrm
btm_utils.cpython-39.pyc61480644editdlrm
fixer_base.cpython-39.opt-1.pyc62550644editdlrm
fixer_base.cpython-39.opt-2.pyc35040644editdlrm
fixer_base.cpython-39.pyc62550644editdlrm
fixer_util.cpython-39.opt-1.pyc121700644editdlrm
fixer_util.cpython-39.opt-2.pyc100070644editdlrm
fixer_util.cpython-39.pyc121700644editdlrm
main.cpython-39.opt-1.pyc86710644editdlrm
main.cpython-39.opt-2.pyc69180644editdlrm
main.cpython-39.pyc86890644editdlrm
patcomp.cpython-39.opt-1.pyc53890644editdlrm
patcomp.cpython-39.opt-2.pyc48810644editdlrm
patcomp.cpython-39.pyc56050644editdlrm
pygram.cpython-39.opt-1.pyc12620644editdlrm
pygram.cpython-39.opt-2.pyc10570644editdlrm
pygram.cpython-39.pyc12620644editdlrm
pytree.cpython-39.opt-1.pyc236720644editdlrm
pytree.cpython-39.opt-2.pyc149690644editdlrm
pytree.cpython-39.pyc242950644editdlrm
refactor.cpython-39.opt-1.pyc206130644editdlrm
refactor.cpython-39.opt-2.pyc165670644editdlrm
refactor.cpython-39.pyc206430644editdlrm
__init__.cpython-39.opt-1.pyc3020644editdlrm
__init__.cpython-39.opt-2.pyc3020644editdlrm
__init__.cpython-39.pyc3020644editdlrm
__main__.cpython-39.opt-1.pyc2150644editdlrm
__main__.cpython-39.opt-2.pyc2150644editdlrm
__main__.cpython-39.pyc2150644editdlrm
Edit: /usr/lib64/python3.9/lib2to3/__pycache__/btm_matcher.cpython-39.opt-1.pyc (4877B)
a ´ißã@sldZdZddlZddlZddlmZddlmZddlm Z Gdd „d e ƒZ Gd d „d e ƒZ ia d d „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 eZdZdZe ¡Zdd„ZdS)ÚBMNodez?Class for a node of the Aho-Corasick automaton used in matchingcCs"i|_g|_ttjƒ|_d|_dS)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 rrrrrrsrc@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) Ú BottomMatcherzgThe main matcher class. After instantiating the patterns should be added using the add_fixer methodcCs0tƒ|_tƒ|_|jg|_g|_t d¡|_dS)NZRefactoringTool) ÚsetÚmatchrÚrootZnodesr ÚloggingÚ getLoggerÚloggerrrrrrs  zBottomMatcher.__init__cCsH|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 ÚappendrZ pattern_treeZget_linear_subpatternÚaddr)rÚfixerZtreeZlinearÚ match_nodesZ match_noderrrÚ add_fixer%s   zBottomMatcher.add_fixerc CsÄ|s |gSt|dtƒr`g}|dD]6}|j||d�}|D]}| | |dd…|¡¡q:q$|S|d|jvr„tƒ}||j|d<n|j|d}|dd…r¶|j|dd…|d�}n|g}|SdS)z5Recursively adds a linear pattern to the AC automatonrrrN)Ú isinstanceÚtupler"Úextendrr)rÚpatternr r$Ú alternativeZ end_nodesÚendZ next_noderrrr"1s"  zBottomMatcher.addc Csî|j}ttƒ}|D]Ö}|}|rd|_|jD]$}t|tjƒr*|jdkr*d|_qPq*|j dkrb|j}n|j }||j vr˜|j |}|j D]}||  |¡q‚nH|j}|j dur²|j jr²q||j vrà|j |}|j D]}||  |¡qÌ|j }qq|S)auThe main interface with the bottom matcher. The tree is traversed from the bottom using the constructed automaton. Nodes are only checked once as the tree is retraversed. When the automaton fails, we give it one more shot(in case the above tree matches as a whole with the rejected leaf), then we break for the next leaf. There is the special case of multiple arguments(see code comments) where we recheck the nodes Args: The leaves of the AST tree to be matched Returns: A dictionary of node matches with fixers as the keys Tú;FrN)rrÚlistZ was_checkedZchildrenr&rZLeafÚvalueÚtyperr r!Úparent) rZleavesZcurrent_ac_nodeÚresultsZleafZcurrent_ast_nodeÚchildZ node_tokenr#rrrÚrunSs8      ÿ    zBottomMatcher.runcs*tdƒ‡fdd„‰ˆ|jƒtdƒdS)z %d [label=%s] //%sr)rÚkeysÚprintr Ú type_reprÚstrr r )ZnodeZ subnode_keyZsubnode©Ú print_noderrr9Žs ÿ z*BottomMatcher.print_ac..print_nodeú}N)r5rrrr8rÚprint_ac‹s  zBottomMatcher.print_acN) rrrrrr%r"r3r;rrrrrs  "8rcCsDts8ddlm}|j ¡D]\}}t|ƒtkr|t|<qt ||¡S)Nr)Úpython_symbols)Ú _type_reprsZpygramr<Ú__dict__Úitemsr/ÚintÚ setdefault)Ztype_numr<ÚnameÚvalrrrr6›s  r6)rÚ __author__rrÚ collectionsrrrZ btm_utilsrÚobjectrrr=r6rrrrÚs