changeset dbb1d2a4b87b in modules/account_es:default
details: 
https://hg.tryton.org/modules/account_es?cmd=changeset&node=dbb1d2a4b87b
description:
        Use TextIOWrapper instead of encode/decode bytes with StringIO

        issue10554
        review344471003
diffstat:

 reporting_tax.py |  12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diffs (33 lines):

diff -r a7d98457f162 -r dbb1d2a4b87b reporting_tax.py
--- a/reporting_tax.py  Wed Jul 14 08:38:16 2021 +0200
+++ b/reporting_tax.py  Thu Jul 22 00:05:32 2021 +0200
@@ -2,7 +2,7 @@
 # this repository contains the full copyright notices and license terms.
 import csv
 import unicodedata
-from io import StringIO
+from io import BytesIO, TextIOWrapper
 
 from collections import defaultdict
 from dateutil.relativedelta import relativedelta
@@ -934,16 +934,14 @@
 
     @classmethod
     def render_csv(cls, report, report_context):
-        vat_book = StringIO()
+        vat_book = BytesIO()
         writer = csv.writer(
-            vat_book, delimiter=';', doublequote=False, escapechar='\\',
+            TextIOWrapper(vat_book, encoding='utf-8', write_through=True),
+            delimiter=';', doublequote=False, escapechar='\\',
             quoting=csv.QUOTE_NONE)
         for record in report_context['records']:
             writer.writerow(cls.get_row(record, report_context))
-        value = vat_book.getvalue()
-        if not isinstance(value, bytes):
-            value = value.encode('utf-8')
-        return value
+        return vat_book.getvalue()
 
     @classmethod
     def get_row(cls, record, report_context):

Reply via email to