Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes
lib2to3.refactor.RefactoringTool Class Reference
Inheritance diagram for lib2to3.refactor.RefactoringTool:
Inheritance graph
[legend]
Collaboration diagram for lib2to3.refactor.RefactoringTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_fixers
def log_error
def log_message
def log_debug
def print_output
def refactor
def refactor_dir
def refactor_file
def refactor_string
def refactor_stdin
def refactor_tree
def traverse_by
def processed_file
def write_file
def refactor_docstring
def refactor_doctest
def summarize
def parse_block
def wrap_toks
def gen_lines

Public Attributes

 fixers
 explicit
 options
 grammar
 errors
 logger
 fixer_log
 wrote
 driver
 post_order
 files
 BM
 bmi_pre_order
 bmi_post_order
 bmi_pre_order_heads
 bmi_post_order_heads
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

string CLASS_PREFIX = "Fix"
string FILE_PREFIX = "fix_"
string PS1 = ">>> "
string PS2 = "... "

Private Member Functions

def _read_python_source

Static Private Attributes

dictionary _default_options = {"print_function" : False}

Detailed Description

Definition at line 174 of file refactor.py.


Constructor & Destructor Documentation

def lib2to3.refactor.RefactoringTool.__init__ (   self,
  fixer_names,
  options = None,
  explicit = None 
)
Initializer.

Args:
    fixer_names: a list of fixers to import
    options: an dict with configuration.
    explicit: a list of fixers to run even if they are explicit.

Definition at line 181 of file refactor.py.

00181 
00182     def __init__(self, fixer_names, options=None, explicit=None):
00183         """Initializer.
00184 
00185         Args:
00186             fixer_names: a list of fixers to import
00187             options: an dict with configuration.
00188             explicit: a list of fixers to run even if they are explicit.
00189         """
00190         self.fixers = fixer_names
00191         self.explicit = explicit or []
00192         self.options = self._default_options.copy()
00193         if options is not None:
00194             self.options.update(options)
00195         if self.options["print_function"]:
00196             self.grammar = pygram.python_grammar_no_print_statement
00197         else:
00198             self.grammar = pygram.python_grammar
00199         self.errors = []
00200         self.logger = logging.getLogger("RefactoringTool")
00201         self.fixer_log = []
00202         self.wrote = False
00203         self.driver = driver.Driver(self.grammar,
00204                                     convert=pytree.convert,
00205                                     logger=self.logger)
00206         self.pre_order, self.post_order = self.get_fixers()
00207 
00208 
00209         self.files = []  # List of files that were or should be modified
00210 
00211         self.BM = bm.BottomMatcher()
00212         self.bmi_pre_order = [] # Bottom Matcher incompatible fixers
00213         self.bmi_post_order = []
00214 
00215         for fixer in chain(self.post_order, self.pre_order):
00216             if fixer.BM_compatible:
00217                 self.BM.add_fixer(fixer)
00218                 # remove fixers that will be handled by the bottom-up
00219                 # matcher
00220             elif fixer in self.pre_order:
00221                 self.bmi_pre_order.append(fixer)
00222             elif fixer in self.post_order:
00223                 self.bmi_post_order.append(fixer)
00224 
00225         self.bmi_pre_order_heads = _get_headnode_dict(self.bmi_pre_order)
00226         self.bmi_post_order_heads = _get_headnode_dict(self.bmi_post_order)
00227 
00228 

Here is the caller graph for this function:


Member Function Documentation

def lib2to3.refactor.RefactoringTool._read_python_source (   self,
  filename 
) [private]
Do our best to decode a Python source file correctly.

Definition at line 318 of file refactor.py.

00318 
00319     def _read_python_source(self, filename):
00320         """
00321         Do our best to decode a Python source file correctly.
00322         """
00323         try:
00324             f = open(filename, "rb")
00325         except IOError as err:
00326             self.log_error("Can't open %s: %s", filename, err)
00327             return None, None
00328         try:
00329             encoding = tokenize.detect_encoding(f.readline)[0]
00330         finally:
00331             f.close()
00332         with _open_with_encoding(filename, "r", encoding=encoding) as f:
00333             return _from_system_newlines(f.read()), encoding

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.gen_lines (   self,
  block,
  indent 
)
Generates lines as expected by tokenize from a list of lines.

This strips the first len(indent + self.PS1) characters off each line.

Definition at line 665 of file refactor.py.

