prettytable
prettytable copied to clipboard
Prettytable 0.7.2 does not handle rowspan correctly
The following table which is valid HTML is not parsed correctly by prettytable:
<table border=1>
<tr>
<th rowspan="2"></th>
<th colspan="2">A</th>
<th>B</th>
</tr>
<tr>
<th>0</th>
<th>1</th>
<th>0</th>
</tr>
<tr>
<td>(0, 0)</td>
<td>1</td>
<td>2</td>
<td>20</td>
</tr>
<tr>
<td>(0, 1)</td>
<td>3</td>
<td>4</td>
<td>40</td>
</tr>
<tr>
<td>(1, 0)</td>
<td>10</td>
<td>20</td>
<td>100</td>
</tr>
</table>
The stack trace of from_html() is:
/usr/lib/python2.7/site-packages/prettytable.pyc in from_html(html_code,
**kwargs)
1435
1436 parser = TableHandler(**kwargs)
-> 1437 parser.feed(html_code)
1438 return parser.tables
1439
/usr/lib64/python2.7/HTMLParser.pyc in feed(self, data)
112 """
113 self.rawdata = self.rawdata + data
--> 114 self.goahead(0)
115
116 def close(self):
/usr/lib64/python2.7/HTMLParser.pyc in goahead(self, end)
158 k = self.parse_starttag(i)
159 elif startswith("</", i):
--> 160 k = self.parse_endtag(i)
161 elif startswith("<!--", i):
162 k = self.parse_comment(i)
/usr/lib64/python2.7/HTMLParser.pyc in parse_endtag(self, i)
396 return gtpos
397
--> 398 self.handle_endtag(elem)
399 self.clear_cdata_mode()
400 return gtpos
/usr/lib/python2.7/site-packages/prettytable.pyc in handle_endtag(self, tag)
1391 self.is_last_row_header = False
1392 if tag == "table":
-> 1393 table = self.generate_table(self.rows)
1394 self.tables.append(table)
1395 self.rows = []
/usr/lib/python2.7/site-packages/prettytable.pyc in generate_table(self, rows)
1416 table.field_names = row[0]
1417 else:
-> 1418 table.add_row(row[0])
1419 return table
1420
/usr/lib/python2.7/site-packages/prettytable.pyc in add_row(self, row)
816
817 if self._field_names and len(row) != len(self._field_names):
--> 818 raise Exception("Row has incorrect number of values,
(actual) %d!=%d (expected)" %(len(row),len(self._field_names)))
819 if not self._field_names:
820 self.field_names = [("Field %d" % (n+1)) for n in range(0,len(row))]
Exception: Row has incorrect number of values, (actual) 4!=3 (expected)
Original issue reported on code.google.com by [email protected]
on 29 Jan 2015 at 4:00