Back to index

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

List of all members.

Public Member Functions

def __init__
def __repr__
def __unicode__
def clone
def post_order
def pre_order
def set_child
def insert_child
def append_child
def __new__
def __eq__
def __ne__
def set_prefix
def get_prefix
def replace
def get_lineno
def changed
def remove
def next_sibling
def prev_sibling
def leaves
def depth
def get_suffix
def __str__

Public Attributes

 type
 children
 fixers_applied
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

 parent = None
 was_changed = False
 was_checked = False

Properties

 prefix = property(_prefix_getter, _prefix_setter)

Private Member Functions

def _eq
def _prefix_getter
def _prefix_setter

Static Private Attributes

 __str__ = __unicode__

Detailed Description

Concrete implementation for interior nodes.

Definition at line 239 of file pytree.py.


Constructor & Destructor Documentation

def lib2to3.pytree.Node.__init__ (   self,
  type,
  children,
  context = None,
  prefix = None,
  fixers_applied = None 
)
Initializer.

Takes a type constant (a symbol number >= 256), a sequence of
child nodes, and an optional context keyword argument.

As a side effect, the parent pointers of the children are updated.

Definition at line 246 of file pytree.py.

00246 
00247                  fixers_applied=None):
00248         """
00249         Initializer.
00250 
00251         Takes a type constant (a symbol number >= 256), a sequence of
00252         child nodes, and an optional context keyword argument.
00253 
00254         As a side effect, the parent pointers of the children are updated.
00255         """
00256         assert type >= 256, type
00257         self.type = type
00258         self.children = list(children)
00259         for ch in self.children:
00260             assert ch.parent is None, repr(ch)
00261             ch.parent = self
00262         if prefix is not None:
00263             self.prefix = prefix
00264         if fixers_applied:
00265             self.fixers_applied = fixers_applied[:]
00266         else:
00267             self.fixers_applied = None

Here is the caller graph for this function:


Member Function Documentation

def lib2to3.pytree.Base.__eq__ (   self,
  other 
) [inherited]
Compare two nodes for equality.

This calls the method _eq().

Definition at line 55 of file pytree.py.

00055 
00056     def __eq__(self, other):
00057         """
00058         Compare two nodes for equality.
00059 
00060         This calls the method _eq().
00061         """
00062         if self.__class__ is not other.__class__:
00063             return NotImplemented
00064         return self._eq(other)

Here is the call graph for this function:

def lib2to3.pytree.Base.__ne__ (   self,
  other 
) [inherited]
Compare two nodes for inequality.

This calls the method _eq().

Definition at line 67 of file pytree.py.

00067 
00068     def __ne__(self, other):
00069         """
00070         Compare two nodes for inequality.
00071 
00072         This calls the method _eq().
00073         """
00074         if self.__class__ is not other.__class__:
00075             return NotImplemented
00076         return not self._eq(other)

Here is the call graph for this function:

def lib2to3.pytree.Base.__new__ (   cls,
  args,
  kwds 
) [inherited]
Constructor that prevents Base from being instantiated.

Definition at line 50 of file pytree.py.

00050 
00051     def __new__(cls, *args, **kwds):
00052         """Constructor that prevents Base from being instantiated."""
00053         assert cls is not Base, "Cannot instantiate Base"
00054         return object.__new__(cls)

Return a canonical string representation.

Definition at line 268 of file pytree.py.

00268 
00269     def __repr__(self):
00270         """Return a canonical string representation."""
00271         return "%s(%s, %r)" % (self.__class__.__name__,
00272                                type_repr(self.type),
00273                                self.children)

Here is the call graph for this function:

def lib2to3.pytree.Base.__str__ (   self) [inherited]

Definition at line 236 of file pytree.py.

00236 
00237         def __str__(self):
00238             return str(self).encode("ascii")

Return a pretty string representation.

This reproduces the input source exactly.

Definition at line 274 of file pytree.py.

00274 
00275     def __unicode__(self):
00276         """
00277         Return a pretty string representation.
00278 
00279         This reproduces the input source exactly.
00280         """
00281         return "".join(map(str, self.children))

def lib2to3.pytree.Node._eq (   self,
  other 
) [private]
Compare two nodes for equality.

Reimplemented from lib2to3.pytree.Base.

Definition at line 285 of file pytree.py.

00285 
00286     def _eq(self, other):
00287         """Compare two nodes for equality."""
00288         return (self.type, self.children) == (other.type, other.children)

def lib2to3.pytree.Node._prefix_getter (   self) [private]
The whitespace and comments preceding this node in the input.

Definition at line 308 of file pytree.py.

00308 
00309     def _prefix_getter(self):
00310         """
00311         The whitespace and comments preceding this node in the input.
00312         """
00313         if not self.children:
00314             return ""
00315         return self.children[0].prefix

