python/samba/gp_parse: Use csv.reader for parsing cvs files
authorNoel Power <noel.power@suse.com>
Wed, 5 Sep 2018 13:18:16 +0000 (14:18 +0100)
committerNoel Power <npower@samba.org>
Mon, 5 Nov 2018 19:05:23 +0000 (20:05 +0100)
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 <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/gp_parse/gp_csv.py

index 280e83175dcb0824778a29f1718ceee7e457c8f7..f1be04c43d366699f51ee766cee62cdd665688c4 100644 (file)
@@ -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):