diff options
author | 2017-03-29 13:35:45 +0300 | |
---|---|---|
committer | 2017-03-29 13:35:45 +0300 | |
commit | e2cc2530fc6d54ebc975c01a4ff887ce12f0a736 (patch) | |
tree | 38385867295c8a09fb0d7f8eaf5fa78179e5b13a /jython-tosca-parser/src/main/resources/Lib/site-packages/unicodecsv-0.14.1-py2.7.egg/unicodecsv/py3.py | |
parent | bccebaa9888906f8ff78172f62ec592956066d82 (diff) |
[SDC-6] sdc-distribution-client 1707 rebasing
Change-Id: I322a05fd79beb6ba4fee4d32afffecf531b86e98
Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'jython-tosca-parser/src/main/resources/Lib/site-packages/unicodecsv-0.14.1-py2.7.egg/unicodecsv/py3.py')
-rw-r--r-- | jython-tosca-parser/src/main/resources/Lib/site-packages/unicodecsv-0.14.1-py2.7.egg/unicodecsv/py3.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/unicodecsv-0.14.1-py2.7.egg/unicodecsv/py3.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/unicodecsv-0.14.1-py2.7.egg/unicodecsv/py3.py new file mode 100644 index 0000000..13a8bf7 --- /dev/null +++ b/jython-tosca-parser/src/main/resources/Lib/site-packages/unicodecsv-0.14.1-py2.7.egg/unicodecsv/py3.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +import csv +from csv import * + + +class _UnicodeWriteWrapper(object): + """Simple write() wrapper that converts unicode to bytes.""" + + def __init__(self, binary, encoding, errors): + self.binary = binary + self.encoding = encoding + self.errors = errors + + def write(self, string): + return self.binary.write(string.encode(self.encoding, self.errors)) + + +class UnicodeWriter(object): + def __init__(self, f, dialect=csv.excel, encoding='utf-8', errors='strict', + *args, **kwds): + if f is None: + raise TypeError + + f = _UnicodeWriteWrapper(f, encoding=encoding, errors=errors) + self.writer = csv.writer(f, dialect, *args, **kwds) + + def writerow(self, row): + return self.writer.writerow(row) + + def writerows(self, rows): + return self.writer.writerows(rows) + + @property + def dialect(self): + return self.writer.dialect + + +class UnicodeReader(object): + def __init__(self, f, dialect=None, encoding='utf-8', errors='strict', + **kwds): + + format_params = ['delimiter', 'doublequote', 'escapechar', + 'lineterminator', 'quotechar', 'quoting', + 'skipinitialspace'] + + if dialect is None: + if not any([kwd_name in format_params + for kwd_name in kwds.keys()]): + dialect = csv.excel + + f = (bs.decode(encoding, errors=errors) for bs in f) + self.reader = csv.reader(f, dialect, **kwds) + + def __next__(self): + return self.reader.__next__() + + def __iter__(self): + return self + + @property + def dialect(self): + return self.reader.dialect + + @property + def line_num(self): + return self.reader.line_num + + +writer = UnicodeWriter +reader = UnicodeReader + + +class DictWriter(csv.DictWriter): + def __init__(self, csvfile, fieldnames, restval='', + extrasaction='raise', dialect='excel', encoding='utf-8', + errors='strict', *args, **kwds): + super().__init__(csvfile, fieldnames, restval, + extrasaction, dialect, *args, **kwds) + self.writer = UnicodeWriter(csvfile, dialect, encoding=encoding, + errors=errors, *args, **kwds) + self.encoding_errors = errors + + def writeheader(self): + header = dict(zip(self.fieldnames, self.fieldnames)) + self.writerow(header) + + +class DictReader(csv.DictReader): + def __init__(self, csvfile, fieldnames=None, restkey=None, restval=None, + dialect='excel', encoding='utf-8', errors='strict', *args, + **kwds): + csv.DictReader.__init__(self, csvfile, fieldnames, restkey, restval, + dialect, *args, **kwds) + self.reader = UnicodeReader(csvfile, dialect, encoding=encoding, + errors=errors, *args, **kwds) |