diff options
| author | Xavier Morel <xmo@odoo.com> | 2017-05-08 16:15:02 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2017-05-12 16:15:39 +0200 |
| commit | 3dd3790597e84186d922b798aa8bb4650513ce4b (patch) | |
| tree | 0a5fe19bf449ed157386d613489975f9a48dd98c /odoo/tools/safe_eval.py | |
| parent | 021de21e8cdcf35276c945d8070d04435fa1a19c (diff) | |
[FIX] P3: raise exception with existing traceback
In Python 2, to raise a new exception but reuse a traceback requires a
special form of ``raise`` (``raise etype, evalue, tb``).
In Python 3, this is now done via a ``with_traceback`` method on
exception objects.
However this requires a bit of trickery as the former is invalid
syntax in Python 3, hence pycompat bridge created via an exec for
Python 2.
Diffstat (limited to 'odoo/tools/safe_eval.py')
| -rw-r--r-- | odoo/tools/safe_eval.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/odoo/tools/safe_eval.py b/odoo/tools/safe_eval.py index 1897486eb82..569df6455e2 100644 --- a/odoo/tools/safe_eval.py +++ b/odoo/tools/safe_eval.py @@ -21,8 +21,10 @@ import functools from psycopg2 import OperationalError from types import CodeType import logging +import sys import werkzeug +from . import pycompat from .misc import ustr import odoo @@ -159,9 +161,8 @@ def test_expr(expr, allowed_codes, mode="eval"): except (SyntaxError, TypeError, ValueError): raise except Exception as e: - import sys exc_info = sys.exc_info() - raise ValueError, '"%s" while compiling\n%r' % (ustr(e), expr), exc_info[2] + pycompat.reraise(ValueError, ValueError('"%s" while compiling\n%r' % (ustr(e), expr)), exc_info[2]) assert_valid_codeobj(allowed_codes, code_obj, expr) return code_obj @@ -320,9 +321,8 @@ def safe_eval(expr, globals_dict=None, locals_dict=None, mode="eval", nocopy=Fal except odoo.exceptions.MissingError: raise except Exception as e: - import sys exc_info = sys.exc_info() - raise ValueError, '%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr), exc_info[2] + pycompat.reraise(ValueError, ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)), exc_info[2]) def test_python_expr(expr, mode="eval"): try: test_expr(expr, _SAFE_OPCODES, mode=mode) |
