aboutsummaryrefslogtreecommitdiff
path: root/scripts/rpki
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/rpki')
-rw-r--r--scripts/rpki/relaxng.py44
-rw-r--r--scripts/rpki/sax_utils.py6
2 files changed, 6 insertions, 44 deletions
diff --git a/scripts/rpki/relaxng.py b/scripts/rpki/relaxng.py
deleted file mode 100644
index feb511af..00000000
--- a/scripts/rpki/relaxng.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# $Id$
-
-import libxml2
-
-def relaxng(xml, rng):
- """
- Validate a chunk of XML against a RelaxNG schema.
- """
-
- # Most of this is lifted from a libxml2 example. Using py-lxml
- # might be a better approach, but this works for now.
- #
- # This is probably very inefficient, as we make no attempt to
- # retain validation contexts between calls. It's still much
- # faster than calling xmllint or jing as an external program.
- #
- # Beware of cleaning up the following code. libxml2 is not well
- # documented but there are hints that much of the following voodoo
- # is required manual memory management (see py-lxml, above)
-
- fh = open(rng, "r")
- schema = fh.read()
- fh.close()
- rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
- rngs = rngp.relaxNGParse()
- ctxt = rngs.relaxNGNewValidCtxt()
-
- doc = libxml2.parseDoc(xml)
- ret = doc.relaxNGValidateDoc(ctxt)
- if ret != 0:
- raise RuntimeError, "RelaxNG validation error"
-
- doc.freeDoc()
- del rngp
- del rngs
- del ctxt
- libxml2.relaxNGCleanupTypes()
-
- # Memory debug specific
- libxml2.cleanupParser()
- if libxml2.debugMemory(1) != 0:
- print "Memory leak %d bytes" % (libxml2.debugMemory(1))
- libxml2.dumpMemory()
- raise RuntimeError, "RelaxNG memory leak"
diff --git a/scripts/rpki/sax_utils.py b/scripts/rpki/sax_utils.py
index d645cc4f..1333df1a 100644
--- a/scripts/rpki/sax_utils.py
+++ b/scripts/rpki/sax_utils.py
@@ -23,6 +23,12 @@ class handler(xml.sax.handler.ContentHandler):
def startElement(self, name, attrs):
a = dict()
for k,v in attrs.items():
+ if isinstance(k, tuple):
+ if k == ('http://www.w3.org/XML/1998/namespace', 'lang'):
+ k = "xml:lang"
+ else:
+ assert k[0] is None
+ k = k[1]
a[k.encode("ascii")] = v.encode("ascii")
if len(self.stack) == 0:
assert not hasattr(self, "result")