1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
import csv
import io
import sys
__all__ = (
'csv_to_list',
'UnicodeMixin',
)
def csv_to_list(value):
if isinstance(value, str) and value:
reader = csv.reader(io.StringIO(value))
parsed = next(reader)
return parsed
return []
# Adapted from http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/
# pylint: disable=R0903
class UnicodeMixin(object):
if sys.version_info >= (3, 0):
__str__ = lambda x: x.__unicode__()
else:
__str__ = lambda x: str(x).encode('utf-8')
|