2 # -*- coding: utf-8 -*-
7 from urlparse import urlparse
9 from lxml.builder import ElementMaker
10 from treecutter import constants as const
13 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
14 r = re.search(r"(?P<url>https?://[^ ]+)\|(?P<title>[\w\-\.]+)", text)
16 rep = r.groups(r.group(1))
17 text = db.link(rep[1],**{const.XLINK+"href": rep[0]})
21 def __init__(self, tablefile, title):
22 self.tablefile = tablefile
27 f = file(self.tablefile, 'r')
33 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
35 nrcol = str(len(cols[0]))
36 if cols[0][0][0] == '*':
37 cols[0][0] = cols[0][0][1:]
41 row.append(db.entry(linkify(e), align="center"))
48 row.append(db.entry(linkify(e)))
49 tab = db.table(db.title(self.title),
50 db.tgroup(head,body,cols=nrcol,
51 colsep='1',rowsep='1',align='left'),
55 if __name__ == "__main__":
56 for arg in sys.argv[1:]:
61 argument = al[1].decode('utf-8')
63 (tablefile, title) = argument.split('|')
64 tab = Table(tablefile,title)
68 sys.stdout.write(etree.tostring(txml,encoding='UTF-8',pretty_print=False))