Mercurial > genshi > genshi-test
view examples/transform/run.py @ 286:df4e03ef300f stable-0.3.x 0.3.2
Updated change log on 0.3.x branch.
author | cmlenz |
---|---|
date | Thu, 12 Oct 2006 12:45:20 +0000 |
parents | 7a426ab6407a |
children |
line wrap: on
line source
#!/usr/bin/python # -*- coding: utf-8 -*- import os import sys from genshi.input import HTMLParser from genshi.template import Context, MarkupTemplate def transform(html_filename, tmpl_filename): tmpl_fileobj = open(tmpl_filename) tmpl = MarkupTemplate(tmpl_fileobj, tmpl_filename) tmpl_fileobj.close() html_fileobj = open(html_filename) html = HTMLParser(html_fileobj, html_filename) print tmpl.generate(Context(input=html)).render('xhtml') html_fileobj.close() if __name__ == '__main__': basepath = os.path.dirname(os.path.abspath(__file__)) tmpl_filename = os.path.join(basepath, 'template.xml') html_filename = os.path.join(basepath, 'index.html') transform(html_filename, tmpl_filename)