summaryrefslogtreecommitdiff
path: root/src/saml2/mdie.py
diff options
context:
space:
mode:
authorIvan Kanakarakis <ivan.kanak@gmail.com>2021-09-09 01:44:11 +0300
committerIvan Kanakarakis <ivan.kanak@gmail.com>2021-09-09 02:04:52 +0300
commit4acf5925f22cc8fb8622d95065c57dff663e8483 (patch)
tree4fc4cca5a270f93fef531649fa8b99aef2bfdb86 /src/saml2/mdie.py
parentf0a6d63c315e5ec0a47419d28720f25ceb359212 (diff)
downloadpysaml2-4acf5925f22cc8fb8622d95065c57dff663e8483.tar.gz
Keep unknown metadata extensions
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
Diffstat (limited to 'src/saml2/mdie.py')
-rw-r--r--src/saml2/mdie.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/saml2/mdie.py b/src/saml2/mdie.py
index 89197315..1bbe3e8d 100644
--- a/src/saml2/mdie.py
+++ b/src/saml2/mdie.py
@@ -3,6 +3,7 @@ import six
from saml2 import element_to_extension_element
from saml2 import extension_elements_to_elements
+from saml2 import ExtensionElement
from saml2 import SamlBase
from saml2 import md
@@ -30,12 +31,20 @@ def _eval(val, onts, mdb_safe):
return None
else:
return val
- elif isinstance(val, dict) or isinstance(val, SamlBase):
+ elif (
+ isinstance(val, dict)
+ or isinstance(val, SamlBase)
+ or isinstance(val, ExtensionElement)
+ ):
return to_dict(val, onts, mdb_safe)
elif isinstance(val, list):
lv = []
for v in val:
- if isinstance(v, dict) or isinstance(v, SamlBase):
+ if (
+ isinstance(v, dict)
+ or isinstance(v, SamlBase)
+ or isinstance(v, ExtensionElement)
+ ):
lv.append(to_dict(v, onts, mdb_safe))
else:
lv.append(v)
@@ -61,7 +70,9 @@ def to_dict(_dict, onts, mdb_safe=False):
continue
val = getattr(_dict, key)
if key == "extension_elements":
- _eel = extension_elements_to_elements(val, onts)
+ _eel = extension_elements_to_elements(
+ val, onts, keep_unmatched=True
+ )
_val = [_eval(_v, onts, mdb_safe) for _v in _eel]
elif key == "extension_attributes":
if mdb_safe:
@@ -77,6 +88,15 @@ def to_dict(_dict, onts, mdb_safe=False):
if mdb_safe:
key = key.replace(".", "__")
res[key] = _val
+ elif isinstance(_dict, ExtensionElement):
+ res = {
+ key: _val
+ for key, val in _dict.__dict__.items()
+ if val and key not in IMP_SKIP
+ for _val in [_eval(val, onts, mdb_safe)]
+ if _val
+ }
+ res["__class__"] = "%s&%s" % (_dict.namespace, _dict.tag)
else:
for key, val in _dict.items():
_val = _eval(val, onts, mdb_safe)