Stop holding on to sys.exc_info tuples quite so much

This used to be necessary on older eventlet, or you'd get TypeErrors
when you went to reraise. Following eventlet 0.13.0, however, it's just
extra code.

For the original eventlet issue, see
https://web.archive.org/web/20140823005223/https://bitbucket.org/eventlet/eventlet/issue/149/yield-in-except-clause-with-wilcard-raise

Change-Id: I19ad0968a82827bdd4ef75fde9ed51f193627d6e
Related-Bug: 1181146
This commit is contained in:
Tim Burke 2018-05-24 15:44:39 -07:00
parent d97673cf54
commit 7fd5a12872
9 changed files with 18 additions and 38 deletions

View File

@ -221,7 +221,7 @@ class InternalClient(object):
raise UnexpectedResponse(msg, resp)
if exc_type:
# To make pep8 tool happy, in place of raise t, v, tb:
six.reraise(exc_type(*exc_value.args), None, exc_traceback)
six.reraise(exc_type, exc_value, exc_traceback)
def _get_metadata(
self, path, metadata_prefix='', acceptable_statuses=(2,),

View File

@ -71,10 +71,8 @@ if this is a middleware subrequest or not. A log processor calculating
bandwidth usage will want to only sum up logs with no swift.source.
"""
import sys
import time
import six
from six.moves.urllib.parse import quote
from swift.common.swob import Request
from swift.common.utils import (get_logger, get_remote_client,
@ -333,13 +331,12 @@ class ProxyLoggingMiddleware(object):
try:
iterable = self.app(env, my_start_response)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
req = Request(env)
status_int = status_int_for_logging(start_status=500)
self.log_request(
req, status_int, input_proxy.bytes_received, 0, start_time,
time.time())
six.reraise(exc_type, exc_value, exc_traceback)
raise
else:
return iter_response(iterable)

View File

@ -49,8 +49,6 @@ Example::
the end of method.
"""
import sys
from swift.common.middleware.s3api.subresource import ACL, Owner, encode_acl
from swift.common.middleware.s3api.s3response import MissingSecurityHeader, \
MalformedACLError, UnexpectedContent
@ -168,9 +166,8 @@ class BaseAclHandler(object):
except(XMLSyntaxError, DocumentInvalid):
raise MalformedACLError()
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
self.logger.error(e)
raise exc_type, exc_value, exc_traceback
raise
else:
if body:
# Specifying grant with both header and xml is not allowed.

View File

@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from base64 import standard_b64encode as b64encode
from base64 import standard_b64decode as b64decode
@ -218,9 +217,8 @@ class BucketController(Controller):
except (XMLSyntaxError, DocumentInvalid):
raise MalformedXML()
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
self.logger.error(e)
raise exc_type, exc_value, exc_traceback
raise
if location != self.conf.location:
# s3api cannot support multiple regions currently.

View File

@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from swift.common.utils import public
from swift.common.middleware.s3api.controllers.base import Controller, \
@ -85,9 +83,8 @@ class MultiObjectDeleteController(Controller):
except ErrorResponse:
raise
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
self.logger.error(e)
raise exc_type, exc_value, exc_traceback
raise
elem = Element('DeleteResult')

View File

@ -61,7 +61,6 @@ Static Large Object when the multipart upload is completed.
import os
import re
import sys
from swift.common.swob import Range
from swift.common.utils import json, public
@ -605,9 +604,8 @@ class UploadController(Controller):
except ErrorResponse:
raise
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
self.logger.error(e)
raise exc_type, exc_value, exc_traceback
raise
# Check the size of each segment except the last and make sure they are
# all more than the minimum upload chunk size

View File

@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from swift.common.http import HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_NO_CONTENT
from swift.common.swob import Range, content_range_header_value
from swift.common.utils import public
@ -144,7 +142,6 @@ class ObjectController(Controller):
resp.body = ''
except NoSuchKey:
# expect to raise NoSuchBucket when the bucket doesn't exist
exc_type, exc_value, exc_traceback = sys.exc_info()
req.get_container_info(self.app)
raise exc_type, exc_value, exc_traceback
raise
return resp

View File

@ -18,7 +18,6 @@ from urllib import quote
from copy import deepcopy
from pkg_resources import resource_stream # pylint: disable-msg=E0611
import six
import sys
from swift.common.utils import get_logger
from swift.common.middleware.s3api.exception import S3Exception
@ -76,10 +75,9 @@ def fromstring(text, root_tag=None, logger=None):
lxml.etree.RelaxNG(file=rng).assertValid(elem)
except IOError as e:
# Probably, the schema file doesn't exist.
exc_type, exc_value, exc_traceback = sys.exc_info()
logger = logger or get_logger({}, log_route='s3api')
logger.error(e)
raise exc_type, exc_value, exc_traceback
raise
except lxml.etree.DocumentInvalid as e:
if logger:
logger.debug(e)

View File

@ -973,7 +973,7 @@ class ResumingGetter(object):
except ChunkReadTimeout:
exc_type, exc_value, exc_traceback = exc_info()
if self.newest or self.server_type != 'Object':
six.reraise(exc_type, exc_value, exc_traceback)
raise
try:
self.fast_forward(self.bytes_used_from_backend)
except (HTTPException, ValueError):
@ -1091,20 +1091,18 @@ class ResumingGetter(object):
self.app.client_timeout)
self.app.logger.increment('client_timeouts')
except GeneratorExit:
exc_type, exc_value, exc_traceback = exc_info()
warn = True
try:
req_range = Range(self.backend_headers['Range'])
except ValueError:
req_range = None
if req_range and len(req_range.ranges) == 1:
begin, end = req_range.ranges[0]
if end is not None and begin is not None:
if end - begin + 1 == self.bytes_used_from_backend:
warn = False
req_range = self.backend_headers['Range']
if req_range:
req_range = Range(req_range)
if len(req_range.ranges) == 1:
begin, end = req_range.ranges[0]
if end is not None and begin is not None:
if end - begin + 1 == self.bytes_used_from_backend:
warn = False
if not req.environ.get('swift.non_client_disconnect') and warn:
self.app.logger.warning(_('Client disconnected on read'))
six.reraise(exc_type, exc_value, exc_traceback)
raise
except Exception:
self.app.logger.exception(_('Trying to send to client'))
raise