bx.cookbook.attribute module
Provides functions for creating simple properties.
If, inside a class definition, you write:
attribute(foo=1, bar=2)
simple properties named ‘foo’ and ‘bar’ are created for this class. Also, private instance variables ‘__foo’ and ‘__bar’ will be added to instances of this class.
USEAGE:
# assumes attribute.py is on path from attribute import *
- class MyClass(object):
readable(foo=1, bar=2) # or, attribute(‘r’, foo=1, bar=2) writable(fro=3, boz=4) # or, attribute(‘w’, fro=3, boz=4) attribute(baz=5)
This is equivalent to the following:
- class MyClass(object):
- def __init__(self):
self.__foo = 1 self.__bar = 2 self.__fro = 3 self.__boz = 4 self.__baz = 5
- def get_foo(self):
return self.__foo
- def get_bar(self):
return self.__bar
- def set_fro(self, value):
self.__fro = value
- def set_boz(self, value):
self.__boz = value
- def get_baz(self):
return self.__baz
- def set_baz(self, value):
self.__baz = value
- def del_baz(self):
del self.__baz
foo = property(fget=get_foo, doc=”foo”) bar = property(fget=get_bar, doc=”bar”) fro = property(fset=set_fro, doc=”fro”) boz = property(fset=set_boz, doc=”boz”) baz = property(fget=get_baz, fset=set_baz, fdel=del_baz, doc=”baz”)
- bx.cookbook.attribute.attribute(permission='rwd', **kwds)
returns one property for each (key,value) pair in kwds; each property provides the specified level of access(permission):
‘r’: readable, ‘w’:writable, ‘d’:deletable
- bx.cookbook.attribute.readable(**kwds)
returns one read-only property for each (key,value) pair in kwds
- bx.cookbook.attribute.writable(**kwds)
returns one write-only property for each (key,value) pair in kwds