Skip to content
Open
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
10 changes: 6 additions & 4 deletions Lib/zoneinfo/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ def load_tzdata(key):
if path.is_dir():
raise IsADirectoryError
return path.open("rb")
except UnicodeEncodeError:
# This error occurs because of unsupported filesystem encoding which
# depends on the locale, such as keys containing a surrogate character.
ZoneInfoNotFoundError(f"key {key} contains non-UTF8 character(s)")
except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError):
# There are four types of exception that can be raised that all amount
# to "we cannot find this key":
# There are three other 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
# installed, or if there's an error in the folder name like
# Amrica/New_York)
# FileNotFoundError: If resource_name doesn't exist in the package
# (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}")

Expand Down
Loading