Merge "Remove various usage of sys.exc_info()"

This commit is contained in:
Jenkins 2013-09-22 14:31:54 +00:00 committed by Gerrit Code Review
commit dae6299157
6 changed files with 12 additions and 31 deletions

View File

@ -192,8 +192,7 @@ class WSRoot(object):
# TODO make sure result type == a._wsme_definition.return_type # TODO make sure result type == a._wsme_definition.return_type
return protocol.encode_result(context, result) return protocol.encode_result(context, result)
except Exception: except Exception as e:
e = sys.exc_info()[1]
infos = wsme.api.format_exception(sys.exc_info(), self._debug) infos = wsme.api.format_exception(sys.exc_info(), self._debug)
if isinstance(e, ClientSideError): if isinstance(e, ClientSideError):
request.client_errorcount += 1 request.client_errorcount += 1
@ -233,8 +232,7 @@ class WSRoot(object):
try: try:
msg = None msg = None
protocol = self._select_protocol(request) protocol = self._select_protocol(request)
except Exception: except Exception as e:
e = sys.exc_info()[1]
msg = ("Error while selecting protocol: %s" % str(e)) msg = ("Error while selecting protocol: %s" % str(e))
log.exception(msg) log.exception(msg)
protocol = None protocol = None
@ -339,8 +337,7 @@ class WSRoot(object):
return html_body % dict( return html_body % dict(
css=formatter.get_style_defs(), css=formatter.get_style_defs(),
content=highlight(content, lexer, formatter).encode('utf8')) content=highlight(content, lexer, formatter).encode('utf8'))
except Exception: except Exception as e:
e = sys.exc_info()[1]
log.warning( log.warning(
"Could not pygment the content because of the following " "Could not pygment the content because of the following "
"error :\n%s" % e) "error :\n%s" % e)

View File

@ -4,7 +4,6 @@ import unittest
import warnings import warnings
import datetime import datetime
import decimal import decimal
import sys
import six import six
from six import u, b from six import u, b
@ -22,8 +21,7 @@ binarysample = b('\x00\xff\x43')
try: try:
1 / 0 1 / 0
except ZeroDivisionError: except ZeroDivisionError as e:
e = sys.exc_info()[1]
zerodivisionerrormsg = str(e) zerodivisionerrormsg = str(e)
@ -379,8 +377,7 @@ class ProtocolTestCase(unittest.TestCase):
res = self.call('invalid_function') res = self.call('invalid_function')
print(res) print(res)
assert "No error raised" assert "No error raised"
except CallException: except CallException as e:
e = sys.exc_info()[1]
self.assertEquals(e.faultcode, 'Client') self.assertEquals(e.faultcode, 'Client')
self.assertEquals(e.faultstring.lower(), self.assertEquals(e.faultstring.lower(),
u('unknown function name: invalid_function')) u('unknown function name: invalid_function'))
@ -390,9 +387,7 @@ class ProtocolTestCase(unittest.TestCase):
res = self.call('witherrors/divide_by_zero') res = self.call('witherrors/divide_by_zero')
print(res) print(res)
assert "No error raised" assert "No error raised"
except CallException: except CallException as e:
e = sys.exc_info()[1]
print(e)
self.assertEquals(e.faultcode, 'Server') self.assertEquals(e.faultcode, 'Server')
self.assertEquals(e.faultstring, zerodivisionerrormsg) self.assertEquals(e.faultstring, zerodivisionerrormsg)
assert e.debuginfo is not None assert e.debuginfo is not None
@ -403,9 +398,7 @@ class ProtocolTestCase(unittest.TestCase):
res = self.call('witherrors/divide_by_zero') res = self.call('witherrors/divide_by_zero')
print(res) print(res)
assert "No error raised" assert "No error raised"
except CallException: except CallException as e:
e = sys.exc_info()[1]
print(e)
self.assertEquals(e.faultcode, 'Server') self.assertEquals(e.faultcode, 'Server')
self.assertEquals(e.faultstring, zerodivisionerrormsg) self.assertEquals(e.faultstring, zerodivisionerrormsg)
assert e.debuginfo is None assert e.debuginfo is None
@ -649,9 +642,7 @@ class ProtocolTestCase(unittest.TestCase):
r = self.call('argtypes/setdatetime') r = self.call('argtypes/setdatetime')
print(r) print(r)
assert "No error raised" assert "No error raised"
except CallException: except CallException as e:
e = sys.exc_info()[1]
print(e)
self.assertEquals(e.faultcode, 'Client') self.assertEquals(e.faultcode, 'Client')
self.assertEquals(e.faultstring, u('Missing argument: "value"')) self.assertEquals(e.faultstring, u('Missing argument: "value"'))

View File

@ -1,7 +1,6 @@
# encoding=utf8 # encoding=utf8
from six import b from six import b
import sys
import unittest import unittest
import webtest import webtest
@ -107,8 +106,7 @@ class TestController(unittest.TestCase):
try: try:
list(scan_api(r)) list(scan_api(r))
assert False, "ValueError not raised" assert False, "ValueError not raised"
except ValueError: except ValueError as e:
e = sys.exc_info()[1]
assert str(e).startswith("Path is too long") assert str(e).startswith("Path is too long")
def test_handle_request(self): def test_handle_request(self):

View File

@ -1,5 +1,4 @@
import unittest import unittest
import sys
import six import six
from wsme import types from wsme import types
@ -180,8 +179,7 @@ class TestTypes(unittest.TestCase):
try: try:
obj.a = 'v3' obj.a = 'v3'
assert False, 'ValueError was not raised' assert False, 'ValueError was not raised'
except ValueError: except ValueError as e:
e = sys.exc_info()[1]
assert str(e) == \ assert str(e) == \
"a: Value 'v3' is invalid (should be one of: v1, v2)", e "a: Value 'v3' is invalid (should be one of: v1, v2)", e

View File

@ -340,8 +340,7 @@ class wsattr(object):
def __set__(self, instance, value): def __set__(self, instance, value):
try: try:
value = validate_value(self.datatype, value) value = validate_value(self.datatype, value)
except ValueError: except ValueError as e:
e = sys.exc_info()[1]
raise ValueError("%s: %s" % (self.name, e)) raise ValueError("%s: %s" % (self.name, e))
dataholder = self._get_dataholder(instance) dataholder = self._get_dataholder(instance)
if value is Unset: if value is Unset:

View File

@ -1,7 +1,6 @@
import decimal import decimal
import datetime import datetime
import base64 import base64
import sys
import six import six
@ -318,8 +317,7 @@ class TestSOAP(wsme.tests.protocol.ProtocolTestCase):
print(kw) print(kw)
try: try:
return fromsuds(_rt, m(**kw)) return fromsuds(_rt, m(**kw))
except suds.WebFault: except suds.WebFault as exc:
exc = sys.exc_info()[1]
raise wsme.tests.protocol.CallException( raise wsme.tests.protocol.CallException(
exc.fault.faultcode, exc.fault.faultcode,
exc.fault.faultstring, exc.fault.faultstring,