Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion 15 Lib/zoneinfo/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def load_tzdata(key):
try:
return importlib.resources.open_binary(package_name, resource_name)
except (ImportError, FileNotFoundError, UnicodeEncodeError):
# There are three types of exception that can be raised that all amount
# There are some 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
Expand All @@ -22,6 +22,19 @@ def load_tzdata(key):
# UnicodeEncodeError: If package_name or resource_name are not UTF-8,
# such as keys containing a surrogate character.
raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
except (IsADirectoryError, PermissionError):
# A few exceptions inherited from OSError can be raised in various scenarios:
#
# IsADirectoryError: If the resource_name links to a directory
# (e.g. Australia)
# PermissionError: If the resource_name links to a directory on Windows
# (e.g. Pacific)
resource_path = importlib.resources.files(package_name).joinpath(key)

if resource_path.is_dir():
raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
else:
raise


def load_data(fobj):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zoneinfo ZoneInfo no longer raises IsADirectoryError or PermissionError when attempting to parse certain keys.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.