Skip to content

Commit cb24cf5

Browse files
committed
Always use the slow path for isprintable
1 parent 055b662 commit cb24cf5

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Tools/scripts/deepfreeze.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,23 @@
1515

1616
verbose = False
1717

18-
# See Objects/unicodectype.c:_PyUnicode_IsPrintable
18+
# See Objects/unicodectype.c:_PyUnicode_IsPrintable()
1919
NON_PRINTABLE = {"Cc", "Cf", "Cs", "Co", "Cn", "Zl", "Zp", "Zs"}
2020

2121

2222
def isprintable(b: bytes) -> bool:
23-
if sys.version_info > (3, 7):
24-
return b.isascii() and b.decode("ascii").isprintable()
25-
else:
26-
try:
27-
s = b.decode("ascii")
28-
except UnicodeDecodeError:
23+
"""isascii() and isprintable() for Python 3.6
24+
25+
return b.isascii() and b.decode("ascii").isprintable()
26+
"""
27+
try:
28+
s = b.decode("ascii")
29+
except UnicodeDecodeError:
30+
return False
31+
for c in s:
32+
if unicodedata.category(c) in NON_PRINTABLE:
2933
return False
30-
for c in s:
31-
if unicodedata.category(c) in NON_PRINTABLE:
32-
return False
33-
return True
34+
return True
3435

3536

3637
def make_string_literal(b: bytes) -> str:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy