當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。