aboutsummaryrefslogtreecommitdiff
path: root/libxcb/xcb-proto/src/import.py
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-05-18 13:54:22 +0000
committermarha <marha@users.sourceforge.net>2010-05-18 13:54:22 +0000
commit96bd0f520fd4a3a8c54e76638985389f60d936e0 (patch)
tree32643acb5ff4fc3b8a35c7842f94dea7d69c2c73 /libxcb/xcb-proto/src/import.py
parent4787c5a8db870b0cff2326bd750c4d96c7d84e51 (diff)
parenta457b80612b4f37be47099e9a0f38c4fc2a42252 (diff)
downloadvcxsrv-96bd0f520fd4a3a8c54e76638985389f60d936e0.tar.gz
vcxsrv-96bd0f520fd4a3a8c54e76638985389f60d936e0.tar.bz2
vcxsrv-96bd0f520fd4a3a8c54e76638985389f60d936e0.zip
svn merge "^/branches/released" .
Diffstat (limited to 'libxcb/xcb-proto/src/import.py')
-rw-r--r--libxcb/xcb-proto/src/import.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/libxcb/xcb-proto/src/import.py b/libxcb/xcb-proto/src/import.py
new file mode 100644
index 000000000..eb58f5561
--- /dev/null
+++ b/libxcb/xcb-proto/src/import.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+
+from xml.sax.saxutils import XMLFilterBase, XMLGenerator
+from xml.sax import make_parser
+import sys, os
+
+path = [os.path.curdir, 'extensions']
+def find_file_on_path(name):
+ for d in path:
+ test = os.path.join(d, name)
+ if os.path.isfile(test):
+ return test
+ raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), name)
+
+seen = {}
+
+class ProcessImports(XMLFilterBase):
+ def setContentHandler(self, handler):
+ self.handler = handler
+ XMLFilterBase.setContentHandler(self, handler)
+
+ def ensure(self, name):
+ if not seen.has_key(name):
+ child = ProcessImports(make_parser())
+ child.setContentHandler(self.handler)
+ child.parse(find_file_on_path(name + '.xml'))
+
+ def startDocument(self):
+ pass
+ def endDocument(self):
+ pass
+
+ inimport = None
+
+ def startElement(self, name, attrs):
+ assert self.inimport is None
+ if name == 'import':
+ self.inimport = ""
+ return
+ XMLFilterBase.startElement(self, name, attrs)
+ if name == 'xcb':
+ seen[attrs['header']] = True
+ self.ensure('xproto')
+
+ def characters(self, content):
+ if self.inimport is not None:
+ self.inimport += content
+ else:
+ XMLFilterBase.characters(self, content)
+
+ def endElement(self, name):
+ if name == 'import':
+ self.ensure(self.inimport)
+ self.inimport = None
+ return
+ XMLFilterBase.endElement(self, name)
+
+out = XMLGenerator()
+importer = ProcessImports(make_parser())
+importer.setContentHandler(out)
+out.startDocument()
+if len(sys.argv) > 1:
+ importer.parse(sys.argv[1])
+else:
+ importer.parse(sys.stdin)
+out.endDocument()