/usr/lib/python2.7/dist-packages/stetl/filters/xmlvalidator.py is in python-stetl 1.1+ds-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Filter: XML validation.
#
# NB: you need to have installed libxml2 2.8.0 or newer!
# Older libxml2 versions like 2.7.8 have a bug which causes failure in GML Schema
# parsing. See https://bugzilla.gnome.org/show_bug.cgi?id=630130
#
# Author:Just van den Broecke
#
from stetl.util import Util, etree
from stetl.filter import Filter
from stetl.packet import FORMAT
log = Util.get_log("xmlvalidator")
class XmlSchemaValidator(Filter):
"""
Validates an etree doc and prints result to log.
consumes=FORMAT.etree_doc, produces=FORMAT.etree_doc
"""
# Constructor
def __init__(self, configdict, section):
Filter.__init__(self, configdict, section, consumes=FORMAT.etree_doc, produces=FORMAT.etree_doc)
self.enabled = self.cfg.get_bool('enabled', True)
self.xsd = self.cfg.get('xsd')
log.info("Building the Schema once with (GML XSD) dependencies for schema=%s (be patient...)" % self.xsd)
self.schema = etree.XMLSchema(etree.parse(self.xsd))
def invoke(self, packet):
if packet.data is None or not self.enabled:
return packet
return self.validate(packet)
def validate(self, packet):
log.info("Validating doc against schema=%s ..." % self.xsd)
result = self.schema.validate(packet.data)
log.info("Validation result: %s" % str(result))
return packet
|