comparison emeraldtree/ElementTree.py @ 23:4c1912ff58a3

Support initialization with children. * emeraldtree/ElementTree.py - Add children argument to Element.__init__. - Style fixes. * emeraldtree/tests/test_ElementTree.py - Use children init. - Check for unicode.
author Bastian Blank <bblank@thinkmo.de>
date Fri, 06 Jun 2008 21:57:12 +0200
parents 0aa00b020bc1
children 47ae505e63ea
comparison
equal deleted inserted replaced
22:0aa00b020bc1 23:4c1912ff58a3
181 181
182 @property 182 @property
183 def tail(self): 183 def tail(self):
184 raise RuntimeError('The tail argument is not supported') 184 raise RuntimeError('The tail argument is not supported')
185 185
186 def __init__(self, tag, attrib={}, **extra): 186 def __init__(self, tag, attrib={}, children=[], **extra):
187 attrib = attrib.copy() 187 attrib = attrib.copy()
188 attrib.update(extra) 188 attrib.update(extra)
189 self.tag = tag 189 self.tag = tag
190 self.attrib = attrib 190 self.attrib = attrib
191 self._children = [] 191 self._children = children[:]
192 192
193 def __repr__(self): 193 def __repr__(self):
194 return "<Element %s at %x>" % (repr(self.tag), id(self)) 194 return "<Element %s at %x>" % (repr(self.tag), id(self))
195 195
196 ## 196 ##
473 # order to get proper namespace handling on output. 473 # order to get proper namespace handling on output.
474 # 474 #
475 # @return An opaque object, representing the QName. 475 # @return An opaque object, representing the QName.
476 476
477 class QName(object): 477 class QName(object):
478 def __init__(self, text, uri = None): 478 def __init__(self, text, uri=None):
479 if text[0] == '{': 479 if text[0] == '{':
480 if uri is not None: 480 if uri is not None:
481 raise ValueError 481 raise ValueError
482 i = text.find('}') 482 i = text.find('}')
483 if i == -1: 483 if i == -1: