<s> '''<STR_LIT>''' <EOL> from lxml import etree <EOL> from arelle . ModelDtsObject import ( ModelConcept , ModelType , ModelGroupDefinition , <EOL> ModelAll , ModelChoice , ModelSequence , <EOL> ModelAny , anonymousTypeSuffix ) <EOL> from arelle . ModelObject import ModelObject , ModelAttribute <EOL> from arelle . XmlValidate import validate <EOL> def validateElementSequence ( modelXbrl , compositor , children , ixFacts , iNextChild = <NUM_LIT:0> ) : <EOL> particles = compositor . dereference ( ) . particles <EOL> iStartingChild = iNextChild <EOL> errDesc = None <EOL> if isinstance ( compositor , ModelAll ) : <EOL> allParticles = set ( ) <EOL> iNextAfterAll = iStartingChild <EOL> elif isinstance ( compositor , ModelChoice ) : <EOL> anyChoiceHasMinOccurs0 = False <EOL> moreParticlesPasses = True <EOL> while moreParticlesPasses : <EOL> moreParticlesPasses = False <EOL> for particle in particles : <EOL> occurrences = <NUM_LIT:0> <EOL> if isinstance ( particle , ( ModelConcept , ModelAny ) ) : <EOL> elementDeclaration = particle . dereference ( ) <EOL> while iNextChild < len ( children ) : <EOL> elt = children [ iNextChild ] <EOL> vQname = elt . vQname ( modelXbrl ) <EOL> if ( ( isinstance ( particle , ModelAny ) and <EOL> particle . allowsNamespace ( vQname . namespaceURI ) ) or <EOL> ( isinstance ( particle , ModelConcept ) and <EOL> elementDeclaration is not None and <EOL> ( vQname == elementDeclaration . qname or <EOL> ( vQname in modelXbrl . qnameConcepts and <EOL> modelXbrl . qnameConcepts [ vQname ] . substitutesForQname ( elementDeclaration . qname ) ) ) ) ) : <EOL> occurrences += <NUM_LIT:1> <EOL> validate ( modelXbrl , elt , ixFacts = ixFacts ) <EOL> iNextChild += <NUM_LIT:1> <EOL> if occurrences == particle . maxOccurs : <EOL> break <EOL> elif not isinstance ( particle , ModelAll ) : <EOL> break <EOL> else : <EOL> while occurrences < particle . maxOccurs : <EOL> iPrevChild = iNextChild <EOL> iNextChild , occurred , errDesc , errArgs = validateElementSequence ( modelXbrl , particle , children , ixFacts , iNextChild ) <EOL> if occurred : <EOL> if occurred and iNextChild == iPrevChild and particle . minOccurs == <NUM_LIT:0> : <EOL> break <EOL> occurrences += <NUM_LIT:1> <EOL> if occurrences == particle . maxOccurs or iNextChild >= len ( children ) : <EOL> break <EOL> else : <EOL> break <EOL> if isinstance ( compositor , ModelChoice ) : <EOL> if occurrences > <NUM_LIT:0> and particle . minOccurs <= occurrences <= particle . maxOccurs : <EOL> return ( iNextChild , True , None , None ) <EOL> else : <EOL> if particle . minOccurs == <NUM_LIT:0> : <EOL> anyChoiceHasMinOccurs0 = True <EOL> iNextChild = iStartingChild <EOL> elif isinstance ( compositor , ModelAll ) : <EOL> if particle . minOccurs <= occurrences <= particle . maxOccurs : <EOL> allParticles . add ( particle ) <EOL> moreParticlesPasses = True <EOL> break <EOL> elif particle . minOccurs > <NUM_LIT:0> and errDesc : <EOL> return ( iNextChild , False , errDesc , errArgs ) <EOL> elif not particle . minOccurs <= occurrences <= particle . maxOccurs : <EOL> return ( iNextChild , False , <EOL> ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) <EOL> if occurrences > <NUM_LIT:0> else <EOL> _ ( "<STR_LIT>" ) <EOL> ) , <EOL> dict ( compositor = compositor , particles = particles , occurrences = occurrences , minOccurs = particle . minOccursStr , maxOccurs = particle . maxOccursStr ) ) <EOL> if isinstance ( compositor , ModelAll ) : <EOL> missingParticles = set ( particles ) - allParticles <EOL> if missingParticles : <EOL> return ( iNextChild , False , <EOL> ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) ) , <EOL> dict ( particles = particles ) ) <EOL> occurred = True <EOL> elif isinstance ( compositor , ModelChoice ) : <EOL> occurred = anyChoiceHasMinOccurs0 <EOL> else : <EOL> occurred = True <EOL> if isinstance ( compositor , ModelType ) and iNextChild < len ( children ) : <EOL> if len ( children ) > iNextChild : <EOL> return ( iNextChild , False , <EOL> ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) ) , <EOL> dict ( compositor = compositor , particles = particles ) ) <EOL> return ( iNextChild , occurred , None , None ) <EOL> def modelGroupCompositorTitle ( compositor ) : <EOL> if isinstance ( compositor , ModelType ) : <EOL> return str ( compositor . qname ) . replace ( anonymousTypeSuffix , "<STR_LIT>" ) <EOL> return compositor . localName . title ( ) <EOL> def validateUniqueParticleAttribution ( modelXbrl , particles , compositor ) : <EOL> priorElementParticles = { } <EOL> priorAnyParticles = [ ] <EOL> for i , particle in enumerate ( particles ) : <EOL> if isinstance ( particle , ModelConcept ) : <EOL> elementDeclaration = particle . dereference ( ) <EOL> if elementDeclaration is not None : <EOL> qname = elementDeclaration . qname <EOL> if qname in priorElementParticles : <EOL> separatingTransitions = <NUM_LIT:0> <EOL> if not isinstance ( compositor , ( ModelChoice , ModelAll ) ) : <EOL> for j in range ( i , priorElementParticles [ qname ] , - <NUM_LIT:1> ) : <EOL> separatingTransitions += particles [ j - <NUM_LIT:1> ] . minOccurs <EOL> if separatingTransitions : <EOL> break <EOL> if not separatingTransitions : <EOL> modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = particle , compositor = compositor . localName , element = qname ) <EOL> else : <EOL> for priorAnyIndex in priorAnyParticles : <EOL> separatingTransitions = <NUM_LIT:0> <EOL> if not isinstance ( compositor , ( ModelChoice , ModelAll ) ) : <EOL> for j in range ( i , priorAnyIndex , - <NUM_LIT:1> ) : <EOL> separatingTransitions += particles [ j - <NUM_LIT:1> ] . minOccurs <EOL> if separatingTransitions : <EOL> break <EOL> if not separatingTransitions : <EOL> modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = particle , compositor = compositor . localName , element = qname ) <EOL> priorElementParticles [ qname ] = i <EOL> elif isinstance ( particle , ModelAny ) : <EOL> if i > <NUM_LIT:0> and particles [ i - <NUM_LIT:1> ] . minOccurs == <NUM_LIT:0> : <EOL> modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = particle , compositor = compositor . localName ) <EOL> priorAnyParticles . insert ( <NUM_LIT:0> , i ) <EOL> else : <EOL> particleDeclaration = particle . dereference ( ) <EOL> if particleDeclaration is not None : <EOL> validateUniqueParticleAttribution ( modelXbrl , particleDeclaration . particles , particle ) </s>
