JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrJFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbrў fc@sdZdZddlZddlZddlmZddlmZddlm Z Gdd d e Z Gd d d e Z ia d d ZdS(uA 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.u+George Boutsioukis iN(u defaultdicti(upytree(u reduce_treecBs2|EeZdZdZejZddZdS(uBMNodeu?Class for a node of the Aho-Corasick automaton used in matchingcCs1i|_g|_ttj|_d|_dS(Nu(utransition_tableufixersunextuBMNodeucountuiducontent(uself((u8/opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu__init__s  uBMNode.__init__N(u__name__u __module__u __qualname__u__doc__u itertoolsucountu__init__(u __locals__((u8/opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyuBMNodes uBMNodecBsV|EeZdZdZddZddZddZdd Zd d Zd S( u BottomMatcherugThe main matcher class. After instantiating the patterns should be added using the add_fixer methodcCsFt|_t|_|jg|_g|_tjd|_dS(NuRefactoringTool( usetumatchuBMNodeurootunodesufixersuloggingu getLoggerulogger(uself((u8/opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu__init__s    uBottomMatcher.__init__cCsh|jj|t|j}|j}|j|d|j}x|D]}|jj|qJWdS(uReduces 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 reachedustartN(ufixersuappendu reduce_treeu pattern_treeuget_linear_subpatternuadduroot(uselfufixerutreeulinearu match_nodesu match_node((u8/opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu add_fixer%s   uBottomMatcher.add_fixercCs |s |gSt|dtrg}x[|dD]O}|j|d|}x1|D])}|j|j|dd|qSWq1W|S|d|jkrt}||j|d     !          uBottomMatcher.runcs7tdfdd|jtddS(u<Prints a graphviz diagram of the BM automaton(for debugging)u digraph g{csxy|jjD]h}|j|}td|j|jt|t|jf|dkrnt|jn|qWdS(Nu%d -> %d [label=%s] //%si(utransition_tableukeysuprintuidu type_reprustrufixersucontent(unodeu subnode_keyusubnode(u print_node(u8/opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu print_nodes ) u*BottomMatcher.print_ac..print_nodeu}N(uprinturoot(uself((u print_nodeu8/opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyuprint_acs  uBottomMatcher.print_acN( u__name__u __module__u __qualname__u__doc__u__init__u add_fixeruaddurunuprint_ac(u __locals__((u8/opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu BottomMatchers   " =u BottomMatchercCshtsXddlm}x?|jjD]+\}}t|tkr&|t|s