X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/13bee2f2e6aea2d936909861f3ab60bb09821a60..eb1b2a97a14f9a4daa772709972e0d1650ac4fd3:/forum/modules/decorators.py diff --git a/forum/modules/decorators.py b/forum/modules/decorators.py index 3c53412..11af9e3 100644 --- a/forum/modules/decorators.py +++ b/forum/modules/decorators.py @@ -69,7 +69,7 @@ class ReturnImediatelyException(Exception): self.ret = ret def _check_decoratable(origin, install=True): - if not isinstance(origin, DecoratableObject): + if not hasattr(origin, '_decoratable_obj'): if inspect.ismethod(origin) and not hasattr(origin, '_decoratable_obj'): decoratable = DecoratableObject(origin) @@ -91,10 +91,18 @@ def _check_decoratable(origin, install=True): elif inspect.isfunction(origin): decoratable = DecoratableObject(origin) + def decorated(*args, **kwargs): + return decoratable(*args, **kwargs) + + decorated._decoratable_obj = decoratable + if install: - setattr(inspect.getmodule(origin), origin.__name__, decoratable) + setattr(inspect.getmodule(origin), origin.__name__, decorated) + + decorated.__name__ = origin.__name__ + decorated.__module__ = origin.__module__ - return decoratable + return decorated return origin @@ -103,7 +111,7 @@ def decorate(origin, needs_origin=True): origin = _check_decoratable(origin) def decorator(fn): - origin._decorate(fn, DecoratableObject.MODE_OVERRIDE, needs_origin=needs_origin) + origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_OVERRIDE, needs_origin=needs_origin) return decorator @@ -112,7 +120,7 @@ def _decorate_params(origin): origin = _check_decoratable(origin) def decorator(fn): - origin._decorate(fn, DecoratableObject.MODE_PARAMS) + origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_PARAMS) return decorator @@ -122,7 +130,7 @@ def _decorate_result(origin, needs_params=False): origin = _check_decoratable(origin) def decorator(fn): - origin._decorate(fn, DecoratableObject.MODE_RESULT, needs_params=needs_params) + origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_RESULT, needs_params=needs_params) return decorator @@ -131,7 +139,7 @@ decorate.result = _decorate_result def _decorate_with(fn): def decorator(origin): origin = _check_decoratable(origin) - origin._decorate(fn, DecoratableObject.MODE_OVERRIDE, needs_origin=True) + origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_OVERRIDE, needs_origin=True) return origin return decorator @@ -140,7 +148,7 @@ decorate.withfn = _decorate_with def _decorate_result_with(fn, needs_params=False): def decorator(origin): origin = _check_decoratable(origin) - origin._decorate(fn, DecoratableObject.MODE_RESULT, needs_params=needs_params) + origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_RESULT, needs_params=needs_params) return origin return decorator @@ -149,7 +157,7 @@ decorate.result.withfn = _decorate_result_with def _decorate_params_with(fn): def decorator(origin): origin = _check_decoratable(origin) - origin._decorate(fn, DecoratableObject.MODE_PARAMS) + origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_PARAMS) return origin return decorator