File 0009-Make-previous-commits-python2-compatible.patch of Package python-pysaml2
From 08c29b5d65c4bc560051182ab620aedc2fcb7278 Mon Sep 17 00:00:00 2001
From: Jan Zerebecki <jan.suse@zerebecki.de>
Date: Mon, 8 Feb 2021 20:38:26 +0100
Subject: [PATCH 9/9] Make previous commits python2 compatible
Use six.raise_from instead of its python3 variant.
Replace reportlib_resources useage with inspect.
The reportlib_resources functionality was not available for one that is
also compatible with python2.
Also some older versions of reportlib_resources fail when used this way.
Remove arguent use_fallback for xmlschema as it was only introduced in
v1.2.3.
(cherry picked from commit aee48bcbe0595e3201fa827207c1b28632f8ab99)
---
src/saml2/samlxml/schema/__init__.py | 44 ++++++++++++----------------
src/saml2/sigver.py | 4 +--
2 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/src/saml2/samlxml/schema/__init__.py b/src/saml2/samlxml/schema/__init__.py
index 56e08b1c..c4c3a3e9 100644
--- a/src/saml2/samlxml/schema/__init__.py
+++ b/src/saml2/samlxml/schema/__init__.py
@@ -1,37 +1,32 @@
-from importlib_resources import path as _resource_path
+import inspect
+import os.path
from xmlschema import XMLSchema as _XMLSchema
from xmlschema.exceptions import XMLSchemaException as XMLSchemaError
import saml2.data.schemas as _data_schemas
-
def _create_xml_schema_validator(source, **kwargs):
- kwargs = {
- **kwargs,
+ kwargs.update({
"validation": "strict",
"locations": _locations,
"base_url": source,
"allow": "sandbox",
- "use_fallback": False,
- }
+ })
return _XMLSchema(source, **kwargs)
-with _resource_path(_data_schemas, "xml.xsd") as fp:
- _path_schema_xml = str(fp)
-with _resource_path(_data_schemas, "envelope.xsd") as fp:
- _path_schema_envelope = str(fp)
-with _resource_path(_data_schemas, "xenc-schema.xsd") as fp:
- _path_schema_xenc = str(fp)
-with _resource_path(_data_schemas, "xmldsig-core-schema.xsd") as fp:
- _path_schema_xmldsig_core = str(fp)
-with _resource_path(_data_schemas, "saml-schema-assertion-2.0.xsd") as fp:
- _path_schema_saml_assertion = str(fp)
-with _resource_path(_data_schemas, "saml-schema-metadata-2.0.xsd") as fp:
- _path_schema_saml_metadata = str(fp)
-with _resource_path(_data_schemas, "saml-schema-protocol-2.0.xsd") as fp:
- _path_schema_saml_protocol = str(fp)
+def _resource_path_str(package, resource):
+ return os.path.join(os.path.dirname(inspect.getabsfile(package)), resource)
+
+
+_path_schema_xml = _resource_path_str(_data_schemas, "xml.xsd")
+_path_schema_envelope = _resource_path_str(_data_schemas, "envelope.xsd")
+_path_schema_xenc = _resource_path_str(_data_schemas, "xenc-schema.xsd")
+_path_schema_xmldsig_core = _resource_path_str(_data_schemas, "xmldsig-core-schema.xsd")
+_path_schema_saml_assertion = _resource_path_str(_data_schemas, "saml-schema-assertion-2.0.xsd")
+_path_schema_saml_metadata = _resource_path_str(_data_schemas, "saml-schema-metadata-2.0.xsd")
+_path_schema_saml_protocol = _resource_path_str(_data_schemas, "saml-schema-protocol-2.0.xsd")
_locations = {
"http://www.w3.org/XML/1998/namespace": _path_schema_xml,
@@ -42,12 +37,9 @@ _locations = {
"urn:oasis:names:tc:SAML:2.0:protocol": _path_schema_saml_protocol,
}
-with _resource_path(_data_schemas, "saml-schema-assertion-2.0.xsd") as fp:
- schema_saml_assertion = _create_xml_schema_validator(str(fp))
-with _resource_path(_data_schemas, "saml-schema-metadata-2.0.xsd") as fp:
- schema_saml_metadata = _create_xml_schema_validator(str(fp))
-with _resource_path(_data_schemas, "saml-schema-protocol-2.0.xsd") as fp:
- schema_saml_protocol = _create_xml_schema_validator(str(fp))
+schema_saml_assertion = _create_xml_schema_validator(_resource_path_str(_data_schemas, "saml-schema-assertion-2.0.xsd"))
+schema_saml_metadata = _create_xml_schema_validator(_resource_path_str(_data_schemas, "saml-schema-metadata-2.0.xsd"))
+schema_saml_protocol = _create_xml_schema_validator(_resource_path_str(_data_schemas, "saml-schema-protocol-2.0.xsd"))
node_to_schema = {
diff --git a/src/saml2/sigver.py b/src/saml2/sigver.py
index 4f2bf85f..6c64cede 100644
--- a/src/saml2/sigver.py
+++ b/src/saml2/sigver.py
@@ -1547,7 +1547,7 @@ class SecurityContext(object):
"type": node_name,
"document": decoded_xml,
}
- raise SignatureError(error_context) from e
+ six.raise_from(SignatureError(error_context), e)
try:
_schema.validate(str(item))
@@ -1559,7 +1559,7 @@ class SecurityContext(object):
"type": node_name,
"document": decoded_xml,
}
- raise SignatureError(error_context) from e
+ six.raise_from(SignatureError(error_context), e)
# saml-core section "5.4 XML Signature Profile" defines constrains on the
# xmldsig-core facilities. It explicitly dictates that enveloped signatures
--
2.30.2