From: Douglas Bagnall Date: Tue, 11 Jun 2024 23:34:36 +0000 (+1200) Subject: pytest: simplify and fix HEXDUMP_FILTER used in hexdumps X-Git-Tag: tdb-1.4.11~371 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6347b0c3736e1208d09f94e2b67f1b4234205374;p=thirdparty%2Fsamba.git 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 --- 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_')}