Package gavo :: Package base :: Module attrdef
[frames] | no frames]

Module attrdef

source code

Attribute definitions for structures.

These are objects having at least the following attributes and methods:

They may have an attribute xmlName that allows parsing from xml elements named differently from the attribute. To keep things transparent, use this sparingly; the classic use case is with lists, where you can call an attribute options but have the XML element still be just "option".

AtomicAttributes, defined as those that are parsed from a unicode literal, add methods

This is not enough for complex attributes. More on those in the base.complexattrs module.

AttributeDefs *may* have a validate(instance) method. Structure instances will call them when they are done building. They should raise LiteralParseErrors if it turns out a value that looked right is not after all (in a way, they could catch validity rather than well-formedness violations, but I don't think this distinction is necessary here).

See structure on how to use all these.

Classes
  Undefined
a sentinel for all kinds of undefined values.
  LiteralParseError
is raised if an attribute literal is somehow bad.
  NotGiven
A sentinel class for defaultless values that can remain undefined.
  Computed
A sentinel class for computed (property) defaults.
  AttributeDef
is the base class for all attribute definitions.
  AtomicAttribute
A base class for attributes than can be immediately parsed and unparsed from strings.
  RawAttribute
An attribute definition that does no parsing at all.
  UnicodeAttribute
An attribute definition for an item containing a unicode string.
  NWUnicodeAttribute
A UnicodeAttribute that has its whitespace normalized.
  RelativePathAttribute
A (utf-8 encoded) path relative to some base path.
  FunctionRelativePathAttribute
A (utf-8 encoded) path relative to the result of some function at runtime.
  EnumeratedUnicodeAttribute
An attribute definition for an item that can only take on one of a finite set of values.
  IntAttribute
An attribute definition for integer attributes.
  FloatAttribute
An attribute definition for floating point attributes.
  BooleanAttribute
A boolean attribute.
  StringListAttribute
An attribute containing a list of comma separated strings.
  StringSetAttribute
A StringListAttribute, except the result is a set.
  IdMapAttribute
An attribute allowing a quick specification of identifiers to identifiers.
  ActionAttribute
An attribute definition for attributes triggering a method call on the parent instance.