diff options
| author | Xavier Morel <xmo@odoo.com> | 2017-10-11 11:07:15 +0200 |
|---|---|---|
| committer | Martin Trigaux <mat@odoo.com> | 2017-10-11 11:42:31 +0200 |
| commit | 4c3846e7e061ebe35b4e14fc4ae9a1d3b8c220b3 (patch) | |
| tree | ff05fe6e49240ae25716657e73e14acb3683ec10 | |
| parent | f5b2a4b0f294b509171f559ba6a4b548da8cb728 (diff) | |
[FIX] tools: use codecs for csv reader/writer
The class PoFile was already using it.
TextIOWrapper closes its underlying buffer causing the "Synchronize Terms" action
to fail (trying to read on a closed buffer).
Fixes #19911
| -rw-r--r-- | odoo/tools/pycompat.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/odoo/tools/pycompat.py b/odoo/tools/pycompat.py index feb65da7a67..14195c4fa79 100644 --- a/odoo/tools/pycompat.py +++ b/odoo/tools/pycompat.py @@ -3,6 +3,7 @@ # very strongly inspired by https://github.com/pallets/werkzeug/blob/master/werkzeug/_compat.py #pylint: disable=deprecated-module import csv +import codecs import collections import io import sys @@ -85,14 +86,16 @@ else: raise value.with_traceback(tb) raise value + _reader = codecs.getreader('utf-8') + _writer = codecs.getwriter('utf-8') def csv_reader(stream, **params): assert not isinstance(stream, io.TextIOBase),\ "For cross-compatibility purposes, csv_reader takes a bytes stream" - return csv.reader(io.TextIOWrapper(stream, encoding='utf-8'), **params) + return csv.reader(_reader(stream), **params) def csv_writer(stream, **params): assert not isinstance(stream, io.TextIOBase), \ "For cross-compatibility purposes, csv_writer takes a bytes stream" - return csv.writer(io.TextIOWrapper(stream, encoding='utf-8', line_buffering=True), **params) + return csv.writer(_writer(stream), **params) def to_text(source): """ Generates a text value (an instance of text_type) from an arbitrary |
