| 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): |