[py3k] Fix raise with embedded traceback
python 3 removed the raise syntax with 2 and 3 expressions.
--- a/dataimport/deprecated.py Fri Sep 11 14:52:09 2015 +0200
+++ b/dataimport/deprecated.py Fri Sep 11 15:29:25 2015 +0200
@@ -167,7 +167,9 @@
if res[dest] is None:
break
except ValueError as err:
- raise ValueError('error with %r field: %s' % (src, err)), None, sys.exc_info()[-1]
+ exc = ValueError('error with %r field: %s' % (src, err))
+ exc.__traceback__ = sys.exc_info()[-1]
+ raise exc
return res
--- a/devtools/testlib.py Fri Sep 11 14:52:09 2015 +0200
+++ b/devtools/testlib.py Fri Sep 11 15:29:25 2015 +0200
@@ -940,7 +940,9 @@
msg = '[%s in %s] %s' % (klass, view.__regid__, exc)
except Exception:
msg = '[%s in %s] undisplayable exception' % (klass, view.__regid__)
- raise AssertionError, msg, tcbk
+ exc = AssertionError(msg)
+ exc.__traceback__ = tcbk
+ raise exc
return self._check_html(output, view, template)
def get_validator(self, view=None, content_type=None, output=None):
@@ -1015,7 +1017,9 @@
for idx, line in enumerate(content)
if line_context_filter(idx+1, position))
msg += u'\nfor content:\n%s' % content
- raise AssertionError, msg, tcbk
+ exc = AssertionError(msg)
+ exc.__traceback__ = tcbk
+ raise exc
def assertDocTestFile(self, testfile):
# doctest returns tuple (failure_count, test_count)
--- a/ext/tal.py Fri Sep 11 14:52:09 2015 +0200
+++ b/ext/tal.py Fri Sep 11 15:29:25 2015 +0200
@@ -184,7 +184,10 @@
interpreter.execute(self)
except UnicodeError as unierror:
LOGGER.exception(str(unierror))
- raise simpleTALES.ContextContentException("found non-unicode %r string in Context!" % unierror.args[1]), None, sys.exc_info()[-1]
+ exc = simpleTALES.ContextContentException(
+ "found non-unicode %r string in Context!" % unierror.args[1])
+ exc.__traceback__ = sys.exc_info()[-1]
+ raise exc
def compile_template(template):
@@ -232,7 +235,8 @@
result = eval(expr, globals, locals)
except Exception as ex:
ex = ex.__class__('in %r: %s' % (expr, ex))
- raise ex, None, sys.exc_info()[-1]
+ ex.__traceback__ = sys.exc_info()[-1]
+ raise ex
if (isinstance (result, simpleTALES.ContextVariable)):
return result.value()
return result
--- a/gettext.py Fri Sep 11 14:52:09 2015 +0200
+++ b/gettext.py Fri Sep 11 15:29:25 2015 +0200
@@ -103,11 +103,10 @@
try:
danger = [x for x in tokens if x[0] == token.NAME and x[1] != 'n']
except tokenize.TokenError:
- raise ValueError, \
- 'plural forms expression error, maybe unbalanced parenthesis'
+ raise ValueError('plural forms expression error, maybe unbalanced parenthesis')
else:
if danger:
- raise ValueError, 'plural forms expression could be dangerous'
+ raise ValueError('plural forms expression could be dangerous')
# Replace some C operators by their Python equivalents
plural = plural.replace('&&', ' and ')
@@ -133,7 +132,7 @@
# Actually, we never reach this code, because unbalanced
# parentheses get caught in the security check at the
# beginning.
- raise ValueError, 'unbalanced parenthesis in plural form'
+ raise ValueError('unbalanced parenthesis in plural form')
s = expr.sub(repl, stack.pop())
stack[-1] += '(%s)' % s
else:
--- a/web/http_headers.py Fri Sep 11 14:52:09 2015 +0200
+++ b/web/http_headers.py Fri Sep 11 15:29:25 2015 +0200
@@ -295,9 +295,9 @@
cur = cur+1
if qpair:
- raise ValueError, "Missing character after '\\'"
+ raise ValueError("Missing character after '\\'")
if quoted:
- raise ValueError, "Missing end quote"
+ raise ValueError("Missing end quote")
if start != cur:
if foldCase:
@@ -347,7 +347,7 @@
##### parser utilities:
def checkSingleToken(tokens):
if len(tokens) != 1:
- raise ValueError, "Expected single token, not %s." % (tokens,)
+ raise ValueError("Expected single token, not %s." % (tokens,))
return tokens[0]
def parseKeyValue(val):
@@ -355,7 +355,7 @@
return val[0], None
elif len(val) == 3 and val[1] == Token('='):
return val[0], val[2]
- raise ValueError, "Expected key or key=value, but got %s." % (val,)
+ raise ValueError("Expected key or key=value, but got %s." % (val,))
def parseArgs(field):
args = split(field, Token(';'))
@@ -506,7 +506,7 @@
type, args = parseArgs(field)
if len(type) != 3 or type[1] != Token('/'):
- raise ValueError, "MIME Type "+str(type)+" invalid."
+ raise ValueError("MIME Type "+str(type)+" invalid.")
# okay, this spec is screwy. A 'q' parameter is used as the separator
# between MIME parameters and (as yet undefined) additional HTTP
@@ -569,7 +569,7 @@
type, args = parseArgs(header)
if len(type) != 3 or type[1] != Token('/'):
- raise ValueError, "MIME Type "+str(type)+" invalid."
+ raise ValueError("MIME Type "+str(type)+" invalid.")
args = [(kv[0].lower(), kv[1]) for kv in args]
--- a/web/views/baseviews.py Fri Sep 11 14:52:09 2015 +0200
+++ b/web/views/baseviews.py Fri Sep 11 15:29:25 2015 +0200
@@ -231,7 +231,7 @@
"""
rset = self.cw_rset
if rset is None:
- raise NotImplementedError, self
+ raise NotImplementedError(self)
for i in xrange(len(rset)):
self.wview(self.__regid__, rset, row=i, **kwargs)
if len(rset) > 1: