Example #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)))
Example #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 '%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]))
     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)))
 def test_std_class_up_to(self):
     names = list(reflection.get_all_class_names(RuntimeError,
                                                 up_to=Exception))
     self.assertEqual(RUNTIME_ERROR_CLASSES[:-2], names)
 def test_std_class(self):
     names = list(reflection.get_all_class_names(RuntimeError))
     self.assertEqual(RUNTIME_ERROR_CLASSES, names)
 def test_std_class_up_to(self):
     names = list(
         reflection.get_all_class_names(RuntimeError, up_to=Exception))
     self.assertEqual(RUNTIME_ERROR_CLASSES[:-2], names)
 def test_std_class(self):
     names = list(reflection.get_all_class_names(RuntimeError))
     self.assertEqual(RUNTIME_ERROR_CLASSES, names)
Example #7
0

kwargs_func('0', 1, 2, 3, 4, k1=5, k2=6)


class A(object):
    pass


class B(A):
    pass


class C(B):
    pass


for m in [
        reflection.get_callable_args, reflection.get_callable_name,
        reflection.accepts_kwargs
]:
    for n in [args_func, kwargs_func]:
        print("%-50s (%-20s): %s" % (reflection.get_callable_name(m),
                                     reflection.get_callable_name(n), m(n)))

print(list(reflection.get_all_class_names(C())))

# Special arguments (like *args and **kwargs) are not included into output.
#print(reflection.get_callable_args(args_func))
#print(reflection.get_callable_args(kwargs_func))
Example #8
0
def extract_roots(exc_type):
    return to_tuple(
        reflection.get_all_class_names(exc_type,
                                       up_to=BaseException,
                                       truncate_builtins=False))