blob: 6e27ccffd73228c037b20b510416c70a4a64901c (
plain)
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
|
QUOTE_MINIMAL = None
class Dialect(object):
pass
def register_dialect(name, d):
pass
class reader(object):
def __init__(self, csvfile, dialect="excel", **fmtparams):
self.i = 0
self.lines = []
for line in csvfile:
elems = []
elem = []
inQuote = False
skip = 0
for i, c in enumerate(line):
if skip > 0:
skip -= 1
continue
if inQuote:
if c == '"' and not line.startswith('""', i):
inQuote = False
elif c == '"' and line.startswith('""', i):
elem.append(c)
skip = 1
else:
elem.append(c)
else:
if c == '"':
inQuote = True
elif c == ';':
elems.append("".join(elem))
elem = []
else:
elem.append(c)
if line:
elems.append("".join(elem))
self.lines.append(elems)
def __iter__(self):
self.i = 0
return self
def __next__(self):
try:
line = self.lines[self.i]
self.i += 1
return line
except IndexError:
raise StopIteration
|