mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
add writeEmptyTag.
This commit is contained in:
parent
44413c9f0b
commit
7a12c8b21f
2 changed files with 15 additions and 0 deletions
|
@ -13,5 +13,15 @@
|
||||||
|
|
||||||
class KpatEmitter:
|
class KpatEmitter:
|
||||||
"""docstring for KpatEmitter"""
|
"""docstring for KpatEmitter"""
|
||||||
|
def _out(self, text):
|
||||||
|
"""docstring for _out"""
|
||||||
|
self.f.write(text)
|
||||||
|
|
||||||
def __init__(self, f):
|
def __init__(self, f):
|
||||||
self.f = f
|
self.f = f
|
||||||
|
self._out("""<?xml version="1.0" encoding="UTF-8"?>\n""")
|
||||||
|
|
||||||
|
def writeEmptyTag(self, name, attrs):
|
||||||
|
self._out(
|
||||||
|
"<" + name + "".join([" "+x[0]+"=\""+x[1]+"\"" for x in attrs])
|
||||||
|
+ "/>\n")
|
||||||
|
|
|
@ -11,3 +11,8 @@ class MyTests(unittest.TestCase):
|
||||||
f = cStringIO()
|
f = cStringIO()
|
||||||
e = KpatEmitter(f)
|
e = KpatEmitter(f)
|
||||||
self.assertTrue(e)
|
self.assertTrue(e)
|
||||||
|
e.writeEmptyTag("foo", [("one", "val1"), ("two", "val2")])
|
||||||
|
self.assertEqual(
|
||||||
|
f.getvalue(),
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
|
+ "<foo one=\"val1\" two=\"val2\"/>\n")
|
||||||
|
|
Loading…
Add table
Reference in a new issue