]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46124: Update zoneinfo to rely on importlib.resources traversable API. (GH-30190)
authorJason R. Coombs <jaraco@jaraco.com>
Fri, 21 Jan 2022 21:18:31 +0000 (16:18 -0500)
committerGitHub <noreply@github.com>
Fri, 21 Jan 2022 21:18:31 +0000 (13:18 -0800)
Automerge-Triggered-By: GH:jaraco
Lib/zoneinfo/_common.py
Lib/zoneinfo/_tzpath.py
Misc/NEWS.d/next/Library/2021-12-18-18-41-30.bpo-46124.ESPrb7.rst [new file with mode: 0644]

index 4c24f01bd7b270eac5579680bee572c7b7ef0e88..98cdfe37ca6caef972d20bf15fce8f664adbad6a 100644 (file)
@@ -2,14 +2,14 @@ import struct
 
 
 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":
index 672560b9514429e18598cdada8e1a086c6b29cef..4985dce2dc36d0e6b3c9c9dddc1fb69fd7667768 100644 (file)
@@ -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:
diff --git a/Misc/NEWS.d/next/Library/2021-12-18-18-41-30.bpo-46124.ESPrb7.rst b/Misc/NEWS.d/next/Library/2021-12-18-18-41-30.bpo-46124.ESPrb7.rst
new file mode 100644 (file)
index 0000000..26f9f81
--- /dev/null
@@ -0,0 +1 @@
+Update :mod:`zoneinfo` to rely on importlib.resources traversable API.