# HG changeset patch # User souliane # Date 1435077254 -7200 # Node ID c1b77f07f644b009165d7765cb8e98595fcc678d # Parent 9ae3d9c8b28ab70445fe5184cbf279e7efced84c replace shipped file unicodecsv.py with the module of the same name diff -r 9ae3d9c8b28a -r c1b77f07f644 README --- 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 ** diff -r 9ae3d9c8b28a -r c1b77f07f644 sat_website/forms.py --- 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): diff -r 9ae3d9c8b28a -r c1b77f07f644 sat_website/unicodecsv.py --- 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)