From df59d3af429d46ee575ab5d3a7fe3f8cd49a74bc Mon Sep 17 00:00:00 2001 From: Stuart Bishop Date: Mon, 22 Mar 2021 08:36:34 +0000 Subject: Complete switch of code generation to Python3 --- Makefile | 3 ++- gen_tests.py | 6 +++--- gen_tzinfo.py | 11 ++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index ac0a755..5c42fb3 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,9 @@ PYTHON36=python3.6 PYTHON37=python3.7 PYTHON38=python3.8 PYTHON39=python3.9 -PYTHON=/usr/bin/python +PYTHON2=/usr/bin/python2 PYTHON3=/usr/bin/python3 +PYTHON=${PYTHON3} IANA=./tz IANA_GIT=https://github.com/eggert/tz.git diff --git a/gen_tests.py b/gen_tests.py index cff1204..5ba0648 100644 --- a/gen_tests.py +++ b/gen_tests.py @@ -28,14 +28,14 @@ def main(): # files and will output historical records we can't cope with # otherwise. command = [zdump, '-v', '-c', '1902,2038', zone] - zd_out = subprocess.check_output(command) + zd_out = subprocess.check_output(command, encoding="utf8") # Skip bogus output on 64bit architectures, per Bug #213816 lines = [ line.strip() for line in zd_out.splitlines() - if not line.decode('utf-8').strip().endswith('NULL')] + if not line.strip().endswith('NULL')] for line in lines: - print >> datf, line + print(line, file=datf) datf.flush() datf.close() diff --git a/gen_tzinfo.py b/gen_tzinfo.py index 0d1c9c8..3c372dd 100644 --- a/gen_tzinfo.py +++ b/gen_tzinfo.py @@ -23,7 +23,7 @@ def allzones(): for dirpath, dirnames, filenames in os.walk(zoneinfo): for f in filenames: p = os.path.join(dirpath, f) - if open(p, 'rb').read(4) == 'TZif': + if open(p, 'rb').read(4) == b'TZif': zones.append(p) stripnum = len(os.path.commonprefix(zones)) zones = [z[stripnum:] for z in zones] @@ -41,19 +41,16 @@ def allzones(): zones = [z for z in zones if 'Riyadh8' not in z and z not in [ 'Factory', 'localtime', 'posixrules']] zones.sort() + assert len(zones) > 0 return zones def links(): '''Mapping of alias -> canonical name''' l = {} - olson_src_files = glob('tz/*') - assert olson_src_files, 'No src files' + olson_src_files = ['tz/vanguard.zi', 'tz/main.zi', 'tz/rearguard.zi'] for filename in olson_src_files: - # Filenames containing a '.' are not data files. - if '.' in os.path.basename(filename): - continue - for line in open(filename): + for line in open(filename, 'r'): if line.strip().startswith('#') or not line.strip(): continue match = re.search(r'^\s*Link\s+([\w/\-]+)\s+([\w/\-]+)', line) -- cgit v1.2.1