File: util.py

package info (click to toggle)
python-setoptconf 0.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: python: 1,427; sh: 7; makefile: 5
file content (26 lines) | stat: -rw-r--r-- 539 bytes parent folder | download | duplicates (2)
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')