buffer = cStringIO.StringIO()
codecinfo = codecs.lookup('utf8')
wrapper = codecs.StreamReaderWriter(buffer, codecinfo.streamreader,
    codecinfo.streamwriter)
Python: How to get StringIO.writelines to accept unicode string?