+ if self._params_decoration:\r
+ for dec in self._params_decoration:\r
+ try:\r
+ args, kwargs = dec(*args, **kwargs)\r
+ except ReturnImediatelyException, e:\r
+ return e.ret\r
+\r
+ res = self._callable(*args, **kwargs)\r
+\r
+ if self._result_decoration:\r
+ for dec in self._result_decoration:\r
+ if dec._needs_params:\r
+ res = dec(res, *args, **kwargs)\r
+ else:\r
+ res = dec(res)\r
+\r
+ return res\r
+\r
+class ReturnImediatelyException(Exception):\r
+ def __init__(self, ret):\r
+ super(Exception, self).__init__()\r
+ self.ret = ret\r
+\r
+def _check_decoratable(origin, install=True):\r
+ if not hasattr(origin, '_decoratable_obj'):\r
+ if inspect.ismethod(origin) and not hasattr(origin, '_decoratable_obj'):\r
+ decoratable = DecoratableObject(origin)\r
+\r
+ def decoratable_method(self, *args, **kwargs):\r
+ return decoratable(self, *args, **kwargs)\r
+\r
+ decoratable_method._decoratable_obj = decoratable\r
+\r
+ def decoratable_decorate(fn, mode, **kwargs):\r
+ decoratable._decorate(fn, mode, **kwargs)\r
+\r
+ decoratable_method._decorate = decoratable_decorate\r
+\r
+ if install:\r
+ setattr(origin.im_class, origin.__name__, decoratable_method)\r
+\r
+ return decoratable_method\r
+ \r
+ elif inspect.isfunction(origin):\r
+ decoratable = DecoratableObject(origin)\r
+\r
+ def decorated(*args, **kwargs):\r
+ return decoratable(*args, **kwargs)\r