mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
[3.13] gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (GH-136117) (#136136)
gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (GH-136117)
(cherry picked from commit ee47670e8b
)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
parent
b415d1c18e
commit
e194793602
2 changed files with 9 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue