diff options
author | Johan Dahlin <jdahlin@async.com.br> | 2008-04-21 14:12:47 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-04-21 14:12:47 +0000 |
commit | ef45f35137a79e62b6c48906036000f48e34e8f9 (patch) | |
tree | 799b84daa42d533f61c22f5e2263a8780e50df89 /giscanner/xmlwriter.py | |
parent | 94261f3b084fe72ea8459d4b9c133f687e8771d2 (diff) | |
download | gobject-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.py | 11 |
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() + |