Update of /cvsroot/docstring/dps/dps
In directory usw-pr-cvs1:/tmp/cvs-serv7921/dps/dps
Modified Files:
nodes.py
Log Message:
- Added docstrings to ``_Element``.
- Extended ``+=`` to lists of nodes.
- Added ``classifier``.
Index: nodes.py
===================================================================
RCS file: /cvsroot/docstring/dps/dps/nodes.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** nodes.py 2001/08/23 03:55:19 1.3
--- nodes.py 2001/08/25 01:44:16 1.4
***************
*** 62,65 ****
--- 62,90 ----
class _Element(_Node):
+ """
+ `_Element` is the superclass to all specific elements.
+
+ Elements contain attributes and child nodes. Elements emulate dictionaries
+ for attributes, indexing by attribute name (a string). To set the
+ attribute 'att' to 'value', do::
+
+ element['att'] = 'value'
+
+ Elements also emulate lists for child nodes (element nodes and/or text
+ nodes), indexing by integer. To get the first child node, use::
+
+ element[0]
+
+ Elements may be constructed using the ``+=`` operator. To add one new
+ child node to element, do::
+
+ element += node
+
+ To add a list of multiple child nodes at once, use the same ``+=``
+ operator::
+
+ element += [node1, node2]
+ """
+
childtextsep = '\n\n'
"""Separator for child nodes, used by `astext()` method."""
***************
*** 67,73 ****
--- 92,105 ----
def __init__(self, rawsource='', *children, **attributes):
self.rawsource = rawsource
+ """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}."""
+
self.tagName = self.__class__.__name__
+ """The element generic identifier, usually the class name."""
def _dom_node(self):
***************
*** 145,151 ****
def __iadd__(self, other):
! if other is not None:
! assert isinstance(other, _Node)
self.children.append(other)
return self
--- 177,185 ----
def __iadd__(self, other):
! """Append a node or a list of nodes to `self.children`."""
! if isinstance(other, _Node):
self.children.append(other)
+ elif other is not None:
+ self.children.extend(other)
return self
***************
*** 359,362 ****
--- 393,397 ----
class definition_list_item(_Element): pass
class term(_TextElement): pass
+ class classifier(_TextElement): pass
class definition(_Element): pass
class field_list(_Element): pass
|