00665 
00666     def gen_lines(self, block, indent):
00667         """Generates lines as expected by tokenize from a list of lines.
00668 
00669         This strips the first len(indent + self.PS1) characters off each line.
00670         """
00671         prefix1 = indent + self.PS1
00672         prefix2 = indent + self.PS2
00673         prefix = prefix1
00674         for line in block:
00675             if line.startswith(prefix):
00676                 yield line[len(prefix):]
00677             elif line == prefix.rstrip() + "\n":
00678                 yield "\n"
00679             else:
00680                 raise AssertionError("line=%r, prefix=%r" % (line, prefix))
00681             prefix = prefix2
00682         while True:
00683             yield ""
00684 

Here is the caller graph for this function:

Inspects the options to load the requested patterns and handlers.

Returns:
  (pre_order, post_order), where pre_order is the list of fixers that
  want a pre-order AST traversal, and post_order is the list that want
  post-order traversal.

Definition at line 229 of file refactor.py.

00229 
00230     def get_fixers(self):
00231         """Inspects the options to load the requested patterns and handlers.
00232 
00233         Returns:
00234           (pre_order, post_order), where pre_order is the list of fixers that
00235           want a pre-order AST traversal, and post_order is the list that want
00236           post-order traversal.
00237         """
00238         pre_order_fixers = []
00239         post_order_fixers = []
00240         for fix_mod_path in self.fixers:
00241             mod = __import__(fix_mod_path, {}, {}, ["*"])
00242             fix_name = fix_mod_path.rsplit(".", 1)[-1]
00243             if fix_name.startswith(self.FILE_PREFIX):
00244                 fix_name = fix_name[len(self.FILE_PREFIX):]
00245             parts = fix_name.split("_")
00246             class_name = self.CLASS_PREFIX + "".join([p.title() for p in parts])
00247             try:
00248                 fix_class = getattr(mod, class_name)
00249             except AttributeError:
00250                 raise FixerError("Can't find %s.%s" % (fix_name, class_name))
00251             fixer = fix_class(self.options, self.fixer_log)
00252             if fixer.explicit and self.explicit is not True and \
00253                     fix_mod_path not in self.explicit:
00254                 self.log_message("Skipping implicit fixer: %s", fix_name)
00255                 continue
00256 
00257             self.log_debug("Adding transformation: %s", fix_name)
00258             if fixer.order == "pre":
00259                 pre_order_fixers.append(fixer)
00260             elif fixer.order == "post":
00261                 post_order_fixers.append(fixer)
00262             else:
00263                 raise FixerError("Illegal fixer order: %r" % fixer.order)
00264 
00265         key_func = operator.attrgetter("run_order")
00266         pre_order_fixers.sort(key=key_func)
00267         post_order_fixers.sort(key=key_func)
00268         return (pre_order_fixers, post_order_fixers)

Here is the call graph for this function:

def lib2to3.refactor.RefactoringTool.log_debug (   self,
  msg,
  args 
)

Definition at line 279 of file refactor.py.

00279 
00280     def log_debug(self, msg, *args):
00281         if args:
00282             msg = msg % args
00283         self.logger.debug(msg)

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.log_error (   self,
  msg,
  args,
  kwds 
)
Called when an error occurs.

Reimplemented in lib2to3.main.StdoutRefactoringTool.

Definition at line 269 of file refactor.py.

00269 
00270     def log_error(self, msg, *args, **kwds):
00271         """Called when an error occurs."""
00272         raise

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.log_message (   self,
  msg,
  args 
)
Hook to log a message.

Definition at line 273 of file refactor.py.

00273 
00274     def log_message(self, msg, *args):
00275         """Hook to log a message."""
00276         if args:
00277             msg = msg % args
00278         self.logger.info(msg)

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.parse_block (   self,
  block,
  lineno,
  indent 
)
Parses a block into a tree.

This is necessary to get correct line number / offset information
in the parser diagnostics and embedded into the parse tree.

Definition at line 641 of file refactor.py.

00641 
00642     def parse_block(self, block, lineno, indent):
00643         """Parses a block into a tree.
00644 
00645         This is necessary to get correct line number / offset information
00646         in the parser diagnostics and embedded into the parse tree.
00647         """
00648         tree = self.driver.parse_tokens(self.wrap_toks(block, lineno, indent))
00649         tree.future_features = frozenset()
00650         return tree

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.print_output (   self,
  old_text,
  new_text,
  filename,
  equal 
)
Called with the old version, new version, and filename of a
refactored file.

