[FIX] qweb: use python builtins for safe_eval._BUILTINS key instead of value.get('key')

This commit is contained in:
Christophe Matthieu
2016-06-23 12:03:03 +02:00
parent 566cfd494b
commit 2dc19eb6f0
2 changed files with 8 additions and 42 deletions
+1 -1
View File
@@ -271,7 +271,7 @@ class IrQWeb(models.AbstractModel, QWeb):
)
# ast.Expression().body -> expr
return Contextifier().visit(st).body
return Contextifier(safe_eval._BUILTINS).visit(st).body
def _get_attr_bool(self, attr, default=False):
if attr:
+7 -41
View File
@@ -312,7 +312,7 @@ class QWeb(object):
def _compiled_fn(self, append, values):
log = {'last_path_node': None}
values.update(self.default_values())
values = dict(self.default_values(), **values)
try:
return compiled(self, append, values, options, log)
except QWebException, e:
@@ -327,43 +327,7 @@ class QWeb(object):
def default_values(self):
""" Return attributes added to the values for each computed template. """
return {
'True': True,
'False': False,
'None': None,
'str': str,
'unicode': unicode,
'bool': bool,
'int': int,
'float': float,
'long': long,
'enumerate': enumerate,
'dict': dict,
'list': list,
'tuple': tuple,
'map': map,
'abs': abs,
'min': min,
'max': max,
'sum': sum,
'reduce': reduce,
'filter': filter,
'round': round,
'len': len,
'repr': repr,
'set': set,
'all': all,
'any': any,
'ord': ord,
'chr': chr,
'cmp': cmp,
'divmod': divmod,
'isinstance': isinstance,
'range': range,
'xrange': xrange,
'zip': zip,
'format': self.format,
}
return dict(format=self.format)
def get_template(self, template, options):
""" Retrieve the given template, and return it as a pair ``(element,
@@ -1402,11 +1366,13 @@ class QWeb(object):
def _compile_expr(self, expr):
""" Compiles a purported Python expression to ast, and alter its
variable references to access values data instead. Can be overridden to
use a safe eval method.
variable references to access values data instead exept for
python buildins.
This compile method is unsafe!
Can be overridden to use a safe eval method.
"""
# string must be stripped otherwise whitespace before the start for
# formatting purpose are going to break parse/compile
st = ast.parse(expr.strip(), mode='eval')
# ast.Expression().body -> expr
return Contextifier().visit(st).body
return Contextifier(builtin_defaults).visit(st).body