From 6347b0c3736e1208d09f94e2b67f1b4234205374 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Wed, 12 Jun 2024 11:34:36 +1200 Subject: [PATCH] pytest: simplify and fix HEXDUMP_FILTER used in hexdumps The old test x if ((len(repr(chr(x))) == 3) and (x < 127)) else ord('.') went through some contortions to see if the character was printable, and it got it slightly wrong. The idea was that `repr(chr(97)` is "'a'", while `repr(chr(167)` is "'\xa7'", which we can distinguish using the length. But that miscategorised the backslash character, which is represented as "'\\'", a string of length 4, so it was show as '.' instead. Instead we notice that the characters we want to print in a hexdump are exactly those between 32 and 126, inclusive. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- python/samba/tests/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py index 136dd2fc316..ef57309ab70 100644 --- a/python/samba/tests/__init__.py +++ b/python/samba/tests/__init__.py @@ -57,7 +57,8 @@ from unittest import SkipTest BINDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../bin")) -HEXDUMP_FILTER = bytearray([x if ((len(repr(chr(x))) == 3) and (x < 127)) else ord('.') for x in range(256)]) +# HEXDUMP_FILTER maps ASCII control characters to '.', printables to themselves +HEXDUMP_FILTER = bytearray(x if (x > 31 and x < 127) else 46 for x in range(256)) LDB_ERR_LUT = {v: k for k, v in vars(ldb).items() if k.startswith('ERR_')} -- 2.47.3