Skip to content

Commit b07d947

Browse files
committed
try to access resource using importlib.resources
`pkg_resources` is now deprecated and will throw a DeprecationWarning when importing, try and use the replacement `importlib.resources` (Python 3.7+) if available.
1 parent 00ad7f1 commit b07d947

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)