diff options
author | Alfredo Moralejo <amoralej@redhat.com> | 2021-09-30 09:39:36 +0200 |
---|---|---|
committer | Alfredo Moralejo <amoralej@redhat.com> | 2021-10-11 09:48:54 +0200 |
commit | e1392feda59ed0fdcf10934d57f833c64e99c19a (patch) | |
tree | 1d282ecda9fc520ca673c9764ae8908789f3af76 | |
parent | f12ade09aa89211c42b7dc6ed94728f8aa69cffb (diff) | |
download | pysaml2-e1392feda59ed0fdcf10934d57f833c64e99c19a.tar.gz |
Use importlib.resources in python >= 3.7
importlib.resources was added to python standard library since python 3.7
[1]. This patch is implementing conditional to use it instead of the
importlib_resources backport when using python 3.7 or newer.
[1] https://docs.python.org/3/whatsnew/3.7.html
-rw-r--r-- | setup.cfg | 2 | ||||
-rw-r--r-- | src/saml2/sigver.py | 7 | ||||
-rw-r--r-- | src/saml2/xml/schema/__init__.py | 7 |
3 files changed, 13 insertions, 3 deletions
@@ -53,7 +53,7 @@ install_requires = pytz requests >= 1.0.0 six - importlib_resources + importlib_resources;python_version<'3.7' xmlschema >= 1.2.1 diff --git a/src/saml2/sigver.py b/src/saml2/sigver.py index 973d6245..c9c66b13 100644 --- a/src/saml2/sigver.py +++ b/src/saml2/sigver.py @@ -9,12 +9,12 @@ import logging import os import re import six +import sys from uuid import uuid4 as gen_random_key from time import mktime from tempfile import NamedTemporaryFile from subprocess import Popen from subprocess import PIPE -from importlib_resources import path as _resource_path from OpenSSL import crypto @@ -59,6 +59,11 @@ 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__) diff --git a/src/saml2/xml/schema/__init__.py b/src/saml2/xml/schema/__init__.py index 56e08b1c..ce38b807 100644 --- a/src/saml2/xml/schema/__init__.py +++ b/src/saml2/xml/schema/__init__.py @@ -1,10 +1,15 @@ -from importlib_resources import path as _resource_path +import sys 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 = { |