(key)
| 37 | |
| 38 | |
| 39 | def _load_tzdata(key): |
| 40 | components = key.split("/") |
| 41 | package_name = ".".join(["tzdata.zoneinfo"] + components[:-1]) |
| 42 | resource_name = components[-1] |
| 43 | |
| 44 | # Empty or relative path components cannot name a zone, and they produce |
| 45 | # module names that the import machinery handles inconsistently across |
| 46 | # versions, so treat them as not found up front. A key naming a directory |
| 47 | # (a subpackage) is not a zone either, and opening it raises a |
| 48 | # platform-dependent error, see CPython gh-85702. |
| 49 | if any(c in ("", ".", "..") for c in components) or _is_package_directory( |
| 50 | package_name, resource_name |
| 51 | ): |
| 52 | raise TZFileNotFound("Time zone not found: %s", zone_key=key) |
| 53 | |
| 54 | try: |
| 55 | return _open_binary(package_name, resource_name) |
| 56 | except _TZDATA_LOAD_EXCEPTIONS: |
| 57 | # ImportError: package does not exist (or tzdata is not installed) |
| 58 | # FileNotFoundError: the key is not a file in the package |
| 59 | # UnicodeEncodeError: the key is not encodable as a filename |
| 60 | # IsADirectoryError: the key names a package rather than a resource |
| 61 | # ValueError: the key is not a valid path (e.g. contains a NUL byte) |
| 62 | raise TZFileNotFound("Time zone not found: %s", zone_key=key) from None |
| 63 | |
| 64 | |
| 65 | def _load_tzdata_keys(): |
nothing calls this directly
no test coverage detected