Reimplemented in lib2to3.main.StdoutRefactoringTool.

Definition at line 284 of file refactor.py.

00284 
00285     def print_output(self, old_text, new_text, filename, equal):
00286         """Called with the old version, new version, and filename of a
00287         refactored file."""
00288         pass

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.processed_file (   self,
  new_text,
  filename,
  old_text = None,
  write = False,
  encoding = None 
)
Called when a file has been refactored, and there are changes.

Definition at line 503 of file refactor.py.

00503 
00504                        encoding=None):
00505         """
00506         Called when a file has been refactored, and there are changes.
00507         """
00508         self.files.append(filename)
00509         if old_text is None:
00510             old_text = self._read_python_source(filename)[0]
00511             if old_text is None:
00512                 return
00513         equal = old_text == new_text
00514         self.print_output(old_text, new_text, filename, equal)
00515         if equal:
00516             self.log_debug("No changes to %s", filename)
00517             return
00518         if write:
00519             self.write_file(new_text, filename, old_text, encoding)
00520         else:
00521             self.log_debug("Not writing changes to %s", filename)

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.refactor (   self,
  items,
  write = False,
  doctests_only = False 
)
Refactor a list of files and directories.

Definition at line 289 of file refactor.py.

00289 
00290     def refactor(self, items, write=False, doctests_only=False):
00291         """Refactor a list of files and directories."""
00292 
00293         for dir_or_file in items:
00294             if os.path.isdir(dir_or_file):
00295                 self.refactor_dir(dir_or_file, write, doctests_only)
00296             else:
00297                 self.refactor_file(dir_or_file, write, doctests_only)

Here is the call graph for this function:

def lib2to3.refactor.RefactoringTool.refactor_dir (   self,
  dir_name,
  write = False,
  doctests_only = False 
)
Descends down a directory and refactor every Python file found.

Python files are assumed to have a .py extension.

Files and subdirectories starting with '.' are skipped.

Definition at line 298 of file refactor.py.

00298 
00299     def refactor_dir(self, dir_name, write=False, doctests_only=False):
00300         """Descends down a directory and refactor every Python file found.
00301 
00302         Python files are assumed to have a .py extension.
00303 
00304         Files and subdirectories starting with '.' are skipped.
00305         """
00306         py_ext = os.extsep + "py"
00307         for dirpath, dirnames, filenames in os.walk(dir_name):
00308             self.log_debug("Descending into %s", dirpath)
00309             dirnames.sort()
00310             filenames.sort()
00311             for name in filenames:
00312                 if (not name.startswith(".") and
00313                     os.path.splitext(name)[1] == py_ext):
00314                     fullname = os.path.join(dirpath, name)
00315                     self.refactor_file(fullname, write, doctests_only)
00316             # Modify dirnames in-place to remove subdirs with leading dots
00317             dirnames[:] = [dn for dn in dirnames if not dn.startswith(".")]

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.refactor_docstring (   self,
  input,
  filename 
)
Refactors a docstring, looking for doctests.

This returns a modified version of the input string.  It looks
for doctests, which start with a ">>>" prompt, and may be
continued with "..." prompts, as long as the "..." is indented
the same as the ">>>".

(Unfortunately we can't use the doctest module's parser,
since, like most parsers, it is not geared towards preserving
the original source.)

Definition at line 546 of file refactor.py.

00546 
00547     def refactor_docstring(self, input, filename):
00548         """Refactors a docstring, looking for doctests.
00549 
00550         This returns a modified version of the input string.  It looks
00551         for doctests, which start with a ">>>" prompt, and may be
00552         continued with "..." prompts, as long as the "..." is indented
00553         the same as the ">>>".
00554 
00555         (Unfortunately we can't use the doctest module's parser,
00556         since, like most parsers, it is not geared towards preserving
00557         the original source.)
00558         """
00559         result = []
00560         block = None
00561         block_lineno = None
00562         indent = None
00563         lineno = 0
00564         for line in input.splitlines(True):
00565             lineno += 1
00566             if line.lstrip().startswith(self.PS1):
00567                 if block is not None:
00568                     result.extend(self.refactor_doctest(block, block_lineno,
00569                                                         indent, filename))
00570                 block_lineno = lineno
00571                 block = [line]
00572                 i = line.find(self.PS1)
00573                 indent = line[:i]
00574             elif (indent is not None and
00575                   (line.startswith(indent + self.PS2) or
00576                    line == indent + self.PS2.rstrip() + "\n")):
00577                 block.append(line)
00578             else:
00579                 if block is not None:
00580                     result.extend(self.refactor_doctest(block, block_lineno,
00581                                                         indent, filename))
00582                 block = None
00583                 indent = None
00584                 result.append(line)
00585         if block is not None:
00586             result.extend(self.refactor_doctest(block, block_lineno,
00587                                                 indent, filename))
00588         return "".join(result)

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.refactor_doctest (   self,
  block,
  lineno,
  indent,
  filename 
)
Refactors one doctest.

A doctest is given as a block of lines, the first of which starts
with ">>>" (possibly indented), while the remaining lines start
with "..." (identically indented).

Definition at line 589 of file refactor.py.

00589 
00590     def refactor_doctest(self, block, lineno, indent, filename):
00591         """Refactors one doctest.
00592 
00593         A doctest is given as a block of lines, the first of which starts
00594         with ">>>" (possibly indented), while the remaining lines start
00595         with "..." (identically indented).
00596 
00597         """
00598         try:
00599             tree = self.parse_block(block, lineno, indent)
00600         except Exception as err:
00601             if self.logger.isEnabledFor(logging.DEBUG):
00602                 for line in block:
00603                     self.log_debug("Source: %s", line.rstrip("\n"))
00604             self.log_error("Can't parse docstring in %s line %s: %s: %s",
00605                            filename, lineno, err.__class__.__name__, err)
00606             return block
00607         if self.refactor_tree(tree, filename):
00608             new = str(tree).splitlines(True)
00609             # Undo the adjustment of the line numbers in wrap_toks() below.
00610             clipped, new = new[:lineno-1], new[lineno-1:]
00611             assert clipped == ["\n"] * (lineno-1), clipped
00612             if not new[-1].endswith("\n"):
00613                 new[-1] += "\n"
00614             block = [indent + self.PS1 + new.pop(0)]
00615             if new:
00616                 block += [indent + self.PS2 + line for line in new]
00617         return block

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.refactor_file (   self,
  filename,
  write = False,
  doctests_only = False 
)
Refactors a file.

Definition at line 334 of file refactor.py.

00334 
00335     def refactor_file(self, filename, write=False, doctests_only=False):
00336         """Refactors a file."""
00337         input, encoding = self._read_python_source(filename)
00338         if input is None:
00339             # Reading the file failed.
00340             return
00341         input += "\n" # Silence certain parse errors
00342         if doctests_only:
00343             self.log_debug("Refactoring doctests in %s", filename)
00344             output = self.refactor_docstring(input, filename)
00345             if output != input:
00346                 self.processed_file(output, filename, input, write, encoding)
00347             else:
00348                 self.log_debug("No doctest changes in %s", filename)
00349         else:
00350             tree = self.refactor_string(input, filename)
00351             if tree and tree.was_changed:
00352                 # The [:-1] is to take off the \n we added earlier
00353                 self.processed_file(str(tree)[:-1], filename,
00354                                     write=write, encoding=encoding)
00355             else:
00356                 self.log_debug("No changes in %s", filename)

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.refactor_stdin (   self,
  doctests_only = False 
)

Definition at line 384 of file refactor.py.

00384 
00385     def refactor_stdin(self, doctests_only=False):
00386         input = sys.stdin.read()
00387         if doctests_only:
00388             self.log_debug("Refactoring doctests in stdin")
00389             output = self.refactor_docstring(input, "<stdin>")
00390             if output != input:
00391                 self.processed_file(output, "<stdin>", input)
00392             else:
00393                 self.log_debug("No doctest changes in stdin")
00394         else:
00395             tree = self.refactor_string(input, "<stdin>")
00396             if tree and tree.was_changed:
00397                 self.processed_file(str(tree), "<stdin>", input)
00398             else:
00399                 self.log_debug("No changes in stdin")

Here is the call graph for this function:

def lib2to3.refactor.RefactoringTool.refactor_string (   self,
  data,
  name 
)
Refactor a given input string.

Args:
    data: a string holding the code to be refactored.
    name: a human-readable name for use in error/log messages.

Returns:
    An AST corresponding to the refactored input stream; None if
    there were errors during the parse.

Definition at line 357 of file refactor.py.

