]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-139188: Remove `Tools/tz/zdump.py` script (GH-139189)
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Thu, 30 Oct 2025 11:12:45 +0000 (11:12 +0000)
committerGitHub <noreply@github.com>
Thu, 30 Oct 2025 11:12:45 +0000 (12:12 +0100)
Misc/NEWS.d/next/Tools-Demos/2025-09-20-20-31-54.gh-issue-139188.zfcxkW.rst [new file with mode: 0644]
Tools/README
Tools/tz/zdump.py [deleted file]

diff --git a/Misc/NEWS.d/next/Tools-Demos/2025-09-20-20-31-54.gh-issue-139188.zfcxkW.rst b/Misc/NEWS.d/next/Tools-Demos/2025-09-20-20-31-54.gh-issue-139188.zfcxkW.rst
new file mode 100644 (file)
index 0000000..9f52d01
--- /dev/null
@@ -0,0 +1 @@
+Remove ``Tools/tz/zdump.py`` script.
index c8a34d82206672e770387fadde0c4fecbb0ce436..22d76dfdbcf4a4bccbc494feb6cdbaaaeaaee6fd 100644 (file)
@@ -51,8 +51,6 @@ ssl             Scripts to generate ssl_data.h from OpenSSL sources, and run
 
 tsan            Utilities for building CPython with thread-sanitizer.
 
-tz              A script to dump timezone from /usr/share/zoneinfo.
-
 unicode         Tools for generating unicodedata and codecs from unicode.org
                 and other mapping files (by Fredrik Lundh, Marc-Andre Lemburg
                 and Martin von Loewis).
diff --git a/Tools/tz/zdump.py b/Tools/tz/zdump.py
deleted file mode 100644 (file)
index 39de0a4..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-import sys
-import os
-import struct
-from array import array
-from collections import namedtuple
-from datetime import datetime
-
-ttinfo = namedtuple('ttinfo', ['tt_gmtoff', 'tt_isdst', 'tt_abbrind'])
-
-class TZInfo:
-    def __init__(self, transitions, type_indices, ttis, abbrs):
-        self.transitions = transitions
-        self.type_indices = type_indices
-        self.ttis = ttis
-        self.abbrs = abbrs
-
-    @classmethod
-    def fromfile(cls, fileobj):
-        if fileobj.read(4).decode() != "TZif":
-            raise ValueError("not a zoneinfo file")
-        fileobj.seek(20)
-        header = fileobj.read(24)
-        tzh = (tzh_ttisgmtcnt, tzh_ttisstdcnt, tzh_leapcnt,
-               tzh_timecnt, tzh_typecnt, tzh_charcnt) = struct.unpack(">6l", header)
-        transitions = array('i')
-        transitions.fromfile(fileobj, tzh_timecnt)
-        if sys.byteorder != 'big':
-            transitions.byteswap()
-
-        type_indices = array('B')
-        type_indices.fromfile(fileobj, tzh_timecnt)
-
-        ttis = []
-        for i in range(tzh_typecnt):
-            ttis.append(ttinfo._make(struct.unpack(">lbb", fileobj.read(6))))
-
-        abbrs = fileobj.read(tzh_charcnt)
-
-        self = cls(transitions, type_indices, ttis, abbrs)
-        self.tzh = tzh
-
-        return self
-
-    def dump(self, stream, start=None, end=None):
-        for j, (trans, i) in enumerate(zip(self.transitions, self.type_indices)):
-            utc = datetime.utcfromtimestamp(trans)
-            tti = self.ttis[i]
-            lmt = datetime.utcfromtimestamp(trans + tti.tt_gmtoff)
-            abbrind = tti.tt_abbrind
-            abbr = self.abbrs[abbrind:self.abbrs.find(0, abbrind)].decode()
-            if j > 0:
-                prev_tti = self.ttis[self.type_indices[j - 1]]
-                shift = " %+g" % ((tti.tt_gmtoff - prev_tti.tt_gmtoff) / 3600)
-            else:
-                shift = ''
-            print("%s UTC = %s %-5s isdst=%d" % (utc, lmt, abbr, tti[1]) + shift, file=stream)
-
-    @classmethod
-    def zonelist(cls, zonedir='/usr/share/zoneinfo'):
-        zones = []
-        for root, _, files in os.walk(zonedir):
-            for f in files:
-                p = os.path.join(root, f)
-                with open(p, 'rb') as o:
-                    magic =  o.read(4)
-                if magic == b'TZif':
-                    zones.append(p[len(zonedir) + 1:])
-        return zones
-
-if __name__ == '__main__':
-    if len(sys.argv) < 2:
-        zones = TZInfo.zonelist()
-        for z in zones:
-            print(z)
-        sys.exit()
-    filepath = sys.argv[1]
-    if not filepath.startswith('/'):
-        filepath = os.path.join('/usr/share/zoneinfo', filepath)
-    with open(filepath, 'rb') as fileobj:
-        tzi = TZInfo.fromfile(fileobj)
-    tzi.dump(sys.stdout)