Skip to content

Commit e86ac72

Browse files
miss-islingtonvstinnerZeroIntensity
authored
[3.14] gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (GH-136117) (#136128)
gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (GH-136117) (cherry picked from commit ee47670) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 71bd3d0 commit e86ac72

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Lib/zoneinfo/_common.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ def load_tzdata(key):
99
resource_name = components[-1]
1010

1111
try:
12-
return resources.files(package_name).joinpath(resource_name).open("rb")
12+
path = resources.files(package_name).joinpath(resource_name)
13+
# gh-85702: Prevent PermissionError on Windows
14+
if path.is_dir():
15+
raise IsADirectoryError
16+
return path.open("rb")
1317
except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError):
14-
# There are three types of exception that can be raised that all amount
18+
# There are four types of exception that can be raised that all amount
1519
# to "we cannot find this key":
1620
#
1721
# ImportError: If package_name doesn't exist (e.g. if tzdata is not
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
If ``zoneinfo._common.load_tzdata`` is given a package without a resource a
2+
:exc:`zoneinfo.ZoneInfoNotFoundError` is raised rather than a :exc:`PermissionError`.
3+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)