MCPcopy Create free account
hub / github.com/python/cpython / _convert_to_v1

Method _convert_to_v1

Lib/test/test_zoneinfo/test_zoneinfo.py:2204–2230  ·  view source on GitHub ↗
(self, contents)

Source from the content-addressed store, hash-verified

2202 return lzma.decompress(decoded)
2203
2204 def _convert_to_v1(self, contents):
2205 assert contents[0:4] == b"TZif", "Invalid TZif data found!"
2206 version = int(contents[4:5])
2207
2208 header_start = 4 + 16
2209 header_end = header_start + 24 # 6l == 24 bytes
2210 assert version >= 2, "Version 1 file found: no conversion necessary"
2211 isutcnt, isstdcnt, leapcnt, timecnt, typecnt, charcnt = struct.unpack(
2212 ">6l", contents[header_start:header_end]
2213 )
2214
2215 file_size = (
2216 timecnt * 5
2217 + typecnt * 6
2218 + charcnt
2219 + leapcnt * 8
2220 + isstdcnt
2221 + isutcnt
2222 )
2223 file_size += header_end
2224 out = b"TZif" + b"\x00" + contents[5:file_size]
2225
2226 assert (
2227 contents[file_size : (file_size + 4)] == b"TZif"
2228 ), "Version 2 file not truncated at Version 2 header"
2229
2230 return out
2231
2232
2233class ZoneDumpData:

Callers 1

_populate_tzpathMethod · 0.95

Calls 1

unpackMethod · 0.80

Tested by

no test coverage detected