00357 
00358     def refactor_string(self, data, name):
00359         """Refactor a given input string.
00360 
00361         Args:
00362             data: a string holding the code to be refactored.
00363             name: a human-readable name for use in error/log messages.
00364 
00365         Returns:
00366             An AST corresponding to the refactored input stream; None if
00367             there were errors during the parse.
00368         """
00369         features = _detect_future_features(data)
00370         if "print_function" in features:
00371             self.driver.grammar = pygram.python_grammar_no_print_statement
00372         try:
00373             tree = self.driver.parse_string(data)
00374         except Exception as err:
00375             self.log_error("Can't parse %s: %s: %s",
00376                            name, err.__class__.__name__, err)
00377             return
00378         finally:
00379             self.driver.grammar = self.grammar
00380         tree.future_features = features
00381         self.log_debug("Refactoring %s", name)
00382         self.refactor_tree(tree, name)
00383         return tree

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.refactor_tree (   self,
  tree,
  name 
)
Refactors a parse tree (modifying the tree in place).

For compatible patterns the bottom matcher module is
used. Otherwise the tree is traversed node-to-node for
matches.

Args:
    tree: a pytree.Node instance representing the root of the tree
  to be refactored.
    name: a human-readable name for this tree.

Returns:
    True if the tree was modified, False otherwise.

Definition at line 400 of file refactor.py.

00400 
00401     def refactor_tree(self, tree, name):
00402         """Refactors a parse tree (modifying the tree in place).
00403 
00404         For compatible patterns the bottom matcher module is
00405         used. Otherwise the tree is traversed node-to-node for
00406         matches.
00407 
00408         Args:
00409             tree: a pytree.Node instance representing the root of the tree
00410                   to be refactored.
00411             name: a human-readable name for this tree.
00412 
00413         Returns:
00414             True if the tree was modified, False otherwise.
00415         """
00416 
00417         for fixer in chain(self.pre_order, self.post_order):
00418             fixer.start_tree(tree, name)
00419 
00420         #use traditional matching for the incompatible fixers
00421         self.traverse_by(self.bmi_pre_order_heads, tree.pre_order())
00422         self.traverse_by(self.bmi_post_order_heads, tree.post_order())
00423 
00424         # obtain a set of candidate nodes
00425         match_set = self.BM.run(tree.leaves())
00426 
00427         while any(match_set.values()):
00428             for fixer in self.BM.fixers:
00429                 if fixer in match_set and match_set[fixer]:
00430                     #sort by depth; apply fixers from bottom(of the AST) to top
00431                     match_set[fixer].sort(key=pytree.Base.depth, reverse=True)
00432 
00433                     if fixer.keep_line_order:
00434                         #some fixers(eg fix_imports) must be applied
00435                         #with the original file's line order
00436                         match_set[fixer].sort(key=pytree.Base.get_lineno)
00437 
00438                     for node in list(match_set[fixer]):
00439                         if node in match_set[fixer]:
00440                             match_set[fixer].remove(node)
00441 
00442                         try:
00443                             find_root(node)
00444                         except AssertionError:
00445                             # this node has been cut off from a
00446                             # previous transformation ; skip
00447                             continue
00448 
00449                         if node.fixers_applied and fixer in node.fixers_applied:
00450                             # do not apply the same fixer again
00451                             continue
00452 
00453                         results = fixer.match(node)
00454 
00455                         if results:
00456                             new = fixer.transform(node, results)
00457                             if new is not None:
00458                                 node.replace(new)
00459                                 #new.fixers_applied.append(fixer)
00460                                 for node in new.post_order():
00461                                     # do not apply the fixer again to
00462                                     # this or any subnode
00463                                     if not node.fixers_applied:
00464                                         node.fixers_applied = []
00465                                     node.fixers_applied.append(fixer)
00466 
00467                                 # update the original match set for
00468                                 # the added code
00469                                 new_matches = self.BM.run(new.leaves())
00470                                 for fxr in new_matches:
00471                                     if not fxr in match_set:
00472                                         match_set[fxr]=[]
00473 
00474                                     match_set[fxr].extend(new_matches[fxr])
00475 
00476         for fixer in chain(self.pre_order, self.post_order):
00477             fixer.finish_tree(tree, name)
00478         return tree.was_changed

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 618 of file refactor.py.

00618 
00619     def summarize(self):
00620         if self.wrote:
00621             were = "were"
00622         else:
00623             were = "need to be"
00624         if not self.files:
00625             self.log_message("No files %s modified.", were)
00626         else:
00627             self.log_message("Files that %s modified:", were)
00628             for file in self.files:
00629                 self.log_message(file)
00630         if self.fixer_log:
00631             self.log_message("Warnings/messages while refactoring:")
00632             for message in self.fixer_log:
00633                 self.log_message(message)
00634         if self.errors:
00635             if len(self.errors) == 1:
00636                 self.log_message("There was 1 error:")
00637             else:
00638                 self.log_message("There were %d errors:", len(self.errors))
00639             for msg, args, kwds in self.errors:
00640                 self.log_message(msg, *args, **kwds)

