From dd4c2469054efd7d0c6ca49b95a95e1aeba7a6c5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 28 Dec 2021 16:05:27 -0500 Subject: Prefer resources namespace for context. Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com> --- Lib/zoneinfo/_common.py | 4 ++-- Lib/zoneinfo/_tzpath.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/zoneinfo/_common.py b/Lib/zoneinfo/_common.py index 4c6e0ba5e9..98cdfe37ca 100644 --- a/Lib/zoneinfo/_common.py +++ b/Lib/zoneinfo/_common.py @@ -2,14 +2,14 @@ import struct def load_tzdata(key): - from importlib.resources import files + from importlib import resources components = key.split("/") package_name = ".".join(["tzdata.zoneinfo"] + components[:-1]) resource_name = components[-1] try: - return files(package_name).joinpath(resource_name).open('rb') + 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": diff --git a/Lib/zoneinfo/_tzpath.py b/Lib/zoneinfo/_tzpath.py index 9ce4c88425..4985dce2dc 100644 --- a/Lib/zoneinfo/_tzpath.py +++ b/Lib/zoneinfo/_tzpath.py @@ -111,14 +111,14 @@ def available_timezones(): determine if a given file on the time zone search path is to open it and check for the "magic string" at the beginning. """ - from importlib.resources import files + from importlib import resources valid_zones = set() # 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 files("tzdata").joinpath("zones").open() as f: + with resources.files("tzdata").joinpath("zones").open("r") as f: for zone in f: zone = zone.strip() if zone: -- cgit v1.2.1