1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

add writeEmptyTag.

This commit is contained in:
Shlomi Fish 2019-04-08 12:56:03 +03:00
parent 44413c9f0b
commit 7a12c8b21f
2 changed files with 15 additions and 0 deletions

View file

@ -13,5 +13,15 @@
class KpatEmitter:
"""docstring for KpatEmitter"""
def _out(self, text):
"""docstring for _out"""
self.f.write(text)
def __init__(self, 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")

View file

@ -11,3 +11,8 @@ class MyTests(unittest.TestCase):
f = cStringIO()
e = KpatEmitter(f)
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")