]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (#136117)
authorVictor Stinner <vstinner@python.org>
Mon, 30 Jun 2025 14:33:01 +0000 (16:33 +0200)
committerGitHub <noreply@github.com>
Mon, 30 Jun 2025 14:33:01 +0000 (16:33 +0200)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Lib/zoneinfo/_common.py
Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst [new file with mode: 0644]

index 6e05abc32394bca962ae5ead89182acd3d24b6e2..03cc42149f9b74b1e8d8175ca469b43f10fa2d07 100644 (file)
@@ -9,9 +9,13 @@ def load_tzdata(key):
     resource_name = components[-1]
 
     try:
-        return resources.files(package_name).joinpath(resource_name).open("rb")
+        path = resources.files(package_name).joinpath(resource_name)
+        # gh-85702: Prevent PermissionError on Windows
+        if path.is_dir():
+            raise IsADirectoryError
+        return path.open("rb")
     except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError):
-        # There are three types of exception that can be raised that all amount
+        # There are four types of exception that can be raised that all amount
         # to "we cannot find this key":
         #
         # ImportError: If package_name doesn't exist (e.g. if tzdata is not
diff --git a/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst b/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst
new file mode 100644 (file)
index 0000000..fc13eb1
--- /dev/null
@@ -0,0 +1,3 @@
+If ``zoneinfo._common.load_tzdata`` is given a package without a resource a
+:exc:`zoneinfo.ZoneInfoNotFoundError` is raised rather than a :exc:`PermissionError`.
+Patch by Victor Stinner.