8000 bpo-46124: Update zoneinfo to rely on importlib.resources traversable… · python/cpython@00b2b57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00b2b57

Browse files
authored
bpo-46124: Update zoneinfo to rely on importlib.resources traversable API. (GH-30190)
Automerge-Triggered-By: GH:jaraco
1 parent f1e559b commit 00b2b57

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

Lib/zoneinfo/_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33

44
def load_tzdata(key):
5-
import importlib.resources
5+
from importlib import resources
66

77
components = key.split("/")
88
package_name = ".".join(["tzdata.zoneinfo"] + components[:-1])
99
resource_name = components[-1]
1010

1111
try:
12-
return importlib.resources.open_binary(package_name, resource_name)
12+
return resources.files(package_name).joinpath(resource_name).open("rb")
1313
except (ImportError, FileNotFoundError, UnicodeEncodeError):
1414
# There are three types of exception that can be raised that all amount
1515
# to "we cannot find this key":

Lib/zoneinfo/_tzpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def available_timezones():
118118
# Start with loading from the tzdata package if it exists: this has a
119119
# pre-assembled list of zones that only requires opening one file.
120120
try:
121-
with resources.open_text("tzdata", "zones") as f:
121+
with resources.files("tzdata").joinpath("zones").open("r") as f:
122122
for zone in f:
123123
zone = zone.strip()
124124
if zone:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update :mod:`zoneinfo` to rely on importlib.resources traversable API.

0 commit comments

Comments
 (0)
0