(key)
| 2 | |
| 3 | |
| 4 | def load_tzdata(key): |
| 5 | from importlib import resources |
| 6 | |
| 7 | components = key.split("/") |
| 8 | package_name = ".".join(["tzdata.zoneinfo"] + components[:-1]) |
| 9 | resource_name = components[-1] |
| 10 | |
| 11 | try: |
| 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") |
| 17 | except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError): |
| 18 | # There are four types of exception that can be raised that all amount |
| 19 | # to "we cannot find this key": |
| 20 | # |
| 21 | # ImportError: If package_name doesn't exist (e.g. if tzdata is not |
| 22 | # installed, or if there's an error in the folder name like |
| 23 | # Amrica/New_York) |
| 24 | # FileNotFoundError: If resource_name doesn't exist in the package |
| 25 | # (e.g. Europe/Krasnoy) |
| 26 | # UnicodeEncodeError: If package_name or resource_name are not UTF-8, |
| 27 | # such as keys containing a surrogate character. |
| 28 | # IsADirectoryError: If package_name without a resource_name specified. |
| 29 | raise ZoneInfoNotFoundError(f"No time zone found with key {key}") |
| 30 | |
| 31 | |
| 32 | def load_data(fobj): |
nothing calls this directly
no test coverage detected
searching dependent graphs…