ofc@s~dZddlZddlZddlmZddlmZddlmZde fdYZ d e fd YZ dS( s2Base class for fixers (optional, but recommended).iNi(tPatternCompiler(tpygram(tdoes_tree_importtBaseFixcBseZdZdZdZdZdZdZdZ e j dZ e ZdZeZdZdZeZeZejZdZdZdZdZdZd d Zd Zdd Z d Z!dZ"dZ#RS(sOptional 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. itposticCs ||_||_|jdS(sInitializer. Subclass may override. Args: options: an 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(toptionstlogtcompile_pattern(tselfRR((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyt__init__1s  cCsC|jdk r?t}|j|jdt\|_|_ndS(sCompiles self.PATTERN into self.pattern. Subclass may override if it doesn't want to use self.{pattern,PATTERN} in .match(). t with_treeN(tPATTERNtNoneRRtTruetpatternt pattern_tree(RtPC((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyR=s cCs||_tj||_dS(smSet the filename, and a logger derived from it. The main refactoring tool should call this. N(tfilenametloggingt getLoggertlogger(RR((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyt set_filenameHs cCs&i|d6}|jj||o%|S(sReturns 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. tnode(Rtmatch(RRtresults((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyRPs cCs tdS(sReturns 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. N(tNotImplementedError(RRR((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyt transform\suxxx_todo_changemecCsI|}x,||jkr4|t|jj}q W|jj||S(sReturn a string suitable for use as an identifier The new name is guaranteed not to conflict with other identifiers. (t used_namestunicodetnumberstnexttadd(Rttemplatetname((s*/usr/lib64/python2.7/lib2to3/fixer_base.pytnew_namels cCs@|jr,t|_|jjd|jn|jj|dS(Ns### In file %s ###(t first_logtFalseRtappendR(Rtmessage((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyt log_messagews  cCsX|j}|j}d|_d}|j|||f|rT|j|ndS(sWarn 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. usLine %d: could not convert: %sN(t get_linenotclonetprefixR'(RRtreasontlinenot for_outputtmsg((s*/usr/lib64/python2.7/lib2to3/fixer_base.pytcannot_convert}s   cCs'|j}|jd||fdS(sUsed 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. s Line %d: %sN(R(R'(RRR+R,((s*/usr/lib64/python2.7/lib2to3/fixer_base.pytwarnings cCs8|j|_|j|tjd|_t|_dS(sSome 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. iN(RRt itertoolstcountRR R#(RttreeR((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyt start_trees  cCsdS(sSome 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((RR3R((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyt finish_treesN($t__name__t __module__t__doc__R R RRRRRR1R2RtsetRtorderR$texplicitt run_ordert _accept_typetkeep_line_ordert BM_compatibleRtpython_symbolstsymsR RRRRR"R'R/R0R4R5(((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyRs6       tConditionalFixcBs&eZdZdZdZdZRS(s@ Base class for fixers which not execute if an import is found. cGs#tt|j|d|_dS(N(tsuperRBR4R t _should_skip(Rtargs((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyR4scCsa|jdk r|jS|jjd}|d}dj|d }t||||_|jS(Nt.i(RDR tskip_ontsplittjoinR(RRtpkgR!((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyt should_skips N(R6R7R8R RGR4RK(((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyRBs ( R8RR1tpatcompRtRt fixer_utilRtobjectRRB(((s*/usr/lib64/python2.7/lib2to3/fixer_base.pyts