[elbe-devel] [PATCH 1/2] elbepack: unify loading of dbsfed.xsd
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Fri Jun 7 11:23:11 CEST 2024
The schema loading will grow some custom logic.
Deduplicate the loading so the custom logic doesn't need to be duplicated.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/treeutils.py | 10 +++++++++-
elbepack/validate.py | 6 ++----
elbepack/xmlpreprocess.py | 7 ++-----
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/elbepack/treeutils.py b/elbepack/treeutils.py
index e4588bb0c488..12fb33ad97ca 100644
--- a/elbepack/treeutils.py
+++ b/elbepack/treeutils.py
@@ -5,7 +5,9 @@
import copy
from lxml.etree import Element, ElementTree, SubElement
-from lxml.etree import XMLParser, parse, tostring
+from lxml.etree import XMLParser, XMLSchema, parse, tostring
+
+from elbepack.schema import xml_schema_file
# ElementTree helpers
@@ -20,6 +22,12 @@ def xml_bool(value):
raise ValueError(value)
+def dbsfed_schema():
+ with xml_schema_file('dbsfed.xsd') as schema_file:
+ schema_tree = parse(schema_file)
+ return XMLSchema(schema_tree)
+
+
class eiter:
def __init__(self, it):
self.it = it
diff --git a/elbepack/validate.py b/elbepack/validate.py
index 1fd57c80d2e3..68ca2f5c50c6 100644
--- a/elbepack/validate.py
+++ b/elbepack/validate.py
@@ -8,7 +8,7 @@ import sys
from lxml import etree
from lxml.etree import XMLParser, parse
-from elbepack.schema import xml_schema_file
+from elbepack.treeutils import dbsfed_schema
def error_log_to_strings(error_log):
@@ -40,9 +40,7 @@ def validate_xml(fname):
'Elbe does not support files of this size.']
parser = XMLParser(huge_tree=True)
- with xml_schema_file('dbsfed.xsd') as schema_file:
- schema_tree = etree.parse(schema_file)
- schema = etree.XMLSchema(schema_tree)
+ schema = dbsfed_schema()
try:
xml = parse(fname, parser=parser)
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 56a714018782..9bb8c0359d36 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -23,8 +23,7 @@ from elbepack.archivedir import ArchivedirError, combinearchivedir
from elbepack.config import cfg
from elbepack.directories import run_elbe
from elbepack.isooptions import iso_option_valid
-from elbepack.schema import xml_schema_file
-from elbepack.treeutils import xml_bool
+from elbepack.treeutils import dbsfed_schema, xml_bool
from elbepack.validate import error_log_to_strings
@@ -352,9 +351,7 @@ def xmlpreprocess(xml_input_file, xml_output_file, variants=None, proxy=None, gz
variants = set(variants)
parser = XMLParser(huge_tree=True)
- with xml_schema_file('dbsfed.xsd') as schema_file:
- schema_tree = etree.parse(schema_file)
- schema = etree.XMLSchema(schema_tree)
+ schema = dbsfed_schema()
try:
xml = etree.parse(xml_input_file, parser=parser)
--
2.45.2
More information about the elbe-devel
mailing list