8000 bpo-46124: Update zoneinfo to rely on importlib.resources traversable API. by jaraco · Pull Request #30190 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46124: Update zoneinfo to rely on importlib.resources traversable API. #30190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/zoneinfo/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@


def load_tzdata(key):
import importlib.resources
from importlib import resources

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

try:
return importlib.resources.open_binary(package_name, resource_name)
return resources.files(package_name).joinpath(resource_name).open("rb")
except (ImportError, FileNotFoundError, UnicodeEncodeError):
# There are three types of exception that can be raised that all amount
# to "we cannot find this key":
Expand Down
2 changes: 1 addition & 1 deletion Lib/zoneinfo/_tzpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def available_timezones():
# Start with loading from the tzdata package if it exists: this has a
# pre-assembled list of zones that only requires opening one file.
try:
with resources.open_text("tzdata", "zones") as f:
with resources.files("tzdata").joinpath("zones").open("r") as f:
for zone in f:
zone = zone.strip()
if zone:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update :mod:`zoneinfo` to rely on importlib.resources traversable API.
0