'Initialzer.
Args:
stream: Stream to write to.
fieldnames: Fieldnames to pass to the DictWriter.
encoding: Desired encoding.
kwds: Additional arguments to pass to the DictWriter.'

def __init__(self, stream, fieldnames, encoding='utf-8', **kwds):

    writer = codecs.getwriter(encoding)
    if ((writer is encodings.utf_8.StreamWriter) or (writer is encodings.ascii.StreamWriter) or (writer is encodings.latin_1.StreamWriter) or (writer is encodings.cp1252.StreamWriter)):
        self.no_recoding = True
        self.encoder = codecs.getencoder(encoding)
        self.writer = csv.DictWriter(stream, fieldnames, **kwds)
    else:
        self.no_recoding = False
        self.encoder = codecs.getencoder('utf-8')
        self.queue = cStringIO.StringIO()
        self.writer = csv.DictWriter(self.queue, fieldnames, **kwds)
        self.stream = writer(stream)
