Skip to content

Commit e1392fe

Browse files
committed
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
1 parent f12ade0 commit e1392fe

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ install_requires =
5353
pytz
5454
requests >= 1.0.0
5555
six
56-
importlib_resources
56+
importlib_resources;python_version<'3.7'
5757
xmlschema >= 1.2.1
5858

5959

src/saml2/sigver.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import os
1010
import re
1111
import six
12+
import sys
1213
from uuid import uuid4 as gen_random_key
1314
from time import mktime
1415
from tempfile import NamedTemporaryFile
1516
from subprocess import Popen
1617
from subprocess import PIPE
17-
from importlib_resources import path as _resource_path
1818

1919
from OpenSSL import crypto
2020

@@ -59,6 +59,11 @@
5959
from saml2.xml.schema import node_to_schema
6060
from saml2.xml.schema import XMLSchemaError
6161

62+
# importlib.resources was introduced in python 3.7
63+
if sys.version_info[:2] >= (3, 7):
64+
from importlib.resources import path as _resource_path
65+
else:
66+
from importlib_resources import path as _resource_path
6267

6368
logger = logging.getLogger(__name__)
6469

src/saml2/xml/schema/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
from importlib_resources import path as _resource_path
1+
import sys
22

33
from xmlschema import XMLSchema as _XMLSchema
44
from xmlschema.exceptions import XMLSchemaException as XMLSchemaError
55

66
import saml2.data.schemas as _data_schemas
77

8+
# importlib.resources was introduced in python 3.7
9+
if sys.version_info[:2] >= (3, 7):
10+
from importlib.resources import path as _resource_path
11+
else:
12+
from importlib_resources import path as _resource_path
813

914
def _create_xml_schema_validator(source, **kwargs):
1015
kwargs = {

0 commit comments

Comments
 (0)