From: Noel Power Date: Wed, 5 Sep 2018 16:01:17 +0000 (+0100) Subject: python/samba/gp_parse: PY2/PY3 Decode only when necessary X-Git-Tag: tdb-1.3.17~921 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc047c2cf458e08e2689ff27677d8622f4507c82;p=thirdparty%2Fsamba.git python/samba/gp_parse: PY2/PY3 Decode only when necessary In python2 we decode str types in load_xml, in python3 these are str class(s) which we cannot decode. Signed-off-by: Noel Power Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/gp_parse/gp_csv.py b/python/samba/gp_parse/gp_csv.py index 9338cedcf15..9e188db47b5 100644 --- a/python/samba/gp_parse/gp_csv.py +++ b/python/samba/gp_parse/gp_csv.py @@ -25,7 +25,7 @@ from io import BytesIO from xml.etree.ElementTree import Element, SubElement from samba.compat import PY3 from samba.gp_parse import GPParser - +from samba.compat import text_type # [MS-GPAC] Group Policy Audit Configuration class GPAuditCsvParser(GPParser): encoding = 'utf-8' @@ -82,12 +82,15 @@ class GPAuditCsvParser(GPParser): header = False self.header = [] for v in r.findall('Value'): - self.header.append(v.text.decode(self.output_encoding)) + if not isinstance(v.text, text_type): + v.text = v.text.decode(self.output_encoding) + self.header.append(v.text) else: line = {} for i, v in enumerate(r.findall('Value')): line[self.header[i]] = v.text if v.text is not None else '' - line[self.header[i]] = line[self.header[i]].decode(self.output_encoding) + if not isinstance(self.header[i], text_type): + line[self.header[i]] = line[self.header[i]].decode(self.output_encoding) self.lines.append(line)