From: Noel Power Date: Wed, 5 Sep 2018 13:18:16 +0000 (+0100) Subject: python/samba/gp_parse: Use csv.reader for parsing cvs files X-Git-Tag: tdb-1.3.17~926 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df578e1554630f6781d40d4820c9026bb7b01d2d;p=thirdparty%2Fsamba.git 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 --- 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):