[docs]classDictWriter(csv.DictWriter):""" Convenience implementation of ``csv.DictWriter``. This exists only to provide the :meth:`writeheader()` method on Python 2.6. """defwriteheader(self):ifhasattr(csv.DictWriter,'writeheader'):returncsv.DictWriter.writeheader(self)self.writer.writerow(self.fieldnames)
[docs]classUTF8Recoder(object):""" Iterator that reads an encoded stream and reencodes the input to UTF-8. .. note:: This class was stolen from the Python 2.7 documentation. """def__init__(self,fileobj,encoding,errors='strict'):self.errors=errorsself.reader=codecs.getreader(encoding)(fileobj,errors=self.errors)def__iter__(self):returnselfdefnext(self):returnself.reader.next().encode('utf_8')
# TODO: probably should deprecate / remove these for py3?UnicodeReader=csv.readerUnicodeDictReader=csv.DictReaderUnicodeWriter=csv.writerUnicodeDictWriter=csv.DictWriter