MCPcopy Index your code
hub / github.com/python/cpython / load_tzdata

Function load_tzdata

Lib/zoneinfo/_common.py:4–29  ·  view source on GitHub ↗
(key)

Source from the content-addressed store, hash-verified

2
3
4def 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
32def load_data(fobj):

Callers

nothing calls this directly

Calls 7

splitMethod · 0.45
joinMethod · 0.45
joinpathMethod · 0.45
filesMethod · 0.45
is_dirMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…