def lib2to3.pytree.Node._prefix_setter (   self,
  prefix 
) [private]

Definition at line 316 of file pytree.py.

00316 
00317     def _prefix_setter(self, prefix):
00318         if self.children:
00319             self.children[0].prefix = prefix

def lib2to3.pytree.Node.append_child (   self,
  child 
)
Equivalent to 'node.children.append(child)'. This method also sets the
child's parent attribute appropriately.

Definition at line 341 of file pytree.py.

00341 
00342     def append_child(self, child):
00343         """
00344         Equivalent to 'node.children.append(child)'. This method also sets the
00345         child's parent attribute appropriately.
00346         """
00347         child.parent = self
00348         self.children.append(child)
00349         self.changed()
00350 

Here is the call graph for this function:

def lib2to3.pytree.Base.changed (   self) [inherited]

Definition at line 164 of file pytree.py.

00164 
00165     def changed(self):
00166         if self.parent:
00167             self.parent.changed()
00168         self.was_changed = True

Here is the caller graph for this function:

def lib2to3.pytree.Node.clone (   self)
Return a cloned (deep) copy of self.

Reimplemented from lib2to3.pytree.Base.

Definition at line 289 of file pytree.py.

00289 
00290     def clone(self):
00291         """Return a cloned (deep) copy of self."""
00292         return Node(self.type, [ch.clone() for ch in self.children],
00293                     fixers_applied=self.fixers_applied)

def lib2to3.pytree.Base.depth (   self) [inherited]

Definition at line 220 of file pytree.py.

00220 
00221     def depth(self):
00222         if self.parent is None:
00223             return 0
00224         return 1 + self.parent.depth()

def lib2to3.pytree.Base.get_lineno (   self) [inherited]
Return the line number which generated the invocant node.

Definition at line 155 of file pytree.py.

00155 
00156     def get_lineno(self):
00157         """Return the line number which generated the invocant node."""
00158         node = self
00159         while not isinstance(node, Leaf):
00160             if not node.children:
00161                 return
00162             node = node.children[0]
00163         return node.lineno

def lib2to3.pytree.Base.get_prefix (   self) [inherited]
Return the prefix for the node (see Leaf class).

DEPRECATED; use the prefix property directly.

Definition at line 122 of file pytree.py.

00122 
00123     def get_prefix(self):
00124         """
00125         Return the prefix for the node (see Leaf class).
00126 
00127         DEPRECATED; use the prefix property directly.
00128         """
00129         warnings.warn("get_prefix() is deprecated; use the prefix property",
00130                       DeprecationWarning, stacklevel=2)
00131         return self.prefix

Here is the call graph for this function:

def lib2to3.pytree.Base.get_suffix (   self) [inherited]
Return the string immediately following the invocant node. This is
effectively equivalent to node.next_sibling.prefix

Definition at line 225 of file pytree.py.

00225 
00226     def get_suffix(self):
00227         """
00228         Return the string immediately following the invocant node. This is
00229         effectively equivalent to node.next_sibling.prefix
00230         """
00231         next_sib = self.next_sibling
00232         if next_sib is None:
00233             return ""
00234         return next_sib.prefix

Here is the call graph for this function:

def lib2to3.pytree.Node.insert_child (   self,
  i,
  child 
)
Equivalent to 'node.children.insert(i, child)'. This method also sets
the child's parent attribute appropriately.

Definition at line 332 of file pytree.py.

00332 
00333     def insert_child(self, i, child):
00334         """
00335         Equivalent to 'node.children.insert(i, child)'. This method also sets
00336         the child's parent attribute appropriately.
00337         """
00338         child.parent = self
00339         self.children.insert(i, child)
00340         self.changed()

Here is the call graph for this function:

def lib2to3.pytree.Base.leaves (   self) [inherited]

Reimplemented in lib2to3.pytree.Leaf.

Definition at line 215 of file pytree.py.

00215 
00216     def leaves(self):
00217         for child in self.children:
00218             for x in child.leaves():
00219                 yield x

def lib2to3.pytree.Base.next_sibling (   self) [inherited]
The node immediately following the invocant in their parent's children
list. If the invocant does not have a next sibling, it is None

Definition at line 183 of file pytree.py.

00183 
00184     def next_sibling(self):
00185         """
00186         The node immediately following the invocant in their parent's children
00187         list. If the invocant does not have a next sibling, it is None
00188         """
00189         if self.parent is None:
00190             return None
00191 
00192         # Can't use index(); we need to test by identity
00193         for i, child in enumerate(self.parent.children):
00194             if child is self:
00195                 try:
00196                     return self.parent.children[i+1]
00197                 except IndexError:
00198                     return None

Here is the call graph for this function:

