Hold a value which can be changed as long as it has not been examined
An EigenCell is used to hold a configuration value that should not be
changed once it is used. The value may be set() or unset() at will
as long as the exists() or get() methods have not been called. As
soon as the cell's value has been read or tested for existence, the value
is locked and an AlreadyRead exception will be thrown if you attempt to
set() or unset() the value after that point. (Note: unset() is a
no-op if the value is empty, whether the cell is locked or not, because
it does not change the value's nonexistence.)
Methods
|
|
__init__
exists
get
set
unset
|
|
__init__
|
__init__ ( self )
Create an (empty and unread) EigenCell
|
|
exists
|
exists ( self )
Return true if the cell contains a value.
|
|
get
|
get ( self, setdefault=None )
Return the cell's value, or raise AttributeError if empty
A function may be supplied to set a default value, if the cell has not
yet been read and no value is currently assigned. The return value
of the function will be used. For example:
aCell.get(lambda: someObj())
will set the value of aCell to someObj() if aCell has not been
read and has no value currently assigned. Notice that you must pass
a function, not a value. The simplest way to do this is with lambda
as shown above.
|
|
set
|
set ( self, value )
Set the cell's value, or raise AlreadyRead
|
|
unset
|
unset ( self )
Remove the cell's value (reset to non-existence)
|
|