Ejemplo n.º 1
0
 def __init__(self, exc_info=None, **kwargs):
     if not kwargs:
         if exc_info is None:
             exc_info = sys.exc_info()
         else:
             # This should always be the (type, value, traceback) tuple,
             # either from a prior sys.exc_info() call or from some other
             # creation...
             if len(exc_info) != 3:
                 raise ValueError("Provided 'exc_info' must contain three"
                                  " elements")
         self._exc_info = exc_info
         self._exc_type_names = tuple(
             reflection.get_all_class_names(exc_info[0], up_to=Exception))
         if not self._exc_type_names:
             raise TypeError("Invalid exception type '%s' (%s)" %
                             (exc_info[0], type(exc_info[0])))
         self._exception_str = exc.exception_message(self._exc_info[1])
         self._traceback_str = ''.join(
             traceback.format_tb(self._exc_info[2]))
         self._causes = kwargs.pop('causes', None)
     else:
         self._causes = kwargs.pop('causes', None)
         self._exc_info = exc_info
         self._exception_str = kwargs.pop('exception_str')
         self._exc_type_names = tuple(kwargs.pop('exc_type_names', []))
         self._traceback_str = kwargs.pop('traceback_str', None)
         if kwargs:
             raise TypeError(
                 'Failure.__init__ got unexpected keyword argument(s): %s' %
                 ', '.join(six.iterkeys(kwargs)))
Ejemplo n.º 2
0
 def __init__(self, exc_info=None, **kwargs):
     if not kwargs:
         if exc_info is None:
             exc_info = sys.exc_info()
         else:
             # This should always be the (type, value, traceback) tuple,
             # either from a prior sys.exc_info() call or from some other
             # creation...
             if len(exc_info) != 3:
                 raise ValueError("Provided 'exc_info' must contain three"
                                  " elements")
         self._exc_info = exc_info
         self._exc_type_names = tuple(
             reflection.get_all_class_names(exc_info[0], up_to=Exception))
         if not self._exc_type_names:
             raise TypeError('Invalid exception type: %r' % exc_info[0])
         self._exception_str = exc.exception_message(self._exc_info[1])
         self._traceback_str = ''.join(
             traceback.format_tb(self._exc_info[2]))
     else:
         self._exc_info = exc_info  # may be None
         self._exception_str = kwargs.pop('exception_str')
         self._exc_type_names = tuple(kwargs.pop('exc_type_names', []))
         self._traceback_str = kwargs.pop('traceback_str', None)
         if kwargs:
             raise TypeError(
                 'Failure.__init__ got unexpected keyword argument(s): %s'
                 % ', '.join(six.iterkeys(kwargs)))
Ejemplo n.º 3
0
def _are_equal_exc_info_tuples(ei1, ei2):
    if ei1 == ei2:
        return True
    if ei1 is None or ei2 is None:
        return False  # if both are None, we returned True above

    # NOTE(imelnikov): we can't compare exceptions with '=='
    # because we want exc_info be equal to it's copy made with
    # copy_exc_info above.
    if ei1[0] is not ei2[0]:
        return False
    if not all((type(ei1[1]) == type(ei2[1]),
                exc.exception_message(ei1[1]) == exc.exception_message(ei2[1]),
                repr(ei1[1]) == repr(ei2[1]))):
        return False
    if ei1[2] == ei2[2]:
        return True
    tb1 = traceback.format_tb(ei1[2])
    tb2 = traceback.format_tb(ei2[2])
    return tb1 == tb2
Ejemplo n.º 4
0
def _are_equal_exc_info_tuples(ei1, ei2):
    if ei1 == ei2:
        return True
    if ei1 is None or ei2 is None:
        return False  # if both are None, we returned True above

    # NOTE(imelnikov): we can't compare exceptions with '=='
    # because we want exc_info be equal to it's copy made with
    # copy_exc_info above.
    if ei1[0] is not ei2[0]:
        return False
    if not all(
        (type(ei1[1]) == type(ei2[1]), exc.exception_message(ei1[1])
         == exc.exception_message(ei2[1]), repr(ei1[1]) == repr(ei2[1]))):
        return False
    if ei1[2] == ei2[2]:
        return True
    tb1 = traceback.format_tb(ei1[2])
    tb2 = traceback.format_tb(ei2[2])
    return tb1 == tb2
Ejemplo n.º 5
0
 def test_wrapped_failure_non_ascii_unicode(self):
     hi_cn = u"嗨"
     fail = ValueError(hi_cn)
     self.assertEqual(hi_cn, exceptions.exception_message(fail))
     fail = failure.Failure.from_exception(fail)
     wrapped_fail = exceptions.WrappedFailure([fail])
     if six.PY2:
         # Python 2.x will unicode escape it, while python 3.3+ will not,
         # so we sadly have to differentiate between these two...
         expected_result = u"WrappedFailure: " "[u'Failure: ValueError: %s']" % (hi_cn.encode("unicode-escape"))
     else:
         expected_result = u"WrappedFailure: " "['Failure: ValueError: %s']" % (hi_cn)
     self.assertEqual(expected_result, six.text_type(wrapped_fail))
Ejemplo n.º 6
0
 def test_wrapped_failure_non_ascii_unicode(self):
     hi_cn = u'嗨'
     fail = ValueError(hi_cn)
     self.assertEqual(hi_cn, exceptions.exception_message(fail))
     fail = misc.Failure.from_exception(fail)
     wrapped_fail = exceptions.WrappedFailure([fail])
     if six.PY2:
         # Python 2.x will unicode escape it, while python 3.3+ will not,
         # so we sadly have to differentiate between these two...
         expected_result = (u"WrappedFailure: "
                            "[u'Failure: ValueError: %s']" %
                            (hi_cn.encode("unicode-escape")))
     else:
         expected_result = (u"WrappedFailure: "
                            "['Failure: ValueError: %s']" % (hi_cn))
     self.assertEqual(expected_result, six.text_type(wrapped_fail))
Ejemplo n.º 7
0
 def __init__(self, exc_info=None, **kwargs):
     if not kwargs:
         if exc_info is None:
             exc_info = sys.exc_info()
         self._exc_info = exc_info
         self._exc_type_names = list(
             reflection.get_all_class_names(exc_info[0], up_to=Exception))
         if not self._exc_type_names:
             raise TypeError('Invalid exception type: %r' % exc_info[0])
         self._exception_str = exc.exception_message(self._exc_info[1])
         self._traceback_str = ''.join(
             traceback.format_tb(self._exc_info[2]))
     else:
         self._exc_info = exc_info  # may be None
         self._exception_str = kwargs.pop('exception_str')
         self._exc_type_names = kwargs.pop('exc_type_names', [])
         self._traceback_str = kwargs.pop('traceback_str', None)
         if kwargs:
             raise TypeError(
                 'Failure.__init__ got unexpected keyword argument(s): %s'
                 % ', '.join(six.iterkeys(kwargs)))
Ejemplo n.º 8
0
 def __init__(self, exc_info=None, **kwargs):
     if not kwargs:
         if exc_info is None:
             exc_info = sys.exc_info()
         self._exc_info = exc_info
         self._exc_type_names = list(
             reflection.get_all_class_names(exc_info[0], up_to=Exception))
         if not self._exc_type_names:
             raise TypeError('Invalid exception type: %r' % exc_info[0])
         self._exception_str = exc.exception_message(self._exc_info[1])
         self._traceback_str = ''.join(
             traceback.format_tb(self._exc_info[2]))
     else:
         self._exc_info = exc_info  # may be None
         self._exception_str = kwargs.pop('exception_str')
         self._exc_type_names = kwargs.pop('exc_type_names', [])
         self._traceback_str = kwargs.pop('traceback_str', None)
         if kwargs:
             raise TypeError(
                 'Failure.__init__ got unexpected keyword argument(s): %s' %
                 ', '.join(six.iterkeys(kwargs)))