/usr/lib/python3/dist-packages/unicodecsv/py3.py is in python3-unicodecsv 0.14.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 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)
|