annotate roundup/cgi/engine_chameleon.py @ 7037:22183e7d1443

flake8 whitepace, indents, var names address: B007 Loop control variable 'id' not used within the loop body. If this is intended, start the name with an underscore. E122 continuation line missing indentation or outdented E127 continuation line over-indented for visual indent E128 continuation line under-indented for visual indent E129 visually indented line with same indent as next logical line E701 multiple statements on one line (colon) E703 statement ends with a semicolon E741 ambiguous variable name 'l'
author John Rouillard <rouilj@ieee.org>
date Mon, 10 Oct 2022 15:43:13 -0400
parents 4d20d8251bf2
children b8e63e65d9a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
1 """Templating engine adapter for the Chameleon."""
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
2
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
3 __docformat__ = 'restructuredtext'
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
4
4720
fd72576e07ed API break: rename Templates to Loader for zopetal and chameleon
anatoly techtonik <techtonik@gmail.com>
parents: 4719
diff changeset
5 import chameleon
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
6
5418
55f09ca366c4 Python 3 preparation: StringIO.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5416
diff changeset
7 from roundup.cgi.templating import context, TALLoaderBase
5416
56c9bcdea47f Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4749
diff changeset
8 from roundup.anypy.strings import s2u
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
9
6063
4d20d8251bf2 flake8 whitespace; removed unused import os.path.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
10
4749
0421390b3094 templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents: 4740
diff changeset
11 class Loader(TALLoaderBase):
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
12 def __init__(self, dir):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
13 self.dir = dir
4720
fd72576e07ed API break: rename Templates to Loader for zopetal and chameleon
anatoly techtonik <techtonik@gmail.com>
parents: 4719
diff changeset
14 self.loader = chameleon.PageTemplateLoader(dir)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
15
4740
fe9568a6cbd6 Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents: 4739
diff changeset
16 def load(self, tplname):
4749
0421390b3094 templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents: 4740
diff changeset
17 src, filename = self._find(tplname)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
18 return RoundupPageTemplate(self.loader.load(src))
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
19
6063
4d20d8251bf2 flake8 whitespace; removed unused import os.path.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
20
4635
45ac4cd1a381 Fixes for RoundupPageTemplate in engine_chameleon.py.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 4587
diff changeset
21 class RoundupPageTemplate(object):
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
22 def __init__(self, pt):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
23 self._pt = pt
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
24
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
25 def render(self, client, classname, request, **options):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
26 c = context(client, self, classname, request)
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
27 c.update({'options': options})
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
28
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
29 def translate(msgid, domain=None, mapping=None, default=None):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
30 result = client.translator.translate(domain, msgid,
6063
4d20d8251bf2 flake8 whitespace; removed unused import os.path.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
31 mapping=mapping,
4d20d8251bf2 flake8 whitespace; removed unused import os.path.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
32 default=default)
5416
56c9bcdea47f Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4749
diff changeset
33 return s2u(result)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
34
4635
45ac4cd1a381 Fixes for RoundupPageTemplate in engine_chameleon.py.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 4587
diff changeset
35 output = self._pt.render(None, translate, **c)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
36 return output.encode(client.charset)
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
37
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
38 def __getitem__(self, name):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
39 return self._pt[name]
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
40
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
41 def __getattr__(self, name):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
42 return getattr(self._pt, name)

Roundup Issue Tracker: http://roundup-tracker.org/