From e1392feda59ed0fdcf10934d57f833c64e99c19a Mon Sep 17 00:00:00 2001 From: Alfredo Moralejo Date: Thu, 30 Sep 2021 09:39:36 +0200 Subject: [PATCH] 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 --- setup.cfg | 2 +- src/saml2/sigver.py | 7 ++++++- src/saml2/xml/schema/__init__.py | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index e04c5520..41ccdd7f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 = { -- 2.26.3