Update of /cvsroot/docstring/dps/dps
In directory usw-pr-cvs1:/tmp/cvs-serv1329/dps/dps
Modified Files:
nodes.py
Log Message:
updated
Index: nodes.py
===================================================================
RCS file: /cvsroot/docstring/dps/dps/nodes.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** nodes.py 2002/01/28 02:18:45 1.23
--- nodes.py 2002/01/29 02:17:18 1.24
***************
*** 31,34 ****
--- 31,37 ----
"""Abstract base class of nodes in a document tree."""
+ parent = None
+ """Back-reference to the `Node` containing this `Node`."""
+
def __nonzero__(self):
"""Node instances are always true."""
***************
*** 132,138 ****
"""The raw text from which this element was constructed."""
! self.children = list(children)
! """List of child nodes (elements and/or text)."""
self.attributes = attributes
"""Dictionary of attribute {name: value}."""
--- 135,143 ----
"""The raw text from which this element was constructed."""
! self.children = []
! """List of child nodes (elements and/or `Text`)."""
+ self.extend(children) # extend self.children w/ attributes
+
self.attributes = attributes
"""Dictionary of attribute {name: value}."""
***************
*** 217,223 ****
--- 222,231 ----
self.attributes[key] = item
elif isinstance(key, IntType):
+ item.parent = self
self.children[key] = item
elif isinstance(key, SliceType):
assert key.step is None, 'cannot handle slice with stride'
+ for node in item:
+ node.parent = self
self.children[key.start:key.stop] = item
else:
***************
*** 246,251 ****
--- 254,262 ----
"""Append a node or a list of nodes to `self.children`."""
if isinstance(other, Node):
+ other.parent = self
self.children.append(other)
elif other is not None:
+ for node in other:
+ node.parent = self
self.children.extend(other)
return self
***************
*** 269,280 ****
def append(self, item):
! assert isinstance(item, Node)
self.children.append(item)
def extend(self, item):
self.children.extend(item)
def insert(self, i, item):
assert isinstance(item, Node)
self.children.insert(i, item)
--- 280,294 ----
def append(self, item):
! item.parent = self
self.children.append(item)
def extend(self, item):
+ for node in item:
+ node.parent = self
self.children.extend(item)
def insert(self, i, item):
assert isinstance(item, Node)
+ item.parent = self
self.children.insert(i, item)
***************
*** 283,289 ****
def remove(self, item):
- assert isinstance(item, Node)
self.children.remove(item)
def findclass(self, childclass, start=0, end=sys.maxint):
"""
--- 297,313 ----
def remove(self, item):
self.children.remove(item)
+ def index(self, item):
+ return self.children.index(item)
+
+ def replace(self, old, new):
+ """Replace one child `Node` with another child or children."""
+ index = self.index(old)
+ if isinstance(new, Node):
+ self[index] = new
+ elif new is not None:
+ self[index:index+1] = new
+
def findclass(self, childclass, start=0, end=sys.maxint):
"""
***************
*** 673,676 ****
--- 697,701 ----
class substitution_reference(Inline, Reference, TextElement): pass
class image(General, Inline, TextElement): pass
+ class problematic(Inline, TextElement): pass
***************
*** 694,698 ****
note
option option_argument option_list option_list_item organization
! paragraph
reference revision row
section short_option status strong substitution_definition
--- 719,723 ----
note
option option_argument option_list option_list_item organization
! paragraph problematic
reference revision row
section short_option status strong substitution_definition
***************
*** 714,718 ****
"``visit_`` + node class name" method is called by `Node.walk()` upon
entering a node.
!
.. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of
Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA,
--- 739,743 ----
"``visit_`` + node class name" method is called by `Node.walk()` upon
entering a node.
!
.. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of
Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA,
|