mirror of
https://github.com/python/cpython.git
synced 2026-01-04 06:22:20 +00:00
gh-85702: Catch IsADirectoryError in zoneinfo (#131333)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
bd47ec954d
commit
d22604a6d1
3 changed files with 5 additions and 1 deletions
|
|
@ -222,6 +222,7 @@ def test_bad_keys(self):
|
|||
"America.Los_Angeles",
|
||||
"🇨🇦", # Non-ascii
|
||||
"America/New\ud800York", # Contains surrogate character
|
||||
"Europe", # Is a directory, see issue gh-85702
|
||||
]
|
||||
|
||||
for bad_key in bad_keys:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ def load_tzdata(key):
|
|||
|
||||
try:
|
||||
return resources.files(package_name).joinpath(resource_name).open("rb")
|
||||
except (ImportError, FileNotFoundError, UnicodeEncodeError):
|
||||
except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError):
|
||||
# There are three types of exception that can be raised that all amount
|
||||
# to "we cannot find this key":
|
||||
#
|
||||
|
|
@ -21,6 +21,7 @@ def load_tzdata(key):
|
|||
# (e.g. Europe/Krasnoy)
|
||||
# UnicodeEncodeError: If package_name or resource_name are not UTF-8,
|
||||
# such as keys containing a surrogate character.
|
||||
# IsADirectoryError: If package_name without a resource_name specified.
|
||||
raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
If ``zoneinfo._common.load_tzdata`` is given a package without a resource a
|
||||
``ZoneInfoNotFoundError`` is raised rather than a :exc:`IsADirectoryError`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue