comparison bitten/util/xmlio.py @ 121:381233a91db6

Fix for the {{{unittest}}} command, which was raising an exception but swallowing the traceback.
author cmlenz
date Mon, 08 Aug 2005 15:42:03 +0000
parents 77dd69f7c405
children 3ed8f568f60a
comparison
equal deleted inserted replaced
120:b63ed684c29c 121:381233a91db6
129 >>> print Element('foo')['<bar a="3" b="4"><baz/></bar>'] 129 >>> print Element('foo')['<bar a="3" b="4"><baz/></bar>']
130 <foo><![CDATA[<bar a="3" b="4"><baz/></bar>]]></foo> 130 <foo><![CDATA[<bar a="3" b="4"><baz/></bar>]]></foo>
131 """ 131 """
132 __slots__ = ['name', 'attr'] 132 __slots__ = ['name', 'attr']
133 133
134 def __init__(self, *args, **attr): 134 def __init__(self, name_, **attr):
135 """Create an XML element using the specified tag name. 135 """Create an XML element using the specified tag name.
136 136
137 The tag name must be supplied as the first positional argument. All 137 The tag name must be supplied as the first positional argument. All
138 keyword arguments following it are handled as attributes of the element. 138 keyword arguments following it are handled as attributes of the element.
139 """ 139 """
140 Fragment.__init__(self) 140 Fragment.__init__(self)
141 self.name = args[0] 141 self.name = name_
142 self.attr = dict([(name, value) for name, value in attr.items() 142 self.attr = dict([(name, value) for name, value in attr.items()
143 if value is not None]) 143 if value is not None])
144 144
145 def write(self, out, newlines=False): 145 def write(self, out, newlines=False):
146 """Serializes the element and writes the XML to the given output 146 """Serializes the element and writes the XML to the given output
162 162
163 class SubElement(Element): 163 class SubElement(Element):
164 164
165 __slots__ = [] 165 __slots__ = []
166 166
167 def __init__(self, parent, name, **attr): 167 def __init__(self, parent_, name_, **attr):
168 """Create an XML element using the specified tag name. 168 """Create an XML element using the specified tag name.
169 169
170 The first positional argument is the instance of the parent element that 170 The first positional argument is the instance of the parent element that
171 this subelement should be appended to; the second positional argument is 171 this subelement should be appended to; the second positional argument is
172 the name of the tag. All keyword arguments are handled as attributes of 172 the name of the tag. All keyword arguments are handled as attributes of
173 the element. 173 the element.
174 """ 174 """
175 Element.__init__(self, name, **attr) 175 Element.__init__(self, name_, **attr)
176 parent.append(self) 176 parent_.append(self)
177 177
178 178
179 def parse(text): 179 def parse(text):
180 from xml.dom import minidom 180 from xml.dom import minidom
181 if isinstance(text, (str, unicode)): 181 if isinstance(text, (str, unicode)):
Copyright (C) 2012-2017 Edgewall Software