Add a exception reraise function to compat that will allow us to
rewrite invocations like this:
except Exception as e:
raise ClientError, e, sys.exc_info()[2]
as this:
except Exception as e:
reraise(ClientError(e))
since python 3 now provides a with_traceback() method that we can (and
must) use instead.
Put the python 2 specific formulation (shown above) in a separate
py2raise module that we can conditionally import because python 3
decided to make the python 2 code produce a syntax error.
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
from array import array
from binascii import hexlify
from traceback import print_exception
-import sys
+import os, sys
# Please see CODINGSTYLE for important exception handling guidelines
# and the rationale behind add_ex_tb(), add_ex_ctx(), etc.
"""Return hex string (not bytes as with hexlify) representation of b."""
return b.hex()
+ def reraise(ex):
+ raise ex.with_traceback(sys.exc_info()[2])
+
def add_ex_tb(ex):
"""Do nothing (already handled by Python 3 infrastructure)."""
return ex
from pipes import quote
from os import environ
+
+ from bup.py2raise import reraise
+
range = xrange
str_type = basestring
int_types = (int, long)
--- /dev/null
+
+# This file exists because the raise syntax is completely incompatible
+# with Python 3.
+
+def reraise(ex):
+ raise ex, None, sys.exc_info()[2]