From df578e1554630f6781d40d4820c9026bb7b01d2d Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 5 Sep 2018 14:18:16 +0100 Subject: [PATCH] python/samba/gp_parse: Use csv.reader for parsing cvs files The previous version here was using UnicodeReader which was wrapping the UTF8Recoder class and passing that to csv.reader. It looks like the intention was to read a bytestream in a certain encoding and then reencode it to a different encoding. And then UnicodeReader creates unicode from the newly encoded stream. This is unnecssary, we know the encoding of the bytesstream and codec.getreader will happily consume the bytstream and give back unicode. The unicode can be fed directly into csv.writer. Signed-off-by: Noel Power Reviewed-by: Douglas Bagnall --- python/samba/gp_parse/gp_csv.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/samba/gp_parse/gp_csv.py b/python/samba/gp_parse/gp_csv.py index 280e83175dc..f1be04c43d3 100644 --- a/python/samba/gp_parse/gp_csv.py +++ b/python/samba/gp_parse/gp_csv.py @@ -34,10 +34,9 @@ class GPAuditCsvParser(GPParser): def parse(self, contents): self.lines = [] - reader = UnicodeReader(BytesIO(contents), - encoding=self.encoding) + reader = csv.reader(codecs.getreader(self.encoding)(BytesIO(contents))) - self.header = reader.next() + self.header = next(reader) for row in reader: line = {} for i, x in enumerate(row): -- 2.34.1