Module k.accessor

Part of kiwi

The accessor module offers two important front-end functions: kgetattr and ksetattr. These functions allow retrieving attribute values from objects much in the same way as getattr/setattr allow, but with two important differences:

Functionget_default_getter

Obtains from model a callable through which attr_name can be

Functionget_default_setter

Obtains from model a callable through which attr_name can be

ClassCacheControlUndocumented
Class_AttrUnsetUndocumented
ClassDefaultValue

This can be raised in kgetattr accessors to indicate that the default

Functionkgetattr_guardUndocumented
Functionksetattr_guardUndocumented
Functionkgetattr

Returns the value associated with the attribute in model

Functionksetattr

Set the value associated with the attribute in model

Functionenable_attr_cache

Enables the use of the kgetattr cache when using Python

Functionclear_attr_cache

Clears the kgetattr cache. It must be called repeatedly to

def get_default_getter(model, attr_name, cache):

Obtains from model a callable through which attr_name can be retrieved. This callable is an accessor named get_foo, where foo is the value of attr_name, or getattr(model, foo) if the accessor does not exist. If the callable exists, it is returned; if getattr() is to be used a tuple in the format (model, attr_name) is returned.

def get_default_setter(model, attr_name, cache):

Obtains from model a callable through which attr_name can be set. This callable is an accessor named set_foo, where foo is the value of attr_name, or setattr(model, foo, value) if the accessor does not exist. If the callable exists, it is returned; if setattr() is to be used a tuple in the format (model, attr_name) is returned.

def kgetattr_guard(wref):
Undocumented
def ksetattr_guard(wref):
Undocumented
def kgetattr(model, attr_name, default=_AttrUnset, flat=0, ref=weakref.ref, TupleType=types.TupleType, MethodType=types.MethodType, split=string.split, kgetattr_guard=kgetattr_guard, getattr=getattr, dummycache=CacheControl((None, None)), LAMBDA_ACCESS=0, METHOD_ACCESS=1, TUPLE_ACCESS=2, NWR_METHOD_ACCESS=3, NWR_TUPLE_ACCESS=4, FAST_METHOD_ACCESS=5, FAST_TUPLE_ACCESS=6):

Returns the value associated with the attribute in model named by attr_name. If default is provided and model does not have an attribute called attr_name, the default value is returned. If flat=1 is specified, no dot path parsing will be done.

def ksetattr(model, attr_name, value, flat=0, ref=weakref.ref, TupleType=types.TupleType, MethodType=types.MethodType, ksetattr_guard=ksetattr_guard, getattr=getattr, dummycache=CacheControl((None, None)), LAMBDA_ACCESS=0, METHOD_ACCESS=1, TUPLE_ACCESS=2, NWR_METHOD_ACCESS=3, NWR_TUPLE_ACCESS=4, FAST_METHOD_ACCESS=5, FAST_TUPLE_ACCESS=6):

Set the value associated with the attribute in model named by attr_name. If flat=1 is specified, no dot path parsing will be done.

def enable_attr_cache():

Enables the use of the kgetattr cache when using Python versions that do not support weakrefs (1.5.x and earlier). Be warned, using the cache in these versions causes leaked references to accessor methods and models!

def clear_attr_cache():

Clears the kgetattr cache. It must be called repeatedly to avoid memory leaks in Python 2.0 and earlier.