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

Method touch_zone

Lib/test/test_zoneinfo/test_zoneinfo.py:1949–1963  ·  view source on GitHub ↗

Creates a valid TZif file at key under the zoneinfo root tz_root. tz_root must exist, but all folders below that will be created.

(self, key, tz_root)

Source from the content-addressed store, hash-verified

1947 return f.read()
1948
1949 def touch_zone(self, key, tz_root):
1950 """Creates a valid TZif file at key under the zoneinfo root tz_root.
1951
1952 tz_root must exist, but all folders below that will be created.
1953 """
1954 if not os.path.exists(tz_root):
1955 raise FileNotFoundError(f"{tz_root} does not exist.")
1956
1957 root_dir, *tail = key.rsplit("/", 1)
1958 if tail: # If there's no tail, then the first component isn't a dir
1959 os.makedirs(os.path.join(tz_root, root_dir), exist_ok=True)
1960
1961 zonefile_path = os.path.join(tz_root, key)
1962 with open(zonefile_path, "wb") as f:
1963 f.write(self._UTC_bytes)
1964
1965 def test_getattr_error(self):
1966 with self.assertRaises(AttributeError):

Calls 5

openFunction · 0.50
existsMethod · 0.45
rsplitMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected