From d863ccf458e2a46beee560a8c3dee1cd0bacbd61 Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Wed, 14 Aug 2013 14:07:31 -0400 Subject: [PATCH] Work around a 2to3 bug. PYTHON-494 --- bson/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bson/__init__.py b/bson/__init__.py index b105df9e1..173d5db20 100644 --- a/bson/__init__.py +++ b/bson/__init__.py @@ -520,7 +520,13 @@ def decode_all(data, as_class=dict, except Exception: # Change exception type to InvalidBSON but preserve traceback. exc_type, exc_value, exc_tb = sys.exc_info() - raise InvalidBSON, InvalidBSON(str(exc_value)), exc_tb + if PY3: + e = InvalidBSON(str(exc_value)) + raise e.with_traceback(exc_tb) + else: + # 2to3 mistranslates this. + raise InvalidBSON, InvalidBSON(str(exc_value)), exc_tb + if _use_c: decode_all = _cbson.decode_all