Package pyxb :: Package binding :: Module content :: Class AttributeUse |
[hide private]
[frames] | no frames]

# type AttributeUse

source code

    object --+
             |
       cscRoot --+
                 |
                AttributeUse

A helper class that encapsulates everything we need to know about the way an attribute is used within a binding class.

Attributes are stored internally as pairs `(provided, value)`, where `provided` is a boolean indicating whether a value for the attribute was provided externally, and `value` is an instance of the attribute datatype. The `provided` flag is used to determine whether an XML attribute should be added to a created DOM node when generating the XML corresponding to a binding instance.

Instance Methods | [hide private]
__init__(self, name, id, key, data_type, unicode_default=None, fixed=False, required=False, prohibited=False) Create an AttributeUse instance. | source code
pyxb.namespace.ExpandedName |
name(self) The expanded name of the element. | source code
defaultValue(self) The default value of the attribute. | source code
fixed(self) `True` iff the value of the attribute cannot be changed. | source code
required(self) `True` iff the attribute must be assigned a value. | source code
prohibited(self) `True` iff the attribute must not be assigned a value. | source code
provided(self, ctd_instance) `True` iff the given instance has been explicitly given a value for the attribute. | source code
id(self) Tag used within Python code for the attribute. | source code
key(self) String used as key within object dictionary when storing attribute value. | source code
dataType(self) The subclass of pyxb.binding.basis.simpleTypeDefinition of which any attribute value must be an instance. | source code
__getValue(self, ctd_instance) Retrieve the value information for this attribute in a binding instance. | source code
__getProvided(self, ctd_instance) | source code
value(self, ctd_instance) Get the value of the attribute from the instance. | source code
__setValue(self, ctd_instance, new_value, provided) | source code
reset(self, ctd_instance) Set the value of the attribute in the given instance to be its default value, and mark that it has not been provided. | source code
addDOMAttribute(self, dom_support, ctd_instance, element) If this attribute as been set, add the corresponding attribute to the DOM element. | source code
validate(self, ctd_instance) Validate the instance against the requirements imposed by this attribute use. | source code
set(self, ctd_instance, new_value, from_xml=False) Set the value of the attribute. | source code
_description(self, name_only=False, user_documentation=True) | source code

Class Variables | [hide private]
| __name = `None` ExpandedName of the attribute
| __id = `None` Identifier used for this attribute within the owning class
| __key = `None` Private Python attribute used in instances to hold the attribute value
| __dataType = `None` The pyxb.binding.basis.simpleTypeDefinition for values of the attribute
| __unicodeDefault = `None` The default attribute value as a unicode string, or `None`
| __defaultValue = `None` The default value as an instance of __dataType, or `None`
| __fixed = `False` `True` if the attribute value cannot be changed
| __required = `False` `True` if the attribute must appear in every instance of the type
| __prohibited = `False` `True` if the attribute must not appear in any instance of the type

Method Details | [hide private]

### __init__(self, name, id, key, data_type, unicode_default=None, fixed=False, required=False, prohibited=False) (Constructor) | source code
Create an AttributeUse instance. Parameters: `name` (pyxb.namespace.ExpandedName) - The name by which the attribute is referenced in the XML `id` (`str`) - The Python identifier for the attribute within the containing pyxb.basis.binding.complexTypeDefinition. This is a public identifier, derived from the local part of the attribute name and modified to be unique, and is usually used as the name of the attribute's inspector method. `key` (`str`) - The string used to store the attribute value in the dictionary of the containing pyxb.basis.binding.complexTypeDefinition. This is mangled so that it is unique among and is treated as a Python private member. `data_type` (`type`) - The class reference to the subclass of pyxb.binding.basis.simpleTypeDefinition of which the attribute values must be instances. `unicode_default` (`unicode`) - The default value of the attribute as specified in the schema, or None if there is no default attribute value. The default value (of the keyword) is `None`. `fixed` (`bool`) - If `True`, indicates that the attribute, if present, must have the value that was given via `unicode_default`. The default value is `False`. `required` (`bool`) - If `True`, indicates that the attribute must appear in the DOM node used to create an instance of the corresponding pyxb.binding.basis.complexTypeDefinition. The default value is `False`. No more that one of required and prohibited should be assigned `True`. `prohibited` (`bool`) - If `True`, indicates that the attribute must not appear in the DOM node used to create an instance of the corresponding pyxb.binding.basis.complexTypeDefinition. The default value is `False`. No more that one of required and prohibited should be assigned `True`. Raises: `pyxb.SimpleTypeValueError` - the `unicode_default` cannot be used to initialize an instance of `data_type` Overrides: cscRoot.__init__

### provided(self, ctd_instance) | source code
`True` iff the given instance has been explicitly given a value for the attribute. This is used for things like only generating an XML attribute assignment when a value was originally given (even if that value happens to be the default).

### id(self) | source code
Tag used within Python code for the attribute. This is not used directly in the default code generation template.

### __getValue(self, ctd_instance) | source code
Retrieve the value information for this attribute in a binding instance. Parameters: `ctd_instance` (subclass of pyxb.binding.basis.complexTypeDefinition) - The instance object from which the attribute is to be retrieved. Returns: `(provided, value)` where `provided` is a `bool` and `value` is `None` or an instance of the attribute's datatype.

### validate(self, ctd_instance) | source code
Validate the instance against the requirements imposed by this attribute use. There is no return value; calls raise an exception if the content does not validate. Parameters: `ctd_instance` - An instance of a complex type definition. Raises: `pyxb.ProhibitedAttributeError` - when instance has attribute but must not `pyxb.MissingAttributeError` - when instance lacks attribute but must have it (including when a required fixed-value attribute is missing). `pyxb.BatchContentValidationError` - when instance has attribute but its value is not acceptable

### set(self, ctd_instance, new_value, from_xml=False) | source code
Set the value of the attribute. This validates the value against the data type, creating a new instance if necessary. Parameters: `ctd_instance` (subclass of pyxb.binding.basis.complexTypeDefinition) - The binding instance for which the attribute value is to be set `new_value` (Any value that is permitted as the input parameter to the `Factory` method of the attribute's datatype.) - The value for the attribute `from_xml` - Value `True` iff the new_value is known to be in lexical space and must by converted by the type factory. If `False` (default) the value is only converted if it is not already an instance of the attribute's underlying type.