python/samba/gp_parse: PY2/PY3 Decode only when necessary
authorNoel Power <noel.power@suse.com>
Wed, 5 Sep 2018 16:01:17 +0000 (17:01 +0100)
committerNoel Power <npower@samba.org>
Mon, 5 Nov 2018 19:05:24 +0000 (20:05 +0100)
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 <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/gp_parse/gp_csv.py

index 9338cedcf15091c89133ff370d3b5f9aa8e09f60..9e188db47b58b8a380080c935881216db30b48d1 100644 (file)
@@ -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)