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

Method fromfile

Lib/test/datetimetester.py:6631–6665  ·  view source on GitHub ↗
(cls, fileobj)

Source from the content-addressed store, hash-verified

6629
6630 @classmethod
6631 def fromfile(cls, fileobj):
6632 if fileobj.read(4).decode() != "TZif":
6633 raise ValueError("not a zoneinfo file")
6634 fileobj.seek(32)
6635 counts = array('i')
6636 counts.fromfile(fileobj, 3)
6637 if sys.byteorder != 'big':
6638 counts.byteswap()
6639
6640 ut = array('i')
6641 ut.fromfile(fileobj, counts[0])
6642 if sys.byteorder != 'big':
6643 ut.byteswap()
6644
6645 type_indices = array('B')
6646 type_indices.fromfile(fileobj, counts[0])
6647
6648 ttis = []
6649 for i in range(counts[1]):
6650 ttis.append(struct.unpack(">lbb", fileobj.read(6)))
6651
6652 abbrs = fileobj.read(counts[2])
6653
6654 # Convert ttis
6655 for i, (gmtoff, isdst, abbrind) in enumerate(ttis):
6656 abbr = abbrs[abbrind:abbrs.find(0, abbrind)].decode()
6657 ttis[i] = (timedelta(0, gmtoff), isdst, abbr)
6658
6659 ti = [None] * len(ut)
6660 for i, idx in enumerate(type_indices):
6661 ti[i] = ttis[idx]
6662
6663 self = cls(ut, ti)
6664
6665 return self
6666
6667 @classmethod
6668 def fromname(cls, name):

Callers 3

fromnameMethod · 0.80
test_tofromfileMethod · 0.80
test_filewriteMethod · 0.80

Calls 10

timedeltaClass · 0.90
arrayClass · 0.85
enumerateFunction · 0.85
unpackMethod · 0.80
clsClass · 0.50
decodeMethod · 0.45
readMethod · 0.45
seekMethod · 0.45
appendMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected