Use is_printable in definition of _TRANSLATE_NONPRINTABLES

This commit is contained in:
dgelessus 2020-07-06 18:01:02 +02:00
parent b0eefe3889
commit b46018e666
1 changed files with 4 additions and 3 deletions

View File

@ -11,9 +11,6 @@ from . import __version__, api, compress
# The encoding to use when rendering bytes as text (in four-char codes, strings, hex dumps, etc.) or reading a quoted byte string (from the command line).
_TEXT_ENCODING = "MacRoman"
# Translation table to replace ASCII non-printable characters with periods.
_TRANSLATE_NONPRINTABLES = {k: "." for k in [*range(0x20), 0x7f]}
_REZ_ATTR_NAMES = {
api.ResourceAttrs.resSysRef: None, # "Illegal or reserved attribute"
api.ResourceAttrs.resSysHeap: "sysheap",
@ -43,6 +40,10 @@ def is_printable(char: str) -> bool:
return char.isprintable() or char == "\uf8ff"
# Translation table to replace non-printable characters with periods.
_TRANSLATE_NONPRINTABLES = {ord(c): "." for c in bytes(range(256)).decode(_TEXT_ENCODING) if not is_printable(c)}
def bytes_unescape(string: str) -> bytes:
"""Convert a string containing text (in _TEXT_ENCODING) and hex escapes to a bytestring.