The zaqar.common.decorators module

class TransportLog(resource_type)

Bases: object

Standard logging for transport driver responders

This class implements a logging decorator that the transport driver responders can use for standard logging

api_version_manager(version_info)

Manage API versions based on their status

This decorator disables DEPRECATED APIs by default unless the user explicitly enables it by adding it to the enable_deprecated_api_versions configuration option.

Parameters:version_info – Dictionary containing the API version info.
caches(keygen, ttl, cond=None)

Flags a getter method as being cached using oslo_cache.

It is assumed that the containing class defines an attribute named _cache that is an instance of an oslo_cache backend.

The getter should raise an exception if the value can’t be loaded, which will skip the caching step. Otherwise, the getter must return a value that can be encoded with msgpack.

Note that you can also flag a remover method such that it will purge an associated item from the cache, e.g.:

def project_cache_key(user, project=None):
    return user + ':' + str(project)

class Project(object):
    def __init__(self, db, cache):
        self._db = db
        self._cache = cache

    @decorators.caches(project_cache_key, 60)
    def get_project(self, user, project=None):
        return self._db.get_project(user, project)

    @get_project.purges
    def del_project(self, user, project=None):
        self._db.delete_project(user, project)
Parameters:
  • keygen – A static key generator function. This function must accept the same arguments as the getter, sans self.
  • ttl – TTL for the cache entry, in seconds.
  • cond – Conditional for whether or not to cache the value. Must be a function that takes a single value, and returns True or False.
lazy_property(write=False, delete=True)

Creates a lazy property.

Parameters:
  • write – Whether this property is “writable”
  • delete – Whether this property can be deleted.
memoized_getattr(meth)

Memoizes attributes returned by __getattr__

It can be used to remember the results from __getattr__ and reduce the debt of calling it again when the same attribute is accessed.

This decorator memoizes attributes by setting them on the object itself.

The wrapper returned by this decorator won’t alter the returned value.

Returns:A wrapper around the decorated method.