当前位置: 首页>>代码示例>>Python>>正文


Python mako.template方法代码示例

本文整理汇总了Python中mako.template方法的典型用法代码示例。如果您正苦于以下问题:Python mako.template方法的具体用法?Python mako.template怎么用?Python mako.template使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mako的用法示例。


在下文中一共展示了mako.template方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: text_error_template

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def text_error_template(lookup=None):
    """Provides a template that renders a stack trace in a similar format to
    the Python interpreter, substituting source template filenames, line
    numbers and code for that of the originating source template, as
    applicable.

    """
    import mako.template
    return mako.template.Template(r"""
<%page args="error=None, traceback=None"/>
<%!
    from mako.exceptions import RichTraceback
%>\
<%
    tback = RichTraceback(error=error, traceback=traceback)
%>\
Traceback (most recent call last):
% for (filename, lineno, function, line) in tback.traceback:
  File "${filename}", line ${lineno}, in ${function or '?'}
    ${line | trim}
% endfor
${tback.errorname}: ${tback.message}
""") 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:exceptions.py

示例2: traceback

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def traceback(self):
        """Return a list of 4-tuple traceback records (i.e. normal python
        format) with template-corresponding lines remapped to the originating
        template.

        """
        return list(self._get_reformatted_records(self.records)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:exceptions.py

示例3: text_error_template

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def text_error_template(lookup=None):
    """Provides a template that renders a stack trace in a similar format to
    the Python interpreter, substituting source template filenames, line
    numbers and code for that of the originating source template, as
    applicable.

    """
    import mako.template

    return mako.template.Template(
        r"""
<%page args="error=None, traceback=None"/>
<%!
    from mako.exceptions import RichTraceback
%>\
<%
    tback = RichTraceback(error=error, traceback=traceback)
%>\
Traceback (most recent call last):
% for (filename, lineno, function, line) in tback.traceback:
  File "${filename}", line ${lineno}, in ${function or '?'}
    ${line | trim}
% endfor
${tback.errorname}: ${tback.message}
"""
    ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:28,代码来源:exceptions.py

示例4: get_cheetah_tests

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def get_cheetah_tests():
    if not Cheetah:
        return []

    tmpl_src = """
        <table>
            #for $row in $table
                <tr>
                    #for $column in $row.values()
                        <td>$column</td>
                    #end for
                </tr>
            #end for
        </table>
    """

    tmpl_search_list = [{'table': TABLE_DATA}]

    tmpl = Cheetah.Template.Template(tmpl_src, searchList=tmpl_search_list)

    def test_cheetah():
        """Cheetah template"""
        tmpl.respond()

    return [
        test_cheetah,
    ] 
开发者ID:youtube,项目名称:spitfire,代码行数:29,代码来源:render_benchmark.py

示例5: get_django_tests

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def get_django_tests():
    if not django:
        return []

    django.conf.settings.configure()
    django.setup()

    tmpl_src = """
        <table>
            {% for row in table %}
                <tr>
                    {% for column in row.values %}
                        <td>{{ column }}</td>
                    {% endfor %}
                </tr>
            {% endfor %}
        </table>
    """
    tmpl_autoescaped_src = ('{% autoescape on %}' +
                            tmpl_src +
                            '{% endautoescape %}')

    tmpl = django.template.Template(tmpl_src)
    tmpl_autoescaped = django.template.Template(tmpl_autoescaped_src)

    tmpl_context = django.template.Context({'table': TABLE_DATA})

    def test_django():
        """Django template"""
        tmpl.render(tmpl_context)

    def test_django_autoescaped():
        """Django template autoescaped"""
        tmpl_autoescaped.render(tmpl_context)

    return [
        test_django,
        test_django_autoescaped,
    ] 
开发者ID:youtube,项目名称:spitfire,代码行数:41,代码来源:render_benchmark.py

示例6: get_jinja2_tests

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def get_jinja2_tests():
    if not jinja2:
        return []

    tmpl_src = """
        <table>
            {% for row in table %}
                <tr>
                    {% for column in row.values() %}
                        <td>{{ column }}</td>
                    {% endfor %}
                </tr>
            {% endfor %}
        </table>
    """

    tmpl = jinja2.Template(tmpl_src)
    tmpl_autoescaped = jinja2.Template(tmpl_src, autoescape=True)

    def test_jinja2():
        """Jinja2 template"""
        tmpl.render(table=TABLE_DATA)

    def test_jinja2_autoescaped():
        """Jinja2 template autoescaped"""
        tmpl_autoescaped.render(table=TABLE_DATA)

    return [
        test_jinja2,
        test_jinja2_autoescaped,
    ] 
开发者ID:youtube,项目名称:spitfire,代码行数:33,代码来源:render_benchmark.py

示例7: get_mako_tests

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def get_mako_tests():
    if not mako:
        return []

    tmpl_src = """
        <table>
            % for row in table:
                <tr>
                    % for column in row.values():
                        <td>${column}</td>
                    % endfor
                </tr>
            % endfor
        </table>
    """

    tmpl = mako.template.Template(tmpl_src)
    tmpl_autoescaped = mako.template.Template(tmpl_src, default_filters=['h'])

    def test_mako():
        """Mako template"""
        tmpl.render(table=TABLE_DATA)

    def test_mako_autoescaped():
        """Mako template autoescaped"""
        tmpl_autoescaped.render(table=TABLE_DATA)

    return [
        test_mako,
        test_mako_autoescaped,
    ] 
开发者ID:youtube,项目名称:spitfire,代码行数:33,代码来源:render_benchmark.py

示例8: profile_tests

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def profile_tests(which=None):
    print 'Profiling...'
    print
    import hotshot, hotshot.stats
    profile_data = 'template.prof'
    profile = hotshot.Profile(profile_data)
    profile.runcall(run_tests, which=which, number=1, compare=False)
    stats = hotshot.stats.load(profile_data)
    stats.strip_dirs()
    stats.sort_stats('time', 'calls')
    print
    stats.print_stats()
    print 'Profile data written to %s' % profile_data 
开发者ID:youtube,项目名称:spitfire,代码行数:15,代码来源:render_benchmark.py

示例9: get_python_tests

# 需要导入模块: import mako [as 别名]
# 或者: from mako import template [as 别名]
def get_python_tests():
    tmpl_table = string.Template('<table>\n$table\n</table>\n')
    tmpl_row = string.Template('<tr>\n$row\n</tr>\n')
    tmpl_column = string.Template('<td>$column</td>\n')

    def _buffer_fn(write, table):
        write('<table>\n')
        for row in table:
            write('<tr>\n')
            for column in row.itervalues():
                write('<td>')
                write('%s' % column)
                write('</td>\n')
            write('</tr>\n')
        write('</table>\n')

    def test_python_template():
        """Python string template"""
        rows = ''
        for row in TABLE_DATA:
            columns = ''
            for column in row.itervalues():
                columns = columns + tmpl_column.substitute(column=column)
            rows = rows + tmpl_row.substitute(row=columns)
        return tmpl_table.substitute(table=rows)

    def test_python_stringio():
        """Python StringIO buffer"""
        buffer = StringIO.StringIO()
        _buffer_fn(buffer.write, TABLE_DATA)
        return buffer.getvalue()

    def test_python_cstringio():
        """Python cStringIO buffer"""
        buffer = cStringIO.StringIO()
        _buffer_fn(buffer.write, TABLE_DATA)
        return buffer.getvalue()

    def test_python_list():
        """Python list concatenation"""
        buffer = []
        _buffer_fn(buffer.append, TABLE_DATA)
        return ''.join(buffer)

    return [
        test_python_template,
        test_python_stringio,
        test_python_cstringio,
        test_python_list,
    ] 
开发者ID:youtube,项目名称:spitfire,代码行数:52,代码来源:render_benchmark.py


注:本文中的mako.template方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。