changeset 5fddafe3348a in modules/account_fr:default
details:
https://hg.tryton.org/modules/account_fr?cmd=changeset&node=5fddafe3348a
description:
Use TextIOWrapper instead of encode/decode bytes with StringIO
issue10554
review344471003
diffstat:
account.py | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)
diffs (36 lines):
diff -r 6439a5d7da78 -r 5fddafe3348a account.py
--- a/account.py Mon Jul 12 23:33:30 2021 +0200
+++ b/account.py Thu Jul 22 00:05:32 2021 +0200
@@ -1,7 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import csv
-from io import StringIO
+from io import BytesIO, TextIOWrapper
from sql import Table
from sql.aggregate import Sum
@@ -97,8 +97,9 @@
])
def transition_generate(self):
- fec = StringIO()
- writer = self.get_writer(fec)
+ fec = BytesIO()
+ writer = self.get_writer(
+ TextIOWrapper(fec, encoding='utf-8', write_through=True))
writer.writerow(self.get_header())
format_date = self.get_format_date()
format_number = self.get_format_number()
@@ -112,10 +113,7 @@
for line in self.get_lines():
row = self.get_row(line, format_date, format_number)
writer.writerow(map(convert, row))
- value = fec.getvalue()
- if not isinstance(value, bytes):
- value = value.encode('utf-8')
- self.result.file = self.result.__class__.file.cast(value)
+ self.result.file = self.result.__class__.file.cast(fec.getvalue())
return 'result'
def default_result(self, fields):