Exemple #1
0
        def wrapped(self, context, *args, **kw):
            # Don't store self or context in the payload, it now seems to
            # contain confidential information.
            try:
                return f(self, context, *args, **kw)
            except Exception as e:
                with excutils.save_and_reraise_exception():
                    if notifier or get_notifier:
                        payload = dict(exception=e)
                        wrapped_func = safe_utils.get_wrapped_function(f)
                        call_dict = inspect.getcallargs(
                            wrapped_func, self, context, *args, **kw)
                        # self can't be serialized and shouldn't be in the
                        # payload
                        call_dict.pop('self', None)
                        cleansed = _cleanse_dict(call_dict)
                        payload.update({'args': cleansed})

                        # If f has multiple decorators, they must use
                        # functools.wraps to ensure the name is
                        # propagated.
                        event_type = f.__name__

                        (notifier
                         or get_notifier()).error(context, event_type, payload)
        def wrapped(self, context, *args, **kw):
            # Don't store self or context in the payload, it now seems to
            # contain confidential information.
            try:
                return f(self, context, *args, **kw)
            except Exception as e:
                with excutils.save_and_reraise_exception():
                    if notifier or get_notifier:
                        payload = dict(exception=e)
                        wrapped_func = safe_utils.get_wrapped_function(f)
                        call_dict = inspect.getcallargs(wrapped_func, self,
                                                        context, *args, **kw)
                        # self can't be serialized and shouldn't be in the
                        # payload
                        call_dict.pop('self', None)
                        cleansed = _cleanse_dict(call_dict)
                        payload.update({'args': cleansed})

                        # If f has multiple decorators, they must use
                        # functools.wraps to ensure the name is
                        # propagated.
                        event_type = f.__name__

                        (notifier or get_notifier()).error(context,
                                                           event_type,
                                                           payload)
Exemple #3
0
    def test_single_wrapped(self):
        @self._wrapper
        def wrapped(self, instance, red=None, blue=None):
            pass

        func = safe_utils.get_wrapped_function(wrapped)
        func_code = func.__code__
        self.assertEqual(4, len(func_code.co_varnames))
        self.assertIn('self', func_code.co_varnames)
        self.assertIn('instance', func_code.co_varnames)
        self.assertIn('red', func_code.co_varnames)
        self.assertIn('blue', func_code.co_varnames)
Exemple #4
0
    def test_single_wrapped(self):
        @self._wrapper
        def wrapped(self, instance, red=None, blue=None):
            pass

        func = safe_utils.get_wrapped_function(wrapped)
        func_code = func.__code__
        self.assertEqual(4, len(func_code.co_varnames))
        self.assertIn('self', func_code.co_varnames)
        self.assertIn('instance', func_code.co_varnames)
        self.assertIn('red', func_code.co_varnames)
        self.assertIn('blue', func_code.co_varnames)
Exemple #5
0
 def _decorator(f):
     base_f = safe_utils.get_wrapped_function(f)
     arg_names, a, kw, _default = inspect.getargspec(base_f)
     if a or kw or set(args) <= set(arg_names):
         # NOTE : We can't really tell if correct stuff will
         # be passed if it's a function with *args or **kwargs so
         # we still carry on and hope for the best
         return dec(f)
     else:
         raise TypeError("Decorated function %(f_name)s does not "
                         "have the arguments expected by the "
                         "decorator %(d_name)s" %
                         {'f_name': base_f.__name__,
                          'd_name': dec.__name__})
Exemple #6
0
 def _decorator(f):
     base_f = safe_utils.get_wrapped_function(f)
     arg_names, a, kw, _default = inspect.getargspec(base_f)
     if a or kw or set(args) <= set(arg_names):
         # NOTE : We can't really tell if correct stuff will
         # be passed if it's a function with *args or **kwargs so
         # we still carry on and hope for the best
         return dec(f)
     else:
         raise TypeError("Decorated function %(f_name)s does not "
                         "have the arguments expected by the "
                         "decorator %(d_name)s" % {
                             'f_name': base_f.__name__,
                             'd_name': dec.__name__
                         })