gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 line
1.5KB

  1. # -*- coding: utf-8 -*-
  2. #pylint: disable=deprecated-module
  3. import csv
  4. import codecs
  5. import io
  6. import typing
  7. import warnings
  8. _reader = codecs.getreader('utf-8')
  9. _writer = codecs.getwriter('utf-8')
  10. def csv_reader(stream, **params):
  11. 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)
  12. assert not isinstance(stream, io.TextIOBase),\
  13. "For cross-compatibility purposes, csv_reader takes a bytes stream"
  14. return csv.reader(_reader(stream), **params)
  15. def csv_writer(stream, **params):
  16. 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)
  17. assert not isinstance(stream, io.TextIOBase), \
  18. "For cross-compatibility purposes, csv_writer takes a bytes stream"
  19. return csv.writer(_writer(stream), **params)
  20. def to_text(source: typing.Any) -> str:
  21. """ Generates a text value from an arbitrary source.
  22. * False and None are converted to empty strings
  23. * text is passed through
  24. * bytes are decoded as UTF-8
  25. * rest is textified
  26. """
  27. warnings.warn("Deprecated since Odoo 18.0.", DeprecationWarning, 2)
  28. if source is None or source is False:
  29. return ''
  30. if isinstance(source, bytes):
  31. return source.decode()
  32. if isinstance(source, str):
  33. return source
  34. return str(source)
上海开阖软件有限公司 沪ICP备12045867号-1