gavo.base.complexattrs module¶
Attributes with structure (i.e., containing structures or more than one atom).
These come with parsers of their own, in some way or other.
Structure attributes, which do not have string literals and have some sort of internal structure, add methods
- create(instance, ctx, name) -> structure – creates a new object suitable
as attribute value and returns it (for structures, instance becomes the parent of the new structure as a side effect of this operation). This is what should later be fed to feedObject. It must work as a parser, i.e., have a feedEvent method. The name argument gives the name of the element that caused the create call, allowing for polymorphic attrs.
- replace(instance, oldVal, newVal) -> None – replaces oldVal with newVal; this
works like feedObject, except that an old value is overwritten.
- iterEvents(instance) -> events – yields events to recreate its value
on another instance.
- class gavo.base.complexattrs.DictAttribute(name, description='Undocumented', itemAttD=<gavo.base.attrdef.UnicodeAttribute object>, keyName='key', inverted=False, expandMacros=False, **kwargs)[source]¶
Bases:
AttributeDef
an attribute containing a mapping.
DictAttributes are fairly complex beasts supporting a number of input forms.
The input to those looks like <d key=”foo”>abc</d>; they are constructed with an itemAttD (like StructAttributes), but the name on those is ignored; they are just used for parsing from the strings in the element bodies, which means that itemAttDs must be derived from AtomicAttribute.
You can give a different keyNames; the key attribute is always accepted, though.
For sufficiently exotic situations, you can construct DictAttributes with inverted=True; the resulting dictionary will then have the keys as values and vice versa (this is a doubtful feature; let us know when you use it).
You can also add to existing values using the cumulate XML attribute; <d key=”s”>a</d><d key=”s” cumulate=”True”>bc</a> will leave abc in s.
- property default_¶
- property typeDesc_¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- class gavo.base.complexattrs.ListOfAtomsAttribute(name, default=[], itemAttD=<gavo.base.attrdef.UnicodeAttribute object>, **kwargs)[source]¶
Bases:
CollOfAtomsAttribute
is an attribute definition for an item containing many elements of the same type.
It is constructed with an AttributeDef for the items. Note that it’s safe to pass in lists as defaults since they are copied before being added to the instances, so you won’t (and can’t) have aliasing here.
- property default_¶
- property typeDesc_¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- class gavo.base.complexattrs.MultiStructAttribute(name, childFactory, childNames, **kwargs)[source]¶
Bases:
StructAttribute
describes an attribute containing one of a class of Structures.
This is to support things like grammars or cores – these can be of many types.
This works like StructAttribute, except that childFactory now is a function returning elements (i.e., it’s a childFactoryFactory).
- property typeDesc_¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- class gavo.base.complexattrs.MultiStructListAttribute(name, childFactory, childNames, **kwargs)[source]¶
Bases:
StructListAttribute
,MultiStructAttribute
describes a list of polymorphous children.
See rscdesc cores as to why one could want this; the arguments are as for MultiStructAttribute.
- property typeDesc_¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- class gavo.base.complexattrs.PropertyAttribute(description='Properties (i.e., user-defined key-value pairs) for the element.', **kwargs)[source]¶
Bases:
DictAttribute
adds the property protocol to the parent instance.
The property protocol consists of the methods - setProperty(name, value), - getProperty(name, default=Undefined) - clearProperty(name) - hasProperty(name)
getProperty works like dict.get, except it will raise a KeyError without a default.
This is provided for user information and, to some extent, some DC-internal purposes.
- class gavo.base.complexattrs.SetOfAtomsAttribute(name, default=[], itemAttD=<gavo.base.attrdef.UnicodeAttribute object>, **kwargs)[source]¶
Bases:
CollOfAtomsAttribute
is an attribute definition for an item containing many elements of the same type, when order doesn’t matter but lookup times do.
It is constructed with an AttributeDef for the items. Note that it’s safe to pass in lists as defaults since they are copied before being added to the instances, so you won’t (and can’t) have aliasing here.
- property default_¶
- property typeDesc_¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- class gavo.base.complexattrs.StructAttribute(name, childFactory, default=<Undefined>, description='Undocumented', **kwargs)[source]¶
Bases:
AttributeDef
describes an attribute containing a Structure
These are constructed with a childFactory that must have a feedEvent method. Otherwise, they are normal structs, i.e., the receive a parent as the first argument and keyword arguments for values.
In addition, you can pass a onParentComplete callback that are collected in the completedCallback list by the struct decorator. ParseableStruct instances call these when they receive their end event during XML deserialization.
- property typeDesc_¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- class gavo.base.complexattrs.StructListAttribute(name, childFactory, description='Undocumented', **kwargs)[source]¶
Bases:
StructAttribute
describes an attribute containing a homogeneous list of structures.
- addStruct(instance, value, destIndex=None)[source]¶
adds a structure to the attribute’s value.
Do not directly add to the list, always go through this method; derived classes override it for special behaviour. Also, this is where callbacks are called.
Use destIndex to overwrite an (existing!) struct; default is appending.
- property default_¶
- property typeDesc_¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- class gavo.base.complexattrs.UniquedStructListAttribute(name, childFactory, uniqueAttribute, policy='overwrite', **kwargs)[source]¶
Bases:
StructListAttribute
A StructListAttribute that will only admit one child per value of uniqueAttribute, overwriting existing entries if existing.
Actually, you can pass a policy=”drop” argument to just keep an existing element and drop the new one.
- addStruct(instance, value)[source]¶
adds a structure to the attribute’s value.
Do not directly add to the list, always go through this method; derived classes override it for special behaviour. Also, this is where callbacks are called.
Use destIndex to overwrite an (existing!) struct; default is appending.
- property typeDesc_¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.