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

Method _load_file

Lib/zoneinfo/_zoneinfo.py:229–300  ·  view source on GitHub ↗
(self, fobj)

Source from the content-addressed store, hash-verified

227 return _tzpath.find_tzfile(key)
228
229 def _load_file(self, fobj):
230 # Retrieve all the data as it exists in the zoneinfo file
231 trans_idx, trans_utc, utcoff, isdst, abbr, tz_str = _common.load_data(
232 fobj
233 )
234
235 # Infer the DST offsets (needed for .dst()) from the data
236 dstoff = self._utcoff_to_dstoff(trans_idx, utcoff, isdst)
237
238 # Convert all the transition times (UTC) into "seconds since 1970-01-01 local time"
239 trans_local = self._ts_to_local(trans_idx, trans_utc, utcoff)
240
241 # Construct `_ttinfo` objects for each transition in the file
242 _ttinfo_list = [
243 _ttinfo(
244 _load_timedelta(utcoffset), _load_timedelta(dstoffset), tzname
245 )
246 for utcoffset, dstoffset, tzname in zip(utcoff, dstoff, abbr)
247 ]
248
249 self._trans_utc = trans_utc
250 self._trans_local = trans_local
251 self._ttinfos = [_ttinfo_list[idx] for idx in trans_idx]
252
253 # Find the first non-DST transition
254 for i in range(len(isdst)):
255 if not isdst[i]:
256 self._tti_before = _ttinfo_list[i]
257 break
258 else:
259 if self._ttinfos:
260 self._tti_before = self._ttinfos[0]
261 else:
262 self._tti_before = None
263
264 # Set the "fallback" time zone
265 if tz_str is not None and tz_str != b"":
266 self._tz_after = _parse_tz_str(tz_str.decode())
267 else:
268 if not self._ttinfos and not _ttinfo_list:
269 raise ValueError("No time zone information found.")
270
271 if self._ttinfos:
272 self._tz_after = self._ttinfos[-1]
273 else:
274 self._tz_after = _ttinfo_list[-1]
275
276 # Determine if this is a "fixed offset" zone, meaning that the output
277 # of the utcoffset, dst and tzname functions does not depend on the
278 # specific datetime passed.
279 #
280 # We make three simplifying assumptions here:
281 #
282 # 1. If _tz_after is not a _ttinfo, it has transitions that might
283 # actually occur (it is possible to construct TZ strings that
284 # specify STD and DST but no transitions ever occur, such as
285 # AAA0BBB,0/0,J365/25).
286 # 2. If _ttinfo_list contains more than one _ttinfo object, the objects

Callers 2

_new_instanceMethod · 0.80
from_fileMethod · 0.80

Calls 6

_utcoff_to_dstoffMethod · 0.95
_ts_to_localMethod · 0.95
_ttinfoClass · 0.85
_load_timedeltaFunction · 0.85
_parse_tz_strFunction · 0.85
decodeMethod · 0.45

Tested by

no test coverage detected