mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 03:52:01 +02:00
18.0 vanilla
This commit is contained in:
parent
d72e748793
commit
0a7ae8db93
337 changed files with 399651 additions and 232598 deletions
|
|
@ -3,37 +3,41 @@
|
|||
import csv
|
||||
import codecs
|
||||
import io
|
||||
import typing
|
||||
import warnings
|
||||
|
||||
_reader = codecs.getreader('utf-8')
|
||||
_writer = codecs.getwriter('utf-8')
|
||||
|
||||
|
||||
def csv_reader(stream, **params):
|
||||
warnings.warn("Deprecated since Odoo 18.0: can just use `csv.reader` with a text stream or use `TextIOWriter` or `codec.getreader` to transcode.", DeprecationWarning, 2)
|
||||
assert not isinstance(stream, io.TextIOBase),\
|
||||
"For cross-compatibility purposes, csv_reader takes a bytes stream"
|
||||
return csv.reader(_reader(stream), **params)
|
||||
|
||||
|
||||
def csv_writer(stream, **params):
|
||||
warnings.warn("Deprecated since Odoo 18.0: can just use `csv.writer` with a text stream or use `TextIOWriter` or `codec.getwriter` to transcode.", DeprecationWarning, 2)
|
||||
assert not isinstance(stream, io.TextIOBase), \
|
||||
"For cross-compatibility purposes, csv_writer takes a bytes stream"
|
||||
return csv.writer(_writer(stream), **params)
|
||||
|
||||
|
||||
def to_text(source):
|
||||
""" Generates a text value (an instance of text_type) from an arbitrary
|
||||
source.
|
||||
def to_text(source: typing.Any) -> str:
|
||||
""" Generates a text value from an arbitrary source.
|
||||
|
||||
* False and None are converted to empty strings
|
||||
* text is passed through
|
||||
* bytes are decoded as UTF-8
|
||||
* rest is textified via the current version's relevant data model method
|
||||
* rest is textified
|
||||
"""
|
||||
warnings.warn("Deprecated since Odoo 18.0.", DeprecationWarning, 2)
|
||||
if source is None or source is False:
|
||||
return u''
|
||||
return ''
|
||||
|
||||
if isinstance(source, bytes):
|
||||
return source.decode('utf-8')
|
||||
return source.decode()
|
||||
|
||||
if isinstance(source, str):
|
||||
return source
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue