changeset 94:c1b77f07f644

replace shipped file unicodecsv.py with the module of the same name
author souliane <souliane@mailoo.org>
date Tue, 23 Jun 2015 18:34:14 +0200
parents 9ae3d9c8b28a
children dc8a30f6c369
files README sat_website/forms.py sat_website/unicodecsv.py
diffstat 3 files changed, 2 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/README	Tue Jun 16 21:26:58 2015 +0200
+++ b/README	Tue Jun 23 18:34:14 2015 +0200
@@ -40,6 +40,7 @@
 
     - Django 1.7.3 or superior ( https://www.djangoproject.com )
     - Django application "markdown_deux" ( https://github.com/trentm/django-markdown-deux )
+    - Python module unicodecsv ( https://github.com/jdunck/python-unicodecsv )
 
 ** SETTINGS **
 
--- a/sat_website/forms.py	Tue Jun 16 21:26:58 2015 +0200
+++ b/sat_website/forms.py	Tue Jun 23 18:34:14 2015 +0200
@@ -259,7 +259,7 @@
     def writeResultToCSV(self):
         result = [unicode(value) for key, value in self.results(False)]
         with open(settings.ASSO_SUBSCR_CSV, 'a+') as csvfile:
-            writer = unicodecsv.UnicodeWriter(csvfile, delimiter=';')
+            writer = unicodecsv.writer(csvfile, delimiter=';')
             writer.writerow(result)
 
     def process_submitted_data(self):
--- a/sat_website/unicodecsv.py	Tue Jun 16 21:26:58 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-#
-# CSV Reader and Writer
-#
-# This is a copy paste of the examples given in Python docs:
-# https://docs.python.org/2/library/csv.html
-
-import csv, codecs, cStringIO
-
-class UTF8Recoder:
-    """
-    Iterator that reads an encoded stream and reencodes the input to UTF-8
-    """
-    def __init__(self, f, encoding):
-        self.reader = codecs.getreader(encoding)(f)
-
-    def __iter__(self):
-        return self
-
-    def next(self):
-        return self.reader.next().encode("utf-8")
-
-class UnicodeReader:
-    """
-    A CSV reader which will iterate over lines in the CSV file "f",
-    which is encoded in the given encoding.
-    """
-
-    def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
-        f = UTF8Recoder(f, encoding)
-        self.reader = csv.reader(f, dialect=dialect, **kwds)
-
-    def next(self):
-        row = self.reader.next()
-        return [unicode(s, "utf-8") for s in row]
-
-    def __iter__(self):
-        return self
-
-class UnicodeWriter:
-    """
-    A CSV writer which will write rows to CSV file "f",
-    which is encoded in the given encoding.
-    """
-
-    def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
-        # Redirect output to a queue
-        self.queue = cStringIO.StringIO()
-        self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
-        self.stream = f
-        self.encoder = codecs.getincrementalencoder(encoding)()
-
-    def writerow(self, row):
-        self.writer.writerow([s.encode("utf-8") for s in row])
-        # Fetch UTF-8 output from the queue ...
-        data = self.queue.getvalue()
-        data = data.decode("utf-8")
-        # ... and reencode it into the target encoding
-        data = self.encoder.encode(data)
-        # write to the target stream
-        self.stream.write(data)
-        # empty queue
-        self.queue.truncate(0)
-
-    def writerows(self, rows):
-        for row in rows:
-            self.writerow(row)