summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter A. Bigot <pabigot@users.sourceforge.net>2010-05-29 10:52:44 -0500
committerPeter A. Bigot <pabigot@users.sourceforge.net>2010-05-29 10:52:44 -0500
commitb881b22c15f5e9bf9e0630a31a36ed4c550984de (patch)
tree4996ce6ba7ab1ad8e3b83ad284a1da96967bb8b4
parenta87e2c7bb8eb93c4bbf3b653d815f0af8f6683db (diff)
Rework post-state validation to provide more useful error messages (with context)
-rw-r--r--pyxb/binding/basis.py3
-rw-r--r--pyxb/binding/content.py33
2 files changed, 35 insertions, 1 deletions
diff --git a/pyxb/binding/basis.py b/pyxb/binding/basis.py
index 8ff9795..4b5cf99 100644
--- a/pyxb/binding/basis.py
+++ b/pyxb/binding/basis.py
@@ -2108,7 +2108,8 @@ class complexTypeDefinition (_TypeBinding_mixin, utility._DeconflictSymbols_mixi
"""Initialize the content of this element from the content of the DOM node."""
self.extend(node.childNodes[:], _fallback_namespace)
- self.validateBinding()
+ if self._PerformValidation() and (not self._isNil()) and (self.__stateStack is not None):
+ self.__stateStack.verifyComplete()
return self
def _setDOMFromAttributes (self, dom_support, element):
diff --git a/pyxb/binding/content.py b/pyxb/binding/content.py
index a7482ad..d2870fa 100644
--- a/pyxb/binding/content.py
+++ b/pyxb/binding/content.py
@@ -101,6 +101,23 @@ class ContentState_mixin (pyxb.cscRoot):
"""
raise Exception('ContentState_mixin.notifyFailure not implemented in %s' % (type(self),))
+ def _verifyComplete (self, parent_particle_state):
+ """Determine whether the deep state is complete without further elements.
+
+ No-op for non-aggregate state. For aggregate state, all contained
+ particles should be checked to see whether the overall model can be
+ satisfied if no additional elements are provided. Where appropriate,
+ in this situation the count of the parent particle state should be
+ trivially adjusted to meet its minimum.
+
+ This method does not have a meaningful return value; violations of the
+ content model should produce the corresponding exception (generally,
+ L{MissingContentError}).
+
+ @param parent_particle_state the L{ParticleState} for which this state
+ is the term.
+ """
+ pass
def _validate (self, symbol_set, output_sequence):
raise Exception('ContentState_mixin._validate not implemented in %s' % (type(self),))
@@ -615,6 +632,11 @@ class SequenceState (ContentState_mixin):
raise underflow_exc
return False
+ def _verifyComplete (self, parent_particle_state):
+ while self.__particleState is not None:
+ self.__particleState.verifyComplete()
+ parent_particle_state.incrementToMinimum()
+
def notifyFailure (self, sub_state, particle_ok):
self.__index += 1
self.__particleState = None
@@ -638,6 +660,17 @@ class ParticleState (pyxb.cscRoot):
#print 'PS.IC %s' % (self,)
self.__count += 1
+ def incrementToMinimum (self):
+ if self.__count < self.__particle.minOccurs():
+ self.__count = self.__particle.minOccurs()
+
+ def verifyComplete (self):
+ self.__termState._verifyComplete(self)
+ if not self.__particle.satisfiesOccurrences(self.__count):
+ raise pyxb.MissingContentError('incomplete')
+ if self.__parentState is not None:
+ self.__parentState.notifyFailure(self, True)
+
def step (self, instance, value, element_use):
"""Attempt to apply the value as a new instance of the particle's term.