Skip to content
Snippets Groups Projects
Unverified Commit 4c3846e7 authored by Xavier Morel's avatar Xavier Morel Committed by Martin Trigaux
Browse files

[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
parent f5b2a4b0
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment