From: Noel Power Date: Wed, 5 Sep 2018 11:52:30 +0000 (+0100) Subject: python/samba/gp_parse: PY3 open file non-binary mode for write_binary X-Git-Tag: tdb-1.3.17~928 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d40ef736d5ee34ad5b575dc32f89d0f4cc1885b8;p=thirdparty%2Fsamba.git python/samba/gp_parse: PY3 open file non-binary mode for write_binary Although this is unintuitive it's because we are writing unicode not bytes (both in PY2 & PY3). using the 'b' mode causes an error in PY3. In PY3 we can define the encoding, but not in PY2. 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 cd30ef2bc00..280e83175dc 100644 --- a/python/samba/gp_parse/gp_csv.py +++ b/python/samba/gp_parse/gp_csv.py @@ -23,7 +23,7 @@ import io from io import BytesIO from xml.etree.ElementTree import Element, SubElement - +from samba.compat import PY3 from samba.gp_parse import GPParser # [MS-GPAC] Group Policy Audit Configuration @@ -93,11 +93,9 @@ class GPAuditCsvParser(GPParser): self.lines.append(line) def write_binary(self, filename): - with open(filename, 'wb') as f: - # This should be using a unicode writer, but it seems to be in the - # right encoding at least by default. - # - # writer = UnicodeWriter(f, quoting=csv.QUOTE_MINIMAL) + from io import open + with open(filename, 'w', self.encoding) as f: + # In this case "binary" means "utf-8", so we let Python do that. writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL) writer.writerow(self.header) for line in self.lines: