Skip to content

Commit

Permalink
Use the importlib.resources backport on Python < 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
dstufft committed Apr 5, 2020
1 parent 4bf7d9e commit 7f912f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
10 changes: 3 additions & 7 deletions certifi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
try:
from importlib.resources import read_text
except ImportError:
# This fallback will work for Python versions prior to 3.7 that lack the
# importlib.resources module but relies on the existing `where` function
# so won't address issues with environments like PyOxidizer that don't set
# __file__ on modules.
def read_text(_module, _path, encoding="ascii"):
with open(where(), "r", encoding=encoding) as data:
return data.read()
# Use the backport of importlib.resources for versions of Python that
# don't have importlib.resources
from importlib_resources import read_text


def where():
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@
'Documentation': 'https://certifiio.readthedocs.io/en/latest/',
'Source': 'https://github.com/certifi/python-certifi',
},
extras_require={":python_version < '3.7'": ["importlib-resources"],},
)

0 comments on commit 7f912f4

Please sign in to comment.