diff options
author | haixin <haixin@inspur.com> | 2020-10-07 11:48:23 +0800 |
---|---|---|
committer | haixin <haixin@inspur.com> | 2020-10-09 19:20:51 +0800 |
commit | cfe9881e6b363251d09e59e9b6c8a21ab6fbef37 (patch) | |
tree | bca1a3d5b231358e9d737580c9e5d2046bc44f99 /oslo_utils/excutils.py | |
parent | 87d2a1f9d4be63633f0988a112b2f6f706352de1 (diff) | |
download | oslo-utils-cfe9881e6b363251d09e59e9b6c8a21ab6fbef37.tar.gz |
Remove all usage of six library
Replace six with Python 3 style code.
Change-Id: I52aa4a0f679b56ffa57cdd2199933e36cf076992
Diffstat (limited to 'oslo_utils/excutils.py')
-rw-r--r-- | oslo_utils/excutils.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/oslo_utils/excutils.py b/oslo_utils/excutils.py index 533c7ee..94a6655 100644 --- a/oslo_utils/excutils.py +++ b/oslo_utils/excutils.py @@ -18,14 +18,13 @@ Exception related utilities. """ import functools +import io import logging import os import sys import time import traceback -import six - from oslo_utils import encodeutils from oslo_utils import reflection @@ -70,7 +69,7 @@ class CausedByException(Exception): if indent < 0: raise ValueError("Provided 'indent' must be greater than" " or equal to zero instead of %s" % indent) - buf = six.StringIO() + buf = io.StringIO() if show_root_class: buf.write(reflection.get_class_name(self, fully_qualified=False)) buf.write(": ") @@ -140,7 +139,7 @@ def raise_with_cause(exc_cls, message, *args, **kwargs): # Leave no references around (especially with regards to # tracebacks and any variables that it retains internally). del(exc_type, exc, exc_tb) - six.raise_from(exc_cls(message, *args, **kwargs), kwargs.get('cause')) + raise exc_cls(message, *args, **kwargs) from kwargs.get('cause') class save_and_reraise_exception(object): @@ -193,7 +192,15 @@ class save_and_reraise_exception(object): if self.type_ is None and self.value is None: raise RuntimeError("There is no (currently) captured exception" " to force the reraising of") - six.reraise(self.type_, self.value, self.tb) + try: + if self.value is None: + self.value = self.type_() + if self.value.__traceback__ is not self.tb: + raise self.value.with_traceback(self.tb) + raise self.value + finally: + self.value = None + self.tb = None def capture(self, check=True): (type_, value, tb) = sys.exc_info() @@ -240,7 +247,7 @@ def forever_retry_uncaught_exceptions(*args, **kwargs): retry_delay = max(0.0, float(kwargs.get('retry_delay', 1.0))) same_log_delay = max(0.0, float(kwargs.get('same_log_delay', 60.0))) - @six.wraps(infunc) + @functools.wraps(infunc) def wrapper(*args, **kwargs): last_exc_message = None same_failure_count = 0 @@ -339,7 +346,15 @@ class exception_filter(object): try: if not self._should_ignore_ex(ex): if exc_val is ex: - six.reraise(exc_type, exc_val, traceback) + try: + if exc_val is None: + exc_val = exc_type() + if exc_val.__traceback__ is not traceback: + raise exc_val.with_traceback(traceback) + raise exc_val + finally: + exc_val = None + traceback = None else: raise ex finally: |