summaryrefslogtreecommitdiff
path: root/giscanner/xmlwriter.py
diff options
context:
space:
mode:
authorJohan Dahlin <jdahlin@async.com.br>2008-04-21 14:12:47 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-04-21 14:12:47 +0000
commitef45f35137a79e62b6c48906036000f48e34e8f9 (patch)
tree799b84daa42d533f61c22f5e2263a8780e50df89 /giscanner/xmlwriter.py
parent94261f3b084fe72ea8459d4b9c133f687e8771d2 (diff)
downloadgobject-introspection-ef45f35137a79e62b6c48906036000f48e34e8f9.tar.gz
Add a simple api for writing tags which can be used with the new 'with
2008-04-21 Johan Dahlin <jdahlin@async.com.br> * giscanner/gidlwriter.py: * giscanner/xmlwriter.py: Add a simple api for writing tags which can be used with the new 'with statement' in python 2.5 svn path=/trunk/; revision=190
Diffstat (limited to 'giscanner/xmlwriter.py')
-rw-r--r--giscanner/xmlwriter.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/giscanner/xmlwriter.py b/giscanner/xmlwriter.py
index 2f80603d..e7a9167d 100644
--- a/giscanner/xmlwriter.py
+++ b/giscanner/xmlwriter.py
@@ -1,3 +1,5 @@
+from contextlib import contextmanager
+
from cStringIO import StringIO
from xml.sax.saxutils import quoteattr
@@ -53,3 +55,12 @@ class XMLWriter(object):
tag_name = self._tag_stack.pop()
self._close_tag(tag_name)
return tag_name
+
+ @contextmanager
+ def tagcontext(self, tag_name, attributes=None):
+ self.push_tag(tag_name, attributes)
+ try:
+ yield
+ finally:
+ self.pop_tag()
+