summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--setup.cfg2
-rw-r--r--src/saml2/sigver.py16
-rw-r--r--src/saml2/xml/schema/__init__.py51
3 files changed, 35 insertions, 34 deletions
diff --git a/setup.cfg b/setup.cfg
index 41ccdd7f..bdc21a98 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -53,7 +53,7 @@ install_requires =
pytz
requests >= 1.0.0
six
- importlib_resources;python_version<'3.7'
+ importlib_resources;python_version<'3.9'
xmlschema >= 1.2.1
diff --git a/src/saml2/sigver.py b/src/saml2/sigver.py
index 6d1d0f40..aa0944b7 100644
--- a/src/saml2/sigver.py
+++ b/src/saml2/sigver.py
@@ -16,6 +16,13 @@ from tempfile import NamedTemporaryFile
from subprocess import Popen
from subprocess import PIPE
+# importlib.resources was introduced in python 3.7
+# files API from importlib.resources introduced in python 3.9
+if sys.version_info[:2] >= (3, 9):
+ from importlib.resources import files as _resource_files
+else:
+ from importlib_resources import files as _resource_files
+
from OpenSSL import crypto
import pytz
@@ -56,11 +63,6 @@ from saml2.xmlenc import EncryptedData
from saml2.xml.schema import node_to_schema
from saml2.xml.schema import XMLSchemaError
-# importlib.resources was introduced in python 3.7
-if sys.version_info[:2] >= (3, 7):
- from importlib.resources import path as _resource_path
-else:
- from importlib_resources import path as _resource_path
logger = logging.getLogger(__name__)
@@ -1306,8 +1308,8 @@ class SecurityContext(object):
self.only_use_keys_in_metadata = only_use_keys_in_metadata
if not template:
- with _resource_path(_data_template, "template_enc.xml") as fp:
- self.template = str(fp)
+ fp = str(_resource_files(_data_template).joinpath("template_enc.xml"))
+ self.template = str(fp)
else:
self.template = template
diff --git a/src/saml2/xml/schema/__init__.py b/src/saml2/xml/schema/__init__.py
index ce38b807..5ef5a8e8 100644
--- a/src/saml2/xml/schema/__init__.py
+++ b/src/saml2/xml/schema/__init__.py
@@ -1,15 +1,17 @@
import sys
+# importlib.resources was introduced in python 3.7
+# files API from importlib.resources introduced in python 3.9
+if sys.version_info[:2] >= (3, 9):
+ from importlib.resources import files as _resource_files
+else:
+ from importlib_resources import files as _resource_files
+
from xmlschema import XMLSchema as _XMLSchema
from xmlschema.exceptions import XMLSchemaException as XMLSchemaError
import saml2.data.schemas as _data_schemas
-# importlib.resources was introduced in python 3.7
-if sys.version_info[:2] >= (3, 7):
- from importlib.resources import path as _resource_path
-else:
- from importlib_resources import path as _resource_path
def _create_xml_schema_validator(source, **kwargs):
kwargs = {
@@ -23,20 +25,20 @@ def _create_xml_schema_validator(source, **kwargs):
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)
+_schema_resources = _resource_files(_data_schemas)
+_path_schema_xml = str(_schema_resources.joinpath("xml.xsd"))
+_path_schema_envelope = str(_schema_resources.joinpath("envelope.xsd"))
+_path_schema_xenc = str(_schema_resources.joinpath("xenc-schema.xsd"))
+_path_schema_xmldsig_core = str(_schema_resources.joinpath("xmldsig-core-schema.xsd"))
+_path_schema_saml_assertion = str(
+ _schema_resources.joinpath("saml-schema-assertion-2.0.xsd")
+)
+_path_schema_saml_metadata = str(
+ _schema_resources.joinpath("saml-schema-metadata-2.0.xsd")
+)
+_path_schema_saml_protocol = str(
+ _schema_resources.joinpath("saml-schema-protocol-2.0.xsd")
+)
_locations = {
"http://www.w3.org/XML/1998/namespace": _path_schema_xml,
@@ -44,16 +46,13 @@ _locations = {
"http://www.w3.org/2001/04/xmlenc#": _path_schema_xenc,
"http://www.w3.org/2000/09/xmldsig#": _path_schema_xmldsig_core,
"urn:oasis:names:tc:SAML:2.0:assertion": _path_schema_saml_assertion,
+ "urn:oasis:names:tc:SAML:2.0:metadata": _path_schema_saml_metadata,
"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(_path_schema_saml_assertion)
+schema_saml_metadata = _create_xml_schema_validator(_path_schema_saml_metadata)
+schema_saml_protocol = _create_xml_schema_validator(_path_schema_saml_protocol)
node_to_schema = {
# AssertionType