Here is the call graph for this function:

def lib2to3.refactor.RefactoringTool.traverse_by (   self,
  fixers,
  traversal 
)
Traverse an AST, applying a set of fixers to each node.

This is a helper method for refactor_tree().

Args:
    fixers: a list of fixer instances.
    traversal: a generator that yields AST nodes.

Returns:
    None

Definition at line 479 of file refactor.py.

00479 
00480     def traverse_by(self, fixers, traversal):
00481         """Traverse an AST, applying a set of fixers to each node.
00482 
00483         This is a helper method for refactor_tree().
00484 
00485         Args:
00486             fixers: a list of fixer instances.
00487             traversal: a generator that yields AST nodes.
00488 
00489         Returns:
00490             None
00491         """
00492         if not fixers:
00493             return
00494         for node in traversal:
00495             for fixer in fixers[node.type]:
00496                 results = fixer.match(node)
00497                 if results:
00498                     new = fixer.transform(node, results)
00499                     if new is not None:
00500                         node.replace(new)
00501                         node = new

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.wrap_toks (   self,
  block,
  lineno,
  indent 
)
Wraps a tokenize stream to systematically modify start/end.

Definition at line 651 of file refactor.py.

00651 
00652     def wrap_toks(self, block, lineno, indent):
00653         """Wraps a tokenize stream to systematically modify start/end."""
00654         tokens = tokenize.generate_tokens(self.gen_lines(block, indent).__next__)
00655         for type, value, (line0, col0), (line1, col1), line_text in tokens:
00656             line0 += lineno - 1
00657             line1 += lineno - 1
00658             # Don't bother updating the columns; this is too complicated
00659             # since line_text would also have to be updated and it would
00660             # still break for tokens spanning lines.  Let the user guess
00661             # that the column numbers for doctests are relative to the
00662             # end of the prompt string (PS1 or PS2).
00663             yield type, value, (line0, col0), (line1, col1), line_text
00664 

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.refactor.RefactoringTool.write_file (   self,
  new_text,
  filename,
  old_text,
  encoding = None 
)
Writes a string to a file.

It first shows a unified diff between the old text and the new text, and
then rewrites the file; the latter is only done if the write option is
set.

Reimplemented in lib2to3.main.StdoutRefactoringTool.

Definition at line 522 of file refactor.py.

00522 
00523     def write_file(self, new_text, filename, old_text, encoding=None):
00524         """Writes a string to a file.
00525 
00526         It first shows a unified diff between the old text and the new text, and
00527         then rewrites the file; the latter is only done if the write option is
00528         set.
00529         """
00530         try:
00531             f = _open_with_encoding(filename, "w", encoding=encoding)
00532         except os.error as err:
00533             self.log_error("Can't create %s: %s", filename, err)
00534             return
00535         try:
00536             f.write(_to_system_newlines(new_text))
00537         except os.error as err:
00538             self.log_error("Can't write %s: %s", filename, err)
00539         finally:
00540             f.close()
00541         self.log_debug("Wrote changes to %s", filename)
00542         self.wrote = True

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

dictionary lib2to3.refactor.RefactoringTool._default_options = {"print_function" : False} [static, private]

Definition at line 176 of file refactor.py.

Definition at line 210 of file refactor.py.

Definition at line 212 of file refactor.py.

Definition at line 225 of file refactor.py.

Definition at line 211 of file refactor.py.

Definition at line 224 of file refactor.py.

Definition at line 178 of file refactor.py.

Definition at line 202 of file refactor.py.

Definition at line 198 of file refactor.py.

Definition at line 190 of file refactor.py.

Definition at line 179 of file refactor.py.

Definition at line 208 of file refactor.py.

Definition at line 200 of file refactor.py.

Definition at line 189 of file refactor.py.

Definition at line 195 of file refactor.py.

Definition at line 199 of file refactor.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 191 of file refactor.py.

Definition at line 205 of file refactor.py.

Definition at line 543 of file refactor.py.

Definition at line 544 of file refactor.py.

Definition at line 201 of file refactor.py.


The documentation for this class was generated from the following file: