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

Class ElementUse

source code

    object --+        
             |        
       cscRoot --+    
                 |    
ContentState_mixin --+
                     |
    object --+       |
             |       |
       cscRoot --+   |
                 |   |
ContentModel_mixin --+
                     |
                    ElementUse

Aggregate the information relevant to an element of a complex type.

This includes the original tag name, the spelling of the corresponding object in Python, an indicator of whether multiple instances might be associated with the field, and other relevant information.

Instance Methods [hide private]
pyxb.namespace.ExpandedName
name(self)
The expanded name of the element.
source code
 
id(self)
The string name of the binding class field used to hold the element values.
source code
 
elementBinding(self)
The basis.element instance identifying the information associated with the element declaration.
source code
 
_setElementBinding(self, element_binding) source code
 
isPlural(self)
True iff the content model indicates that more than one element can legitimately belong to this use.
source code
 
__init__(self, name, id, key, is_plural, element_binding=None)
Create an ElementUse instance.
source code
 
defaultValue(self)
Return the default value for this element.
source code
 
value(self, ctd_instance)
Return the value for this use within the given instance.
source code
 
reset(self, ctd_instance)
Set the value for this use in the given element to its default.
source code
 
set(self, ctd_instance, value)
Set the value of this element in the given instance.
source code
 
setOrAppend(self, ctd_instance, value)
Invoke either set or append, depending on whether the element use is plural.
source code
 
append(self, ctd_instance, value)
Add the given value as another instance of this element within the binding instance.
source code
 
toDOM(self, dom_support, parent, value)
Convert the given value to DOM as an instance of this element.
source code
 
_description(self, name_only=False, user_documentation=True) source code
 
newState(self, parent_particle_state)
Implement parent class method.
source code
 
accepts(self, particle_state, instance, value, element_use)
Determine whether the provided value can be added to the instance without violating state validation.
source code
 
_accepts(self, instance, value, element_use) source code
 
_validate(self, symbol_set, output_sequence)
Determine whether an output sequence created from the symbols can be made consistent with the model.
source code
 
__str__(self)
str(x)
source code

Inherited from ContentState_mixin: notifyFailure

Inherited from ContentState_mixin (private): _verifyComplete

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Variables [hide private]
  __name = None
hash(x)
  __id = None
hash(x)
  __key = None
hash(x)
  __elementBinding = None
hash(x)
  __isPlural = False
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

id(self)

source code 

The string name of the binding class field used to hold the element values.

This is the user-visible name, and excepting disambiguation will be equal to the local name of the element.

isPlural(self)

source code 

True iff the content model indicates that more than one element can legitimately belong to this use.

This includes elements in particles with maxOccurs greater than one, and when multiple elements with the same NCName are declared in the same type.

__init__(self, name, id, key, is_plural, element_binding=None)
(Constructor)

source code 

Create an ElementUse instance.

Parameters:
  • name (pyxb.namespace.ExpandedName) - The name by which the element is referenced in the XML
  • id (str) - The Python name for the element within the containing pyxb.basis.binding.complexTypeDefinition. This is a public identifier, albeit modified to be unique, and is usually used as the name of the element's inspector method or property.
  • key (str) - The string used to store the element 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.
  • is_plural (bool) - If True, documents for the corresponding type may have multiple instances of this element. As a consequence, the value of the element will be a list. If False, the value will be None if the element is absent, and a reference to an instance of the type identified by pyxb.binding.basis.element.typeDefinition if present.
  • element_binding - Reference to the class that serves as the binding for the element.
Overrides: object.__init__

defaultValue(self)

source code 

Return the default value for this element.

To Do: Right now, this returns None for non-plural and an empty list for plural elements. Need to support schema-specified default values for simple-type content.

append(self, ctd_instance, value)

source code 

Add the given value as another instance of this element within the binding instance.

Raises:

toDOM(self, dom_support, parent, value)

source code 

Convert the given value to DOM as an instance of this element.

Parameters:
  • dom_support (pyxb.utils.domutils.BindingDOMSupport) - Helper for managing DOM properties
  • parent (xml.dom.Element) - The DOM node within which this element should be generated.
  • value - The content for this element. May be text (if the element allows mixed content), or an instance of basis._TypeBinding_mixin.

newState(self, parent_particle_state)

source code 

Implement parent class method.

Parameters:
  • parent_particle_state - The ParticleState instance for which this instance is a term. None for the top content model of a complex data type.
Overrides: ContentModel_mixin.newState

accepts(self, particle_state, instance, value, element_use)

source code 

Determine whether the provided value can be added to the instance without violating state validation.

This method must not throw any non-catastrophic exceptions; general failures should be transformed to a False return value.

Parameters:
  • particle_state - The ParticleState instance serving as the parent to this state. The implementation must inform that state when the proposed value completes the content model.
  • instance - An instance of a subclass of basis.complexTypeDefinition, into which the provided value will be stored if it is consistent with the current model state.
  • value - The value that is being validated against the state.
  • element_use - An optional ElementUse instance that specifies the element to which the value corresponds. This will be available when the value is extracted by parsing a document, but will be absent if the value was passed as a constructor positional parameter.
Returns:
True if the value was successfully matched against the state. False if the value did not match against the state.
Overrides: ContentState_mixin.accepts
(inherited documentation)

_validate(self, symbol_set, output_sequence)

source code 

Determine whether an output sequence created from the symbols can be made consistent with the model.

The symbol set represents letters in an alphabet; the output sequence orders those letters in a way that satisfies the regular expression expressed in the model. Both are changed as a result of a successful validation; both remain unchanged if the validation failed. In recursing, implementers may assume that output_sequence is monotonic: its length remains unchanged after an invocation iff the symbol set also remains unchanged. The _validateCloneSymbolSet, _validateCloneOutputSequence, and _validateReplaceResults methods are available to help preserve this behavior.

Parameters:
  • symbol_set - A map from ElementUse instances to a list of values. The order of the values corresponds to the order in which they should appear. A key of None identifies values that are stored as wildcard elements. Values are removed from the lists as they are used; when the last value of a list is removed, its key is removed from the map. Thus an empty dictionary is the indicator that no more symbols are available.
  • output_sequence - A mutable list to which should be appended tuples ( eu, val ) where eu is an ElementUse from the set of symbol keys, and val is a value from the corresponding list. A document generated by producing the elements in the given order is expected to validate.
Returns:
True iff the model validates. symbol_set and output_path will be unchanged if this returns False.
Overrides: ContentModel_mixin._validate
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)