2121
2222
2323class Node (object ):
24+ """Represents an item in the tree"""
2425 def __init__ (self , name ):
25- """Node representing an item in the tree.
26- name - The tag name associated with the node
27- parent - The parent of the current node (or None for the document node)
28- value - The value of the current node (applies to text nodes and
29- comments
30- attributes - a dict holding name, value pairs for attributes of the node
31- childNodes - a list of child nodes of the current node. This must
32- include all elements but not necessarily other node types
33- _flags - A list of miscellaneous flags that can be set on the node
26+ """Creates a Node
27+
28+ :arg name: The tag name associated with the node
29+
3430 """
31+ # The tag name assocaited with the node
3532 self .name = name
33+ # The parent of the current node (or None for the document node)
3634 self .parent = None
35+ # The value of the current node (applies to text nodes and comments)
3736 self .value = None
37+ # A dict holding name -> value pairs for attributes of the node
3838 self .attributes = {}
39+ # A list of child nodes of the current node. This must include all
40+ # elements but not necessarily other node types.
3941 self .childNodes = []
42+ # A list of miscellaneous flags that can be set on the node.
4043 self ._flags = []
4144
4245 def __str__ (self ):
@@ -53,30 +56,51 @@ def __repr__(self):
5356
5457 def appendChild (self , node ):
5558 """Insert node as a child of the current node
59+
60+ :arg node: the node to insert
61+
5662 """
5763 raise NotImplementedError
5864
5965 def insertText (self , data , insertBefore = None ):
6066 """Insert data as text in the current node, positioned before the
6167 start of node insertBefore or to the end of the node's text.
68+
69+ :arg data: the data to insert
70+
71+ :arg insertBefore: True if you want to insert the text before the node
72+ and False if you want to insert it after the node
73+
6274 """
6375 raise NotImplementedError
6476
6577 def insertBefore (self , node , refNode ):
6678 """Insert node as a child of the current node, before refNode in the
6779 list of child nodes. Raises ValueError if refNode is not a child of
68- the current node"""
80+ the current node
81+
82+ :arg node: the node to insert
83+
84+ :arg refNode: the child node to insert the node before
85+
86+ """
6987 raise NotImplementedError
7088
7189 def removeChild (self , node ):
7290 """Remove node from the children of the current node
91+
92+ :arg node: the child node to remove
93+
7394 """
7495 raise NotImplementedError
7596
7697 def reparentChildren (self , newParent ):
7798 """Move all the children of the current node to newParent.
7899 This is needed so that trees that don't store text as nodes move the
79100 text in the correct way
101+
102+ :arg newParent: the node to move all this node's children to
103+
80104 """
81105 # XXX - should this method be made more general?
82106 for child in self .childNodes :
@@ -121,10 +145,12 @@ def nodesEqual(self, node1, node2):
121145
122146class TreeBuilder (object ):
123147 """Base treebuilder implementation
124- documentClass - the class to use for the bottommost node of a document
125- elementClass - the class to use for HTML Elements
126- commentClass - the class to use for comments
127- doctypeClass - the class to use for doctypes
148+
149+ * documentClass - the class to use for the bottommost node of a document
150+ * elementClass - the class to use for HTML Elements
151+ * commentClass - the class to use for comments
152+ * doctypeClass - the class to use for doctypes
153+
128154 """
129155 # pylint:disable=not-callable
130156
@@ -144,6 +170,11 @@ class TreeBuilder(object):
144170 fragmentClass = None
145171
146172 def __init__ (self , namespaceHTMLElements ):
173+ """Create a TreeBuilder
174+
175+ :arg namespaceHTMLElements: whether or not to namespace HTML elements
176+
177+ """
147178 if namespaceHTMLElements :
148179 self .defaultNamespace = "http://www.w3.org/1999/xhtml"
149180 else :
@@ -367,17 +398,20 @@ def generateImpliedEndTags(self, exclude=None):
367398 self .generateImpliedEndTags (exclude )
368399
369400 def getDocument (self ):
370- "Return the final tree"
401+ """ Return the final tree"" "
371402 return self .document
372403
373404 def getFragment (self ):
374- "Return the final fragment"
405+ """ Return the final fragment"" "
375406 # assert self.innerHTML
376407 fragment = self .fragmentClass ()
377408 self .openElements [0 ].reparentChildren (fragment )
378409 return fragment
379410
380411 def testSerializer (self , node ):
381412 """Serialize the subtree of node in the format required by unit tests
382- node - the node from which to start serializing"""
413+
414+ :arg node: the node from which to start serializing
415+
416+ """
383417 raise NotImplementedError
0 commit comments