diff options
Diffstat (limited to 'src/saml2/__init__.py')
-rw-r--r-- | src/saml2/__init__.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/saml2/__init__.py b/src/saml2/__init__.py index 6c11e200..6588a741 100644 --- a/src/saml2/__init__.py +++ b/src/saml2/__init__.py @@ -981,7 +981,7 @@ def extension_element_to_element(extension_element, translation_functions, return None -def extension_elements_to_elements(extension_elements, schemas): +def extension_elements_to_elements(extension_elements, schemas, keep_unmatched=False): """ Create a list of elements each one matching one of the given extension elements. This is of course dependent on the access to schemas that describe the extension elements. @@ -989,6 +989,8 @@ def extension_elements_to_elements(extension_elements, schemas): :param extension_elements: The list of extension elements :param schemas: Imported Python modules that represent the different known schemas used for the extension elements + :param keep_unmatched: Whether to keep extension elements that did not match any + schemas :return: A list of elements, representing the set of extension elements that was possible to match against a Class in the given schemas. The elements returned are the native representation of the elements @@ -1004,13 +1006,19 @@ def extension_elements_to_elements(extension_elements, schemas): return res for extension_element in extension_elements: - for schema in schemas: - inst = extension_element_to_element(extension_element, - schema.ELEMENT_FROM_STRING, - schema.NAMESPACE) - if inst: - res.append(inst) - break + convert_results = ( + inst + for schema in schemas + for inst in [ + extension_element_to_element( + extension_element, schema.ELEMENT_FROM_STRING, schema.NAMESPACE + ) + ] + if inst + ) + result = next(convert_results, extension_element if keep_unmatched else None) + if result: + res.append(result) return res |