Here is the caller graph for this function:

Return a post-order iterator for the tree.

Reimplemented from lib2to3.pytree.Base.

Definition at line 294 of file pytree.py.

00294 
00295     def post_order(self):
00296         """Return a post-order iterator for the tree."""
00297         for child in self.children:
00298             for node in child.post_order():
00299                 yield node
00300         yield self

Return a pre-order iterator for the tree.

Reimplemented from lib2to3.pytree.Base.

Definition at line 301 of file pytree.py.

00301 
00302     def pre_order(self):
00303         """Return a pre-order iterator for the tree."""
00304         yield self
00305         for child in self.children:
00306             for node in child.pre_order():
00307                 yield node

Here is the caller graph for this function:

def lib2to3.pytree.Base.prev_sibling (   self) [inherited]
The node immediately preceding the invocant in their parent's children
list. If the invocant does not have a previous sibling, it is None.

Definition at line 200 of file pytree.py.

00200 
00201     def prev_sibling(self):
00202         """
00203         The node immediately preceding the invocant in their parent's children
00204         list. If the invocant does not have a previous sibling, it is None.
00205         """
00206         if self.parent is None:
00207             return None
00208 
00209         # Can't use index(); we need to test by identity
00210         for i, child in enumerate(self.parent.children):
00211             if child is self:
00212                 if i == 0:
00213                     return None
00214                 return self.parent.children[i-1]

Here is the call graph for this function:

def lib2to3.pytree.Base.remove (   self) [inherited]
Remove the node from the tree. Returns the position of the node in its
parent's children before it was removed.

Definition at line 169 of file pytree.py.

00169 
00170     def remove(self):
00171         """
00172         Remove the node from the tree. Returns the position of the node in its
00173         parent's children before it was removed.
00174         """
00175         if self.parent:
00176             for i, node in enumerate(self.parent.children):
00177                 if node is self:
00178                     self.parent.changed()
00179                     del self.parent.children[i]
00180                     self.parent = None
00181                     return i

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.pytree.Base.replace (   self,
  new 
) [inherited]
Replace this node with a new one in the parent.

Definition at line 132 of file pytree.py.

00132 
00133     def replace(self, new):
00134         """Replace this node with a new one in the parent."""
00135         assert self.parent is not None, str(self)
00136         assert new is not None
00137         if not isinstance(new, list):
00138             new = [new]
00139         l_children = []
00140         found = False
00141         for ch in self.parent.children:
00142             if ch is self:
00143                 assert not found, (self.parent.children, self, new)
00144                 if new is not None:
00145                     l_children.extend(new)
00146                 found = True
00147             else:
00148                 l_children.append(ch)
00149         assert found, (self.children, self, new)
00150         self.parent.changed()
00151         self.parent.children = l_children
00152         for x in new:
00153             x.parent = self.parent
00154         self.parent = None

def lib2to3.pytree.Node.set_child (   self,
  i,
  child 
)
Equivalent to 'node.children[i] = child'. This method also sets the
child's parent attribute appropriately.

Definition at line 322 of file pytree.py.

00322 
00323     def set_child(self, i, child):
00324         """
00325         Equivalent to 'node.children[i] = child'. This method also sets the
00326         child's parent attribute appropriately.
00327         """
00328         child.parent = self
00329         self.children[i].parent = None
00330         self.children[i] = child
00331         self.changed()

Here is the call graph for this function:

def lib2to3.pytree.Base.set_prefix (   self,
  prefix 
) [inherited]
Set the prefix for the node (see Leaf class).

DEPRECATED; use the prefix property directly.

Definition at line 112 of file pytree.py.

00112 
00113     def set_prefix(self, prefix):
00114         """
00115         Set the prefix for the node (see Leaf class).
00116 
00117         DEPRECATED; use the prefix property directly.
00118         """
00119         warnings.warn("set_prefix() is deprecated; use the prefix property",
00120                       DeprecationWarning, stacklevel=2)
00121         self.prefix = prefix

Here is the call graph for this function:


Member Data Documentation

Definition at line 283 of file pytree.py.

Reimplemented from lib2to3.pytree.Base.

Definition at line 257 of file pytree.py.

Definition at line 264 of file pytree.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

lib2to3.pytree.Base.parent = None [static, inherited]

Definition at line 45 of file pytree.py.

Reimplemented from lib2to3.pytree.Base.

Definition at line 256 of file pytree.py.

lib2to3.pytree.Base.was_changed = False [static, inherited]

Definition at line 47 of file pytree.py.

lib2to3.pytree.Base.was_checked = False [static, inherited]

Definition at line 48 of file pytree.py.


Property Documentation

Reimplemented from lib2to3.pytree.Base.

Definition at line 320 of file pytree.py.


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