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


Python MarkupTemplateEnginePlugin.render方法代码示例

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


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

示例1: test_helper_functions

# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import render [as 别名]
    def test_helper_functions(self):
        plugin = MarkupTemplateEnginePlugin()
        tmpl = plugin.load_template(PACKAGE + '.templates.functions')
        output = plugin.render({'snippet': u'<b>Foo</b>'}, template=tmpl)
        self.assertEqual("""<div>
False
bar
<b>Foo</b>
<b>Foo</b>
</div>""", output)
开发者ID:nervatura,项目名称:nerva2py,代码行数:12,代码来源:plugin.py

示例2: __init__

# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import render [as 别名]
class WSGITrac:
    """Callable class. Initi with path=/path/to/trac/env"""
    def __init__(self, path, secure=False, parent=False):
      self.path = path
      self.secure = secure
      self.parent = parent
      self.template = MarkupTemplateEnginePlugin()

    def __call__(self, environ, start_response):

      https = environ.get("HTTPS", "off")
      if self.secure and https != 'on':
        return redirect_https(environ, start_response)

      if self.parent:
        project = path_info_pop(environ)
        if project:

            if not os.path.isdir('{0}/{1}'.format(self.path, project)):
                start_response("404 Not Found", [('content-type', 'text/html')])
                return self.template.render({'message': 'Trac name {0} does\'t exist.'.format(project)},
                        format='xhtml', template="wsgiplugin.notfound")

            environ['trac.env_path'] = os.path.join(self.path, project)
            try:
                return dispatch_request(environ, start_response)
            except HTTPForbidden:
                if environ.get('REMOTE_USER'): #We have SOMETHING set in REMOTE_USER - so Forbidden
                    start_response("200 OK", [('content-type', 'text/html')])
                    return self.template.render({}, format='xhtml', template="wsgiplugin.unauthorized")
                else:
                    url = '/login_form?came_from=%s' % construct_url(environ)
                    start_response("302 Temporary Redirect", [('Location', url)])
                    return []
            except HTTPNotFound, e:
                start_response("404 Not Found", [('content-type', 'text/html')])
                return self.template.render({'message': e}, format='xhtml', template="wsgiplugin.notfound")
        else:
            return self._send_index(environ, start_response)

      else:
开发者ID:getpenelope,项目名称:WSGITrac,代码行数:43,代码来源:wsgiplugin.py

示例3: test_render

# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import render [as 别名]
    def test_render(self):
        plugin = MarkupTemplateEnginePlugin()
        tmpl = plugin.load_template(PACKAGE + '.templates.test')
        output = plugin.render({'message': 'Hello'}, template=tmpl)
        self.assertEqual("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
  <head>
    <title>Test</title>
  </head>
  <body>
    <h1>Test</h1>
    <p>Hello</p>
  </body>
</html>""", output)
开发者ID:nervatura,项目名称:nerva2py,代码行数:16,代码来源:plugin.py

示例4: __init__

# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import render [as 别名]
class WSGITrac:
    """Callable class. Initi with path=/path/to/trac/env"""
    def __init__(self, path, secure=False, parent=False):
      self.path = path
      self.secure = secure
      self.parent = parent
      self.template = MarkupTemplateEnginePlugin()
    
    def __call__(self, environ, start_response):

      https = environ.get("HTTPS", "off")
      if self.secure and https != 'on':
        return redirect_https(environ, start_response)
    
      if self.parent:
        project = path_info_pop(environ)
        if project:
            environ['trac.env_path'] = os.path.join(self.path, project)
            return dispatch_request(environ, start_response)
        else:
            return self._send_index(environ, start_response)
          
      else:
        environ['trac.env_path'] = self.path
        return dispatch_request(environ, start_response)
            
        
    def _send_index(self, environ, start_response):
        projects = []
                          
        for env_name in os.listdir(self.path):
            env_path = os.path.join(self.path, env_name)
            try:
              env = open_environment(env_path)
              env_perm = PermissionCache(PermissionSystem(env).get_user_permissions(environ.get("REMOTE_USER", "anonymous")))
                      
              if env_perm.has_permission('WIKI_VIEW'):
                  projects.append({
                      'name': env.project_name,
                      'description': env.project_description,
                      # XXX: get rid of the double / in the beginning
                      'href': construct_url(environ, path_info="/"+env_name),
                  })
            except Exception:
              pass

        projects.sort(lambda x, y: cmp(x['name'].lower(), y['name'].lower()))
        start_response("200 OK", [('content-type', 'text/html')])
        return self.template.render({"projects":projects}, format='xhtml', template = "wsgiplugin.index")
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:51,代码来源:wsgiplugin.py

示例5: test_render_fragment_with_doctype

# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import render [as 别名]
    def test_render_fragment_with_doctype(self):
        plugin = MarkupTemplateEnginePlugin(options={
            'genshi.default_doctype': 'html-strict',
        })
        tmpl = plugin.load_template(PACKAGE + '.templates.test_no_doctype')
        output = plugin.render({'message': 'Hello'}, template=tmpl,
                               fragment=True)
        self.assertEqual("""<html lang="en">
  <head>
    <title>Test</title>
  </head>
  <body>
    <h1>Test</h1>
    <p>Hello</p>
  </body>
</html>""", output)
开发者ID:nervatura,项目名称:nerva2py,代码行数:18,代码来源:plugin.py

示例6: test_render_with_doctype

# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import render [as 别名]
    def test_render_with_doctype(self):
        plugin = MarkupTemplateEnginePlugin(options={
            'genshi.default_doctype': 'html-strict',
        })
        tmpl = plugin.load_template(PACKAGE + '.templates.test')
        output = plugin.render({'message': 'Hello'}, template=tmpl)
        self.assertEqual("""<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
  <head>
    <title>Test</title>
  </head>
  <body>
    <h1>Test</h1>
    <p>Hello</p>
  </body>
</html>""", output)
开发者ID:nervatura,项目名称:nerva2py,代码行数:18,代码来源:plugin.py


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