File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,7 +30,28 @@ class OneLogin_Saml2_XML(object):
3030 dump = staticmethod (etree .dump )
3131 make_root = staticmethod (etree .Element )
3232 make_child = staticmethod (etree .SubElement )
33- cleanup_namespaces = staticmethod (etree .cleanup_namespaces )
33+
34+ @staticmethod
35+ def cleanup_namespaces (tree_or_element , top_nsmap = None , keep_ns_prefixes = None ):
36+ """
37+ Keeps the xmlns:xs namespace intact when etree.cleanup_namespaces is invoked.
38+ :param tree_or_element: An XML tree or element
39+ :type tree_or_element: etree.Element
40+ :param top_nsmap: A mapping from namespace prefixes to namespace URIs
41+ :type top_nsmap: dict
42+ :param keep_ns_prefixes: List of prefixes that should not be removed as part of the cleanup
43+ :type keep_ns_prefixes: list
44+ :returns: An XML tree or element
45+ :rtype: etree.Element
46+ """
47+ all_prefixes_to_keep = [
48+ OneLogin_Saml2_Constants .NS_PREFIX_XS
49+ ]
50+
51+ if keep_ns_prefixes :
52+ all_prefixes_to_keep = list (set (all_prefixes_to_keep .extend (keep_ns_prefixes )))
53+
54+ return etree .cleanup_namespaces (tree_or_element , keep_ns_prefixes = all_prefixes_to_keep )
3455
3556 @staticmethod
3657 def to_string (xml , ** kwargs ):
You can’t perform that action at this time.
0 commit comments