comparison MoinMoin/parser/text_csv.py @ 3641:00af8e564f96 SOC2008-START

parser.text_csv: removes empty lines in front of the csv table
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 25 May 2008 00:43:25 +0200
parents 75db5e7c09e2
children 8fbdd3667488
comparison
equal deleted inserted replaced
3640:e54b2e843990 3641:00af8e564f96
53 self._first_row = None 53 self._first_row = None
54 formatter = request.formatter 54 formatter = request.formatter
55 55
56 # workaround csv.reader deficiency by encoding to utf-8 56 # workaround csv.reader deficiency by encoding to utf-8
57 data = raw.encode('utf-8').split('\n') 57 data = raw.encode('utf-8').split('\n')
58
59 # workaraound to remove empty lines in front of the csv table
60 # if this is not done this parser shows only an empty line
61 count = 0
62 for txt in data:
63 if not txt:
64 count += 1
65 else:
66 data = data[count:]
67 break
68
58 delimiter = ';' 69 delimiter = ';'
59 # Previous versions of this parser have used only the delimiter ";" (by default). 70 # Previous versions of this parser have used only the delimiter ";" (by default).
60 # This version now tries to sniff the delimiter from the list preferred_delimiters 71 # This version now tries to sniff the delimiter from the list preferred_delimiters
61 # Although the Python csv sniffer had quite some changes from py 2.3 to 2.5.1, we try 72 # Although the Python csv sniffer had quite some changes from py 2.3 to 2.5.1, we try
62 # to avoid problems for the case it does not find a delimiter in some given data. 73 # to avoid problems for the case it does not find a delimiter in some given data.
63 # Newer versions of the sniffer do raise an _csv.Error while older versions do 74 # Newer versions of the sniffer do raise an _csv.Error while older versions do
64 # return a whitespace as delimiter. 75 # return a whitespace as delimiter.
65 if data[0]: 76 if data[0]:
66 try: 77 try:
67 preferred_delimiters = [',', '\t', ';', ' ', ':'] 78 preferred_delimiters = [',', '\t', ';', ' ', ':']
68 delimiter = Sniffer().sniff(data[0], preferred_delimiters).delimiter or ';' 79 delimiter = Sniffer().sniff(data[0], preferred_delimiters).delimiter or ';'
69 except Error: 80 except Error:
70 pass 81 pass
71 82
72 visible = None 83 visible = None