mirror of
https://github.com/samba-team/samba.git
synced 2025-12-16 00:23:52 +03:00
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 <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
@@ -23,7 +23,7 @@ import io
|
|||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from xml.etree.ElementTree import Element, SubElement
|
from xml.etree.ElementTree import Element, SubElement
|
||||||
|
from samba.compat import PY3
|
||||||
from samba.gp_parse import GPParser
|
from samba.gp_parse import GPParser
|
||||||
|
|
||||||
# [MS-GPAC] Group Policy Audit Configuration
|
# [MS-GPAC] Group Policy Audit Configuration
|
||||||
@@ -93,11 +93,9 @@ class GPAuditCsvParser(GPParser):
|
|||||||
self.lines.append(line)
|
self.lines.append(line)
|
||||||
|
|
||||||
def write_binary(self, filename):
|
def write_binary(self, filename):
|
||||||
with open(filename, 'wb') as f:
|
from io import open
|
||||||
# This should be using a unicode writer, but it seems to be in the
|
with open(filename, 'w', self.encoding) as f:
|
||||||
# right encoding at least by default.
|
# In this case "binary" means "utf-8", so we let Python do that.
|
||||||
#
|
|
||||||
# writer = UnicodeWriter(f, quoting=csv.QUOTE_MINIMAL)
|
|
||||||
writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
|
writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
|
||||||
writer.writerow(self.header)
|
writer.writerow(self.header)
|
||||||
for line in self.lines:
|
for line in self.lines:
|
||||||
|
|||||||
Reference in New Issue
Block a user