[elbe-devel] [PATCH 2/2] elbepack: treeutils: load local xml.xsd without catalog
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Fri Jun 7 11:23:12 CEST 2024
While the Debian package properly sets up an XML catalog, the validation
also has to work without the catalog set up, for example during unittesting.
So far the xml.xsd was resolved through the internet in this case.
Resolve it to the local file which is already part of ELBE.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/treeutils.py | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/elbepack/treeutils.py b/elbepack/treeutils.py
index 12fb33ad97ca..ffae4621f508 100644
--- a/elbepack/treeutils.py
+++ b/elbepack/treeutils.py
@@ -5,7 +5,7 @@
import copy
from lxml.etree import Element, ElementTree, SubElement
-from lxml.etree import XMLParser, XMLSchema, parse, tostring
+from lxml.etree import Resolver, XMLParser, XMLSchema, parse, tostring
from elbepack.schema import xml_schema_file
@@ -22,9 +22,17 @@ def xml_bool(value):
raise ValueError(value)
+class _ElbepackSchemaResolver(Resolver):
+ def resolve(self, url, id, context):
+ if url == 'http://www.w3.org/2009/01/xml.xsd':
+ return self.resolve_file(xml_schema_file('xml.xsd'), context)
+
+
def dbsfed_schema():
+ parser = XMLParser(no_network=True)
+ parser.resolvers.add(_ElbepackSchemaResolver())
with xml_schema_file('dbsfed.xsd') as schema_file:
- schema_tree = parse(schema_file)
+ schema_tree = parse(schema_file, parser=parser)
return XMLSchema(schema_tree)
--
2.45.2
More information about the elbe-devel
mailing list