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

Skip to content

Commit 9473c00

Browse files
committed
bpo-46124: Update zoneinfo to rely on importlib.resources traversable API.
1 parent fe68486 commit 9473c00

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
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.resources import files
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 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ def available_timezones():
111111
determine if a given file on the time zone search path is to open it
112112
and check for the "magic string" at the beginning.
113113
"""
114-
from importlib import resources
114+
from importlib.resources import files
115115

116116
valid_zones = set()
117117

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 files("tzdata").joinpath("zones").open() 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 zoneinfo to rely on importlib.resources traversable API.

0 commit comments

Comments
 (0)
0