Part of bzrlib
| Function | only_raises | Make a decorator that will only allow the given error classes to be |
| Function | use_fast_decorators | Change the default decorators to be fast loading ones. |
| Function | use_pretty_decorators | Change the default decorators to be pretty ones. |
| Function | cachedproperty | A decorator for methods that makes them properties with their return |
| Function | _get_parameters | Recreate the parameters for a function using introspection. |
| Function | _pretty_needs_read_lock | Decorate unbound to take out and release a read lock. |
| Function | _fast_needs_read_lock | Decorate unbound to take out and release a read lock. |
| Function | _pretty_needs_write_lock | Decorate unbound to take out and release a write lock. |
| Function | _fast_needs_write_lock | Decorate unbound to take out and release a write lock. |
| Class | _CachedPropertyForAttr | Undocumented |
| Class | _CachedProperty | Undocumented |
Recreate the parameters for a function using introspection.
:return: (function_params, calling_params, default_values)
function_params: is a string representing the parameters of the
function. (such as "a, b, c=None, d=1")
This is used in the function declaration.
calling_params: is another string representing how you would call the
function with the correct parameters. (such as "a, b, c=c, d=d")
Assuming you used function_params in the function declaration, this
is the parameters to put in the function call.
default_values_block: a dict with the default values to be passed as
the scope for the 'exec' statement.
For example:
def wrapper(%(function_params)s):
return original(%(calling_params)s)
Decorate unbound to take out and release a read lock.
This decorator can be applied to methods of any class with lock_read() and
unlock() methods.
Typical usage:
class Branch(...):
@needs_read_lock
def branch_method(self, ...):
stuff
Decorate unbound to take out and release a read lock.
This decorator can be applied to methods of any class with lock_read() and
unlock() methods.
Typical usage:
class Branch(...):
@needs_read_lock
def branch_method(self, ...):
stuff
Make a decorator that will only allow the given error classes to be raised. All other errors will be logged and then discarded.
Typical use is something like:
@only_raises(LockNotHeld, LockBroken)
def unlock(self):
# etc
The alternative is to have decorators that do more work to produce nice-looking decorated functions, but this slows startup time.
A decorator for methods that makes them properties with their return value cached.
The value is cached on the instance, using the attribute name provided.
If you don't provide a name, the mangled name of the property is used.
>>> class CachedPropertyTest(object): ... ... @cachedproperty('_foo_cache') ... def foo(self): ... print 'foo computed' ... return 23 ... ... @cachedproperty ... def bar(self): ... print 'bar computed' ... return 69
>>> cpt = CachedPropertyTest() >>> getattr(cpt, '_foo_cache', None) is None True >>> cpt.foo foo computed 23 >>> cpt.foo 23 >>> cpt._foo_cache 23 >>> cpt.bar bar computed 69 >>> cpt._bar_cached_value 69