def compile_webpy_template(source, filename): """Compiles a web.py template. """ from web.template import Template text = Template.normalize_text(source) python_source = Template.generate_code(source, filename) python_source = "from webpy_ext import escape_, TemplateResult, ForLoop\n" + python_source return pyjs_translate(python_source, filename)
def extract_webpy(fileobj, keywords, comment_tags, options): """Extract messages from webpy templates files. :param fileobj: the file-like object the messages should be extracted from :param keywords: a list of keywords (i.e. function names) that should be recognized as translation functions :param comment_tags: a list of translator tags to search for and include in the results :param options: a dictionary of additional options (optional) :return: an iterator over ``(lineno, funcname, message, comments)`` tuples :rtype: ``iterator`` """ code = Template.generate_code(fileobj.read().decode("utf-8"), fileobj.name) return extract_python(StringIO.StringIO(code), keywords, comment_tags, options)