def draw_table(table, x, y, w, padding=<NUM_LIT:5>):
try: from web import _ctx<EOL>except: pass<EOL>f = _ctx.fill()<EOL>_ctx.stroke(f)<EOL>h = _ctx.textheight("<STR_LIT:U+0020>") + padding*<NUM_LIT:2><EOL>row_y = y<EOL>if table.title != "<STR_LIT>":<EOL><INDENT>_ctx.fill(f)<EOL>_ctx.rect(x, row_y, w, h)<EOL>_ctx.fill(<NUM_LIT:1>)<EOL>_ctx.text(table.title, x+padding, row_y+_ctx.fontsize()+ padding)<EOL>row_y += h<EOL><DEDENT>rowspans = [<NUM_LIT:1> for i in range(<NUM_LIT:10>)]<EOL>previous_cell_w = <NUM_LIT:0><EOL>for row in table:<EOL><INDENT>cell_x = x<EOL>cell_w  = <NUM_LIT:1.0> * w<EOL>cell_w -= previous_cell_w * len([n for n in rowspans if n > <NUM_LIT:1>])<EOL>cell_w /= len(row)<EOL>cell_h = <NUM_LIT:0><EOL>for cell in row:<EOL><INDENT>this_h = _ctx.textheight(cell, width=cell_w-padding*<NUM_LIT:2>) + padding*<NUM_LIT:2><EOL>cell_h = max(cell_h, this_h)<EOL><DEDENT>i = <NUM_LIT:0><EOL>for cell in row:<EOL><INDENT>if rowspans[i] > <NUM_LIT:1>:<EOL><INDENT>rowspans[i] -= <NUM_LIT:1><EOL>cell_x += previous_cell_w<EOL>i += <NUM_LIT:1><EOL><DEDENT>m = re.search("<STR_LIT>", cell.properties)<EOL>if m:<EOL><INDENT>rowspan = int(m.group(<NUM_LIT:1>))<EOL>rowspans[i] = rowspan<EOL><DEDENT>else:<EOL><INDENT>rowspan = <NUM_LIT:1><EOL><DEDENT>_ctx.fill(f)<EOL>_ctx.text(cell, cell_x+padding, row_y+_ctx.fontsize()+padding, cell_w-padding*<NUM_LIT:2>)<EOL>_ctx.line(cell_x, row_y, cell_x+cell_w, row_y)<EOL>if cell_x > x:<EOL><INDENT>_ctx.nofill()<EOL>_ctx.line(cell_x, row_y, cell_x, row_y+cell_h)<EOL><DEDENT>cell_x += cell_w<EOL>i += <NUM_LIT:1><EOL><DEDENT>row_y += cell_h<EOL>previous_cell_w = cell_w<EOL><DEDENT>_ctx.nofill()<EOL>_ctx.rect(x, y, w, row_y-y)<EOL>
This is a very poor algorithm to draw Wikipedia tables in NodeBox.