@@ -62,14 +62,7 @@ def removeChild(self, node):
62
62
node .parent = None
63
63
64
64
def cloneNode (self ):
65
- newNode = type (self )(self .name )
66
- if hasattr (self , 'namespace' ):
67
- newNode .namespace = self .namespace
68
- if hasattr (self , 'attributes' ):
69
- for attr , value in self .attributes .iteritems ():
70
- newNode .attributes [attr ] = value
71
- newNode .value = self .value
72
- return newNode
65
+ raise NotImplementedError
73
66
74
67
def hasContent (self ):
75
68
"""Return true if the node has children or text"""
@@ -112,11 +105,17 @@ def printTree(self):
112
105
tree += child .printTree (2 )
113
106
return tree
114
107
108
+ def cloneNode (self ):
109
+ return Document ()
110
+
115
111
class DocumentFragment (Document ):
116
112
type = 2
117
113
def __unicode__ (self ):
118
114
return "#document-fragment"
119
115
116
+ def cloneNode (self ):
117
+ return DocumentFragment ()
118
+
120
119
class DocumentType (Node ):
121
120
type = 3
122
121
def __init__ (self , name , publicId , systemId ):
@@ -140,6 +139,9 @@ def __unicode__(self):
140
139
def hilite (self ):
141
140
return '<code class="markup doctype"><!DOCTYPE %s></code>' % self .name
142
141
142
+ def cloneNode (self ):
143
+ return DocumentType (self .name , self .publicId , self .systemId )
144
+
143
145
class TextNode (Node ):
144
146
type = 4
145
147
def __init__ (self , value ):
@@ -154,6 +156,9 @@ def toxml(self):
154
156
155
157
hilite = toxml
156
158
159
+ def cloneNode (self ):
160
+ return TextNode (self .value )
161
+
157
162
class Element (Node ):
158
163
type = 5
159
164
def __init__ (self , name , namespace = None ):
@@ -206,6 +211,12 @@ def printTree(self, indent):
206
211
tree += child .printTree (indent )
207
212
return tree
208
213
214
+ def cloneNode (self ):
215
+ newNode = Element (self .name )
216
+ for attr , value in self .attributes .iteritems ():
217
+ newNode .attributes [attr ] = value
218
+ return newNode
219
+
209
220
class CommentNode (Node ):
210
221
type = 6
211
222
def __init__ (self , data ):
@@ -221,6 +232,9 @@ def toxml(self):
221
232
def hilite (self ):
222
233
return '<code class="markup comment"><!--%s--></code>' % escape (self .data )
223
234
235
+ def cloneNode (self ):
236
+ return CommentNode (self .data )
237
+
224
238
class TreeBuilder (_base .TreeBuilder ):
225
239
documentClass = Document
226
240
doctypeClass = DocumentType
0 commit comments