2

the purpose of safe_eval in Python odoo? and use of safe_eval. I have checked with few custom modules, they have safe eval function.

Annadurai
  • 31
  • 1
  • 7

1 Answers1

9

safe_eval:

  • Module which contains methods intended to provide more restricted alternatives to evaluate simple and/or untrusted code.

  • Methods in this module are typically used as alternatives to eval() to parse OpenERP domain strings, conditions and expressions, mostly based on locals condition/math builtins.

Usage:

safe_eval(expression[, globals[, locals[, mode[, nocopy]]]]) -> result

System-restricted Python expression evaluation

Evaluates a string that contains an expression that mostly uses Python constants, arithmetic expressions and the objects directly provided in context.

This can be used to e.g. evaluate an OpenERP domain expression from an untrusted source.

  • throws TypeError: If the expression provided is a code object
  • throws SyntaxError: If the expression provided is not valid Python
  • throws NameError: If the expression provided accesses forbidden names
  • throws ValueError: If the expression provided uses forbidden bytecode
Pravitha V
  • 3,308
  • 4
  • 33
  • 51