Skip to content

Commit 6ee7e56

Browse files
authored
Try to access resource using importlib.resources
Merge pull request #134 from scw/use-importlib-resources
2 parents 95fe75d + b07d947 commit 6ee7e56

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/pytz/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ def open_resource(name):
9595
filename = os.path.join(os.path.dirname(__file__),
9696
'zoneinfo', *name_parts)
9797
if not os.path.exists(filename):
98+
# pkg_resources is deprecated, try with importlib first
99+
try:
100+
from importlib.resources import files
101+
except ImportError:
102+
files = None
103+
104+
if files is not None:
105+
# retrieve the zoneinfo file Path object and return its file handle
106+
return files(__name__).joinpath('zoneinfo', *name_parts).open('rb')
107+
98108
# http://bugs.launchpad.net/bugs/383171 - we avoid using this
99109
# unless absolutely necessary to help when a broken version of
100110
# pkg_resources is installed.

0 commit comments

Comments
 (0)