Merged revisions 62263 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

................
  r62263 | martin.v.loewis | 2008-04-10 04:48:01 +0200 (Do, 10 Apr 2008) | 19 lines

  Merged revisions 62080-62262 via svnmerge from
  svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3

  ........
    r62092 | collin.winter | 2008-04-01 18:27:10 +0200 (Di, 01 Apr 2008) | 1 line

    Add get_prev_sibling() to complement pytree's get_next_sibling().
  ........
    r62226 | collin.winter | 2008-04-08 21:07:56 +0200 (Di, 08 Apr 2008) | 1 line

    Add min() and max() to the list of special contexts that don't require adding list() calls around dict methods.
  ........
    r62232 | collin.winter | 2008-04-09 00:12:38 +0200 (Mi, 09 Apr 2008) | 4 lines

    Fix for http://bugs.python.org/issue2596

    This extends fix_xrange to know about the (mostly) same special contexts as fix_dict (where a special context is something that is guaranteed to fully consume the iterable), adding list() calls where appropriate. It also special-cases "x in range(y)".
  ........
................
This commit is contained in:
Martin v. Löwis 2008-04-10 02:50:50 +00:00
parent b47aace423
commit 3de92bf155
6 changed files with 119 additions and 13 deletions

View file

@ -167,13 +167,27 @@ class Base(object):
return None
# Can't use index(); we need to test by identity
for i, sibling in enumerate(self.parent.children):
if sibling is self:
for i, child in enumerate(self.parent.children):
if child is self:
try:
return self.parent.children[i+1]
except IndexError:
return None
def get_prev_sibling(self):
"""Return the node immediately preceding the invocant in their
parent's children list. If the invocant does not have a previous
sibling, return None."""
if self.parent is None:
return None
# Can't use index(); we need to test by identity
for i, child in enumerate(self.parent.children):
if child is self:
if i == 0:
return None
return self.parent.children[i-1]
def get_suffix(self):
"""Return the string immediately following the invocant node. This
is effectively equivalent to node.get_next_sibling().get_prefix()"""