MCPcopy Create free account
hub / github.com/dateutil/dateutil / _load_tzdata

Function _load_tzdata

src/dateutil/_tzdata_impl.py:39–62  ·  view source on GitHub ↗
(key)

Source from the content-addressed store, hash-verified

37
38
39def _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
65def _load_tzdata_keys():

Callers

nothing calls this directly

Calls 4

_is_package_directoryFunction · 0.85
TZFileNotFoundClass · 0.85
_open_binaryFunction · 0.85
splitMethod · 0.80

Tested by

no test coverage detected