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