MCPcopy Index your code
hub / github.com/RustPython/RustPython / touch_zone

Method touch_zone

Lib/test/test_zoneinfo/test_zoneinfo.py:1868–1882  ·  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

1866 return f.read()
1867
1868 def touch_zone(self, key, tz_root):
1869 """Creates a valid TZif file at key under the zoneinfo root tz_root.
1870
1871 tz_root must exist, but all folders below that will be created.
1872 """
1873 if not os.path.exists(tz_root):
1874 raise FileNotFoundError(f"{tz_root} does not exist.")
1875
1876 root_dir, *tail = key.rsplit("/", 1)
1877 if tail: # If there's no tail, then the first component isn't a dir
1878 os.makedirs(os.path.join(tz_root, root_dir), exist_ok=True)
1879
1880 zonefile_path = os.path.join(tz_root, key)
1881 with open(zonefile_path, "wb") as f:
1882 f.write(self._UTC_bytes)
1883
1884 def test_getattr_error(self):
1885 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