cleaner way to get rid of BOM for CsvPage

This commit is contained in:
smurail 2014-10-20 17:08:18 +02:00
commit 977f5a9f02

View file

@ -345,9 +345,12 @@ class CsvPage(Page):
"""
def build_doc(self, content):
# We may need to temporarily convert content to utf-8 because csv
# does not support Unicode.
encoding = self.encoding
if encoding == 'utf-16le':
content = content.decode('utf-16le')[1:].encode('utf-8')
# If there is a BOM, decode('utf-16') will get rid of it
content = content.decode('utf-16').encode('utf-8')
encoding = 'utf-8'
if self.NEWLINES_HACK:
content = content.replace('\r\n', '\n').replace('\r', '\n')