aboutsummaryrefslogtreecommitdiff
path: root/libxcb/xcb-proto/src/import.py
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-03-20 15:17:43 +0000
committermarha <marha@users.sourceforge.net>2010-03-20 15:17:43 +0000
commit4f736752bbdf3bbf1a6325af7ad470198aa5a82a (patch)
tree77c1f6fc206b313a68ffe6f956e1cbb089e7f9db /libxcb/xcb-proto/src/import.py
parent501c558c841fc5bc1a67e6dc8d33c8605276f504 (diff)
downloadvcxsrv-4f736752bbdf3bbf1a6325af7ad470198aa5a82a.tar.gz
vcxsrv-4f736752bbdf3bbf1a6325af7ad470198aa5a82a.tar.bz2
vcxsrv-4f736752bbdf3bbf1a6325af7ad470198aa5a82a.zip
libxcb git update
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()