hup.base.attrib module

Attributes and Attribute Groups.

class Attribute(fget: Union[Callable, str, None] = None, fset: Union[Callable, str, None] = None, fdel: Union[Callable, str, None] = None, doc: Optional[str] = None, dtype: Union[Type[Any], Tuple[Type[Any], ...], None] = None, readonly: bool = False, default: Any = None, factory: Union[Callable, str, None] = None, binddict: Optional[str] = None, bindkey: Optional[str] = None, remote: bool = False, inherit: bool = False, category: Optional[str] = None)

Bases: property, hup.base.abc.Isolated

Extended data descriptor for Attributes.

Data descriptors are classes, used for binding attributes to fields and thereby provide an abstraction layer that facilitates encapsulation and modularity. When any class contains a data descriptor as a class attribute (i.e. a method), then the data descriptor class defines the accessor, mutator and manager methods of the respective attribute.

A succinct way of building data descriptors is given by the property class, which automatically creates an accessor, a mutator and a destructor method from it’s passed arguments. The Attribute class extends this automation by additional options for managing and controlling the behaviour of the attribute:

  • Declaration of accessor, mutator and destructor methods by forward references
  • Automatic type checking against given data type(s)
  • Restriction to read-only attributes
  • Setting of default values, ether as a fixed value, a factory function or by inheritance from a parental object
  • Binding to arbitrary mappings, to allow a namespace aggregation of the attributes data e.g. by their logical attribute type.
  • Binding to arbitrary keys, e.g. to provide different accessors to identical attribute data
  • Handling of remote attributes of a parent object, to allow sharing of attributes between different objects
  • Locical aggregation of attributes by categories
Parameters:
  • fget – Accessor method of the attribute. If provided, it must be a callable or a string, that references a valid method of the owner instance.
  • fset – Mutator method of the attribute. If provided, it must be a callable or a string, that references a valid method of the owner instance.
  • fdel – Destructor method of the attribute. If provided, it must be a callable or a string, that references a valid method of the owner instance.
  • doc – Docstring of the attribute, which is retained throughout the runtime of the application. For more information and doctring convention see PEP 257.
  • dtype – Data type definition of the attribute given as a type or a tuple of types, which is used for type checking assignments to the attribute. If the value passed to the mutator method is not an instance of any of the given types, a InvalidTypeError is raised. By default type checking is disabled.
  • default – Default value, which is returned by calling the getter method, if the following conditions are met: (1) The attribute is not a remote attribute of the parent, (2) the attribute is not inherited from the parent, (3) the attribute has not yet been set, (4) the attribute has no default factory.
  • factory – Default method, which is called if a default value is required. If provided, it must be a callable or a string, that references a valid method of the owner instance. This method is called, if the following conditions are met: (1) The attribute is not a remote attribute of the parent, (2) the attribute is not inherited from the parent, (3) the attribute has not yet been set.
  • binddict – Name of the dictionary (or arbitrary mapping), which comprises the key, which is used to store the attribute data. If provided, it must be a string, that references an attribute of the owner instance, with type mapping. By default, the special attribute __dict__ is used.
  • bindkey – Name of key within the bound dictionary, which is used to store the attribute data. By default the name of the attribute is used.
  • remote – Boolean value which determines, if the accessor, mutator and destructor methods are bypassed to the currently referenced parent attribute group. If no attribute group is referenced or the referenced attribute group, does not contain an attribute of the same name, a ReferenceError is raised on any request to the Attribute.
  • inherit – Boolean value which determines if the default value is inherited from the (current) value of a referenced parent object. If no parent object is referenced or the referenced object, does not contain an attribute of the same name, then the default value is retrieved from the default factory, or if not given, from the default value. By default the default value is not inherited from the parent.
  • readonly – Boolean value which determines, if the attribute is a read-only attribute. For read-only attributes the mutator method raises an AttributeError on requests to the mutator method. By default the attribute is read-writable.
  • category – Optional name of category, which allows a logical aggregation of attributes. If given, that category has to be a string. By default not category is set.
class Content(*args, **kwds)

Bases: hup.base.attrib.Attribute

Attributes for persistent content storage objects.

class Group(parent: Optional[Group] = None, readonly: Optional[bool] = None, remote: Optional[bool] = None, inherit: Optional[bool] = None, content: Optional[Dict[str, Any]] = None, metadata: Optional[Dict[str, Any]] = None)

Bases: hup.base.abc.Isolated

Class for Attribute Groups.

Attribute Groups are used to bind attributes (and other attribute groups) into tree structured objects with a hierarchical control interface. This includes a common interface to access and mutate the values of it’s contained (sub)attributes as well as a common interface to superseed the settings of it’s contained (sub)groups to control the group behaviour in different applications.

Parameters:
  • parent – Reference to logical parent :class:’attribute group <.attrib.Group>’, which is used for inheritance and shared attributes. By default no parent is referenced. Note: The logical parent does not denote the attribute group, that contains this group, but an equally structured attribute, which is used to infere dynamical values for the attributes.
  • readonly – Boolean value, which superseeds the contained attributes read-only behaviour. For the values True or False, all contained attributes respectively are read-only or read-writable. By the default value None, the attributes’ settings are not superseeded.
  • remote – Boolean value, which superseeds the contained attributes remote behaviour. For the value True, all contained attributes are shared attributes of the parent attribute group, which must be referenced and contain the respetive attributes, or an error is raised. For the value False, all contained atributes are handled locally, regardless of a parent group. By the default value None, the attributes’ settings are not superseeded.
  • inherit – Boolean value, which superseeds the contained attributes inheritance behaviour. For the value True, all contained attributes inherit their default values from the attribute values of the parent attribute group, which must be referenced and contain the respetive attributes, or an error is raised. For the value False, the default values of the contained atributes are handled locally, regardless of a parent group. By the default value None, the attributes settings are not superseeded.
  • content
  • metadata
class MetaData(*args, **kwds)

Bases: hup.base.attrib.Attribute

Attributes for persistent metadata storage objects.

class Temporary(*args, **kwds)

Bases: hup.base.attrib.Attribute

Attributes for non persistent storage objects.

class Virtual(*args, **kwds)

Bases: hup.base.attrib.Attribute

Attributes for non persistent virtual objects.