Skip to content

Commit 01d445e

Browse files
fix: move namespace cleanup to source
The namespace cleanup was being ignored for MDQ per-entity publication - it did nothing when invoked on element other than the root element. It would also be resource intensive to clean up when publishing each individual element. Clean up instead at the source - and there, the guard condition is no longer required (the working document is always XML) Co-authored-by: Johan Wassberg <jocar@sunet.se>
1 parent 7d01233 commit 01d445e

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/pyff/builtins.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,6 @@ def _nop(x):
552552
out = output_file
553553
data = req.t
554554

555-
# clean unused namespaces - the working document isn't always XML (eg discojson* produce JSON)
556-
if isinstance(data, (etree._Element, etree._ElementTree)):
557-
# Keep xs: and xsi:, as these are crucial - and xs: is used only
558-
# in attribute values, so may appear as unused.
559-
keep_ns_prefixes = ['xs', 'xsi']
560-
etree.cleanup_namespaces(data, keep_ns_prefixes=keep_ns_prefixes)
561-
562555
if not req.args.get('raw'):
563556
data = dumptree(req.t, pretty_print=req.args.get('pretty_print'))
564557

src/pyff/samlmd.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,12 @@ def entitiesdescriptor(
488488
ent_insert = deepcopy(ent_insert)
489489
t.append(ent_insert)
490490

491+
# clean unused namespaces
492+
# Keep xs: and xsi:, as these are crucial - and xs: is used only
493+
# in attribute values, so may appear as unused.
494+
keep_ns_prefixes = ['xs', 'xsi']
495+
etree.cleanup_namespaces(t, keep_ns_prefixes=keep_ns_prefixes)
496+
491497
if config.devel_write_xml_to_file:
492498
import os
493499

0 commit comments

Comments
 (0)