From cb24cf596fdb5a8fab82cc790a4729bd79bebc3b Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 23 Nov 2021 19:09:06 +0100 Subject: [PATCH] Always use the slow path for isprintable --- Tools/scripts/deepfreeze.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py index f328817231e37a..85c385c9f9f67b 100644 --- a/Tools/scripts/deepfreeze.py +++ b/Tools/scripts/deepfreeze.py @@ -15,22 +15,23 @@ verbose = False -# See Objects/unicodectype.c:_PyUnicode_IsPrintable +# See Objects/unicodectype.c:_PyUnicode_IsPrintable() NON_PRINTABLE = {"Cc", "Cf", "Cs", "Co", "Cn", "Zl", "Zp", "Zs"} def isprintable(b: bytes) -> bool: - if sys.version_info > (3, 7): - return b.isascii() and b.decode("ascii").isprintable() - else: - try: - s = b.decode("ascii") - except UnicodeDecodeError: + """isascii() and isprintable() for Python 3.6 + + return b.isascii() and b.decode("ascii").isprintable() + """ + try: + s = b.decode("ascii") + except UnicodeDecodeError: + return False + for c in s: + if unicodedata.category(c) in NON_PRINTABLE: return False - for c in s: - if unicodedata.category(c) in NON_PRINTABLE: - return False - return True + return True def make_string_literal(b: bytes) -> str: