Persistent attribute (base class for all units).
Unit classes implement the property hooks introduced in Python 2.2 for
class attributes that intercept operations on instance attributes. This
allows units in an Obj subclass' definition to automatically do type
checking and store attribute values persistently, transparently.
Unit is not really meant to be used as-is (although it can be). It is meant
to be a minimalist base class for other units to inherit (examples of such
classes include Data/String, Text/Unicode, Int, Float, Type, Link and Date)
Important Attributes:
- default
- callable object that returns the value to return if the
unit's data row is empty. The default default value is
None.
Methods
|
|
__delete__
__get__
__init__
__set__
default
validate
|
|
__delete__
|
__delete__ ( self, obj )
Property hook for attribute deletion.
Unit uses its __key__ to delete the correct data row in obj.
|
|
__get__
|
__get__ (
self,
obj,
oftype=None,
)
Property hook for attribute retrieval.
Unit uses its __key__ to access the correct data row from obj.
|
|
__init__
|
__init__ (
self,
*default_value,
*keywords,
)
Constructor
Arguments:
- default_value
- if specified, it is used to build a lambda that
returns it as a default value.
Keyword Arguments:
- default
- expected to be a callable object that returns the
default value for this unit.
- constraint
- a callable object that returns true (1) if the
first argument is a valid value for this field,
false (0) if it isn't.
|
|
__set__
|
__set__ (
self,
obj,
value,
)
Property hook for attribute assignment.
Unit uses its __key__ to store value in the correct data row in obj.
|
|
default
|
default ( self )
Default value to return if the database contains no data in this
unit's row. Return None.
|
|
validate
|
validate ( self, value )
Validate value.
Calls the constraint attribute to make sure this value doesn't
contradict it.
By default this always returns true (1), but it this method can be
overloaded to return false (0) is the value isn't valid for this
type.
Exceptions
|
|
ValueError( "value did not pass the constraint" )
|
|
|