Esempio n. 1
0
    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)
Esempio n. 2
0
    def test_helper_functions(self):
        plugin = MarkupTemplateEnginePlugin()
        tmpl = plugin.load_template(PACKAGE + '.templates.functions')
        output = plugin.render({'snippet': '<b>Foo</b>'}, template=tmpl)
        self.assertEqual("""<div>
False
bar
<b>Foo</b>
<b>Foo</b>
</div>""", output)
Esempio n. 3
0
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")
Esempio n. 4
0
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:
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
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")
Esempio n. 8
0
    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)
Esempio n. 9
0
    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)
Esempio n. 10
0
    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)
Esempio n. 11
0
    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)