ž zyMa2c@s~dZddlZddlZddlmZddlmZddlmZGdd„de ƒZ Gd d „d e ƒZ dS( u2Base class for fixers (optional, but recommended).iNi(uPatternCompiler(upygram(udoes_tree_importcBs|EeZdZdZdZdZdZdZdZ e j dƒZ e ƒZdZdZdZdZdZdZejZdd„Zdd„Zd d „Zd d „Zd d„Zddd„Zdd„Zddd„Z dd„Z!dd„Z"dd„Z#dS(uBaseFixuOptional 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. iuposticCs ||_||_|jƒdS(uInitializer. 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(uoptionsulogucompile_pattern(uselfuoptionsulog((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyu__init__0s  uBaseFix.__init__cCsC|jdk r?tƒ}|j|jddƒ\|_|_ndS(u–Compiles self.PATTERN into self.pattern. Subclass may override if it doesn't want to use self.{pattern,PATTERN} in .match(). u with_treeNT(uPATTERNuNoneuPatternCompilerucompile_patternuTrueupatternu pattern_tree(uselfuPC((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyucompile_pattern<s uBaseFix.compile_patterncCs ||_dS(uOSet the filename. The main refactoring tool should call this. N(ufilename(uselfufilename((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyu set_filenameGsuBaseFix.set_filenamecCs&i|d6}|jj||ƒo%|S(uReturns 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. unode(upatternumatch(uselfunodeuresults((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyumatchNs u BaseFix.matchcCs tƒ‚dS(uśReturns 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(uNotImplementedError(uselfunodeuresults((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyu transformZsuBaseFix.transformuxxx_todo_changemecCsI|}x,||jkr4|tt|jƒƒ}q W|jj|ƒ|S(u†Return a string suitable for use as an identifier The new name is guaranteed not to conflict with other identifiers. (u used_namesustrunextunumbersuadd(uselfutemplateuname((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyunew_namejs uBaseFix.new_namecCs@|jr,d|_|jjd|jƒn|jj|ƒdS(Nu### In file %s ###F(u first_loguFalseuloguappendufilename(uselfumessage((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyu log_messageus  uBaseFix.log_messagecCsX|jƒ}|jƒ}d|_d}|j|||fƒ|rT|j|ƒndS(uWarn 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. uuLine %d: could not convert: %sN(u get_linenoucloneuprefixu log_message(uselfunodeureasonulinenou for_outputumsg((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyucannot_convert{s   uBaseFix.cannot_convertcCs'|jƒ}|jd||fƒdS(uŕUsed 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. u Line %d: %sN(u get_linenou log_message(uselfunodeureasonulineno((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyuwarningŠs uBaseFix.warningcCs8|j|_|j|ƒtjdƒ|_d|_dS(uîSome 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. iNT(u used_namesu set_filenameu itertoolsucountunumbersuTrueu first_log(uselfutreeufilename((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyu start_tree”s  uBaseFix.start_treecCsdS(uóSome 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((uselfutreeufilename((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyu finish_tree suBaseFix.finish_treeNF($u__name__u __module__u __qualname__u__doc__uNoneuPATTERNupatternu pattern_treeuoptionsufilenameu itertoolsucountunumbersusetu used_namesuorderuFalseuexplicitu run_orderu _accept_typeukeep_line_orderu BM_compatibleupygramupython_symbolsusymsu__init__ucompile_patternu set_filenameumatchu transformunew_nameu log_messageucannot_convertuwarningu start_treeu finish_tree(u __locals__((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyuBaseFixs4      uBaseFixcs>|EeZdZdZdZ‡fdd†Zdd„Z‡S(uConditionalFixu@ Base class for fixers which not execute if an import is found. cs#tt|ƒj|Œd|_dS(N(usuperuConditionalFixu start_treeuNoneu _should_skip(uselfuargs(u __class__(u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyu start_tree°suConditionalFix.start_treecCsg|jdk r|jS|jjdƒ}|d}dj|dd…ƒ}t|||ƒ|_|jS(Nu.ii˙˙˙˙i˙˙˙˙(u _should_skipuNoneuskip_onusplitujoinudoes_tree_import(uselfunodeupkguname((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyu should_skip´s uConditionalFix.should_skipN(u__name__u __module__u __qualname__u__doc__uNoneuskip_onu start_treeu should_skip(u __locals__((u __class__u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyuConditionalFixŞsuConditionalFix( u__doc__uloggingu itertoolsupatcompuPatternCompileruupygramu fixer_utiludoes_tree_importuobjectuBaseFixuConditionalFix(((u7/opt/alt/python33/lib64/python3.3/lib2to3/fixer_base.pyus  ›