Package logilab :: Package common :: Module decorators
[frames] | no frames]

Module decorators

source code

A few useful function/method decorators.

:copyright: 2006-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: General Public License version 2 - http://www.gnu.org/licenses

Classes
  classproperty
this is a simple property-like class but for class attributes.
  iclassmethod
Descriptor for method which should be available as class method if called on the class or instance method if called on an instance.
  wproperty
Simple descriptor expecting to take a modifier function as first argument and looking for a _<function name> to retrieve the attribute.
Functions
 
cached(callableobj, keyarg=None)
Simple decorator to cache result of method call.
source code
 
clear_cache(obj, funcname)
Function to clear a cache handled by the cached decorator.
source code
 
copy_cache(obj, funcname, cacheobj)
Copy cache for <funcname> from cacheobj to obj.
source code
 
locked(acquire, release)
Decorator taking two methods to acquire/release a lock as argument, returning a decorator function which will call the inner method after having called acquire(self) et will call release(self) afterwards.
source code
 
monkeypatch(klass, methodname=None)
Decorator extending class with the decorated function >>> class A: ...
source code
 
timed(f) source code
Variables
  __package__ = 'logilab.common'
Function Details

monkeypatch(klass, methodname=None)

source code 
Decorator extending class with the decorated function
>>> class A:
...     pass
>>> @monkeypatch(A)
... def meth(self):
...     return 12
...
>>> a = A()
>>> a.meth()
12
>>> @monkeypatch(A, 'foo')
... def meth(self):
...     return 12
...
>>> a.foo()
12