From 99cdb2191e9ab633579f4e7951c2da042529b95d Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Fri, 4 Dec 2020 10:10:50 +1300 Subject: [PATCH] dbcheck: drop py2 support from dump_attr_values() Signed-off-by: Douglas Bagnall Reviewed-by: Noel Power --- python/samba/dbchecker.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py index 6d16e88868e..3750b7bb45f 100644 --- a/python/samba/dbchecker.py +++ b/python/samba/dbchecker.py @@ -35,25 +35,20 @@ from samba.auth import system_session, admin_session from samba.netcmd import CommandError from samba.netcmd.fsmo import get_fsmo_roleowner -# vals is a sequence of ldb.bytes objects which are a subclass -# of 'byte' type in python3 and just a str type in python2, to -# display as string these need to be converted to string via (str) -# function in python3 but that may generate a UnicodeDecode error, -# if so use repr instead. We need to at least try to get the 'str' -# value if possible to allow some tests which check the strings -# outputted to pass, these tests compare attr values logged to stdout -# against those in various results files. def dump_attr_values(vals): - result = "" + """Stringify a value list, using utf-8 if possible (which some tests + want), or the python bytes representation otherwise (with leading + 'b' and escapes like b'\x00'). + """ + result = [] for value in vals: - if len(result): - result = "," + result try: - result = result + str(value) + result.append(value.decode('utf-8')) except UnicodeDecodeError: - result = result + repr(value) - return result + result.append(repr(value)) + return ','.join(result) + class dbcheck(object): """check a SAM database for errors""" -- 2.47.3