From 40ae09dca88d813b760e6cf23598f29d29f17eb9 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Wed, 26 Jul 2023 07:56:31 +0000 Subject: [PATCH] py3.8 compat --- src/main.py | 5 +++-- src/util/compat.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/util/compat.py diff --git a/src/main.py b/src/main.py index 7f5c1b339..5c69c884b 100644 --- a/src/main.py +++ b/src/main.py @@ -3,6 +3,7 @@ import stat import time import logging +from util.compat import * startup_errors = [] def startupError(msg): @@ -54,12 +55,12 @@ def importBundle(bundle): else: prefix = '' top_2 = list(set(filter(lambda f: len(f)>0, - map(lambda f: f.removeprefix(prefix).split('/')[0], all_files)))) + map(lambda f: removeprefix(f, prefix).split('/')[0], all_files)))) for d in top_2: if isValidAddress(d): logging.info(f'unpack {d} into {config.data_dir}') for fname in filter(lambda f: f.startswith(prefix+d) and not f.endswith('/'), all_files): - tgt = config.data_dir + '/' + fname.removeprefix(prefix) + tgt = config.data_dir + '/' + removeprefix(fname, prefix) logging.info(f'-- {fname} --> {tgt}') info = zf.getinfo(fname) info.filename = tgt diff --git a/src/util/compat.py b/src/util/compat.py new file mode 100644 index 000000000..f41e67b25 --- /dev/null +++ b/src/util/compat.py @@ -0,0 +1,16 @@ +import sys + +if sys.version_info.major == 3 and sys.version_info.minor < 9: + def removeprefix(s, prefix, /): + if s.startswith(prefix): + return s[len(prefix):] + return s + def removesuffix(s, suffix, /): + if s.endswith(suffix): + return s[:-len(suffix)] + return s +else: + def removeprefix(s, prefix, /): + return s.removeprefix(prefix) + def removesuffix(s, suffix, /): + return s.removesuffix(suffix)