<s> '''<STR_LIT>''' <EOL> import os , io , sys , json <EOL> from collections import defaultdict <EOL> from arelle import XbrlConst <EOL> from arelle . ModelObject import ModelObject <EOL> from arelle . ModelValue import QName <EOL> from arelle . ModelFormulaObject import Aspect <EOL> from arelle . ModelRenderingObject import ( ModelEuTable , ModelTable , ModelBreakdown , <EOL> ModelEuAxisCoord , ModelDefinitionNode , ModelClosedDefinitionNode , ModelRuleDefinitionNode , <EOL> ModelRelationshipDefinitionNode , ModelSelectionDefinitionNode , ModelFilterDefinitionNode , <EOL> ModelConceptRelationshipDefinitionNode , ModelDimensionRelationshipDefinitionNode , <EOL> ModelCompositionDefinitionNode , ModelTupleDefinitionNode , StructuralNode , <EOL> ROLLUP_NOT_ANALYZED , CHILDREN_BUT_NO_ROLLUP , CHILD_ROLLUP_FIRST , CHILD_ROLLUP_LAST , <EOL> OPEN_ASPECT_ENTRY_SURROGATE ) <EOL> from arelle . PrototypeInstanceObject import FactPrototype <EOL> RENDER_UNITS_PER_CHAR = <NUM_LIT:16> <EOL> class ResolutionException ( Exception ) : <EOL> def __init__ ( self , code , message , ** kwargs ) : <EOL> self . kwargs = kwargs <EOL> self . code = code <EOL> self . message = message <EOL> self . args = ( self . __repr__ ( ) , ) <EOL> def __repr__ ( self ) : <EOL> return _ ( '<STR_LIT>' ) . format ( self . code , self . message % self . kwargs ) <EOL> def resolveAxesStructure ( view , viewTblELR ) : <EOL> if isinstance ( viewTblELR , ( ModelEuTable , ModelTable ) ) : <EOL> table = viewTblELR <EOL> for rel in view . modelXbrl . relationshipSet ( ( XbrlConst . tableBreakdown , XbrlConst . tableBreakdownMMDD , XbrlConst . tableBreakdown201305 , XbrlConst . tableBreakdown201301 , XbrlConst . tableAxis2011 ) ) . fromModelObject ( table ) : <EOL> view . axisSubtreeRelSet = view . modelXbrl . relationshipSet ( ( XbrlConst . tableBreakdownTree , XbrlConst . tableBreakdownTreeMMDD , XbrlConst . tableBreakdownTree201305 , XbrlConst . tableDefinitionNodeSubtree , XbrlConst . tableDefinitionNodeSubtreeMMDD , XbrlConst . tableDefinitionNodeSubtree201305 , XbrlConst . tableDefinitionNodeSubtree201301 , XbrlConst . tableAxisSubtree2011 ) , rel . linkrole ) <EOL> return resolveTableAxesStructure ( view , table , <EOL> view . modelXbrl . relationshipSet ( ( XbrlConst . tableBreakdown , XbrlConst . tableBreakdownMMDD , XbrlConst . tableBreakdown201305 , XbrlConst . tableBreakdown201301 , XbrlConst . tableAxis2011 ) , rel . linkrole ) ) <EOL> return ( None , None , None , None ) <EOL> tblAxisRelSet = view . modelXbrl . relationshipSet ( XbrlConst . euTableAxis , viewTblELR ) <EOL> if len ( tblAxisRelSet . modelRelationships ) > <NUM_LIT:0> : <EOL> view . axisSubtreeRelSet = view . modelXbrl . relationshipSet ( XbrlConst . euAxisMember , viewTblELR ) <EOL> else : <EOL> tblAxisRelSet = view . modelXbrl . relationshipSet ( ( XbrlConst . tableBreakdown , XbrlConst . tableBreakdownMMDD , XbrlConst . tableBreakdown201305 , XbrlConst . tableBreakdown201301 , XbrlConst . tableAxis2011 ) , viewTblELR ) <EOL> view . axisSubtreeRelSet = view . modelXbrl . relationshipSet ( ( XbrlConst . tableBreakdownTree , XbrlConst . tableBreakdownTreeMMDD , XbrlConst . tableBreakdownTree201305 , XbrlConst . tableDefinitionNodeSubtree , XbrlConst . tableDefinitionNodeSubtreeMMDD , XbrlConst . tableDefinitionNodeSubtree201305 , XbrlConst . tableDefinitionNodeSubtree201301 , XbrlConst . tableAxisSubtree2011 ) , viewTblELR ) <EOL> if tblAxisRelSet is None or len ( tblAxisRelSet . modelRelationships ) == <NUM_LIT:0> : <EOL> view . modelXbrl . modelManager . addToLog ( _ ( "<STR_LIT>" ) . format ( viewTblELR ) ) <EOL> return ( None , None , None , None ) <EOL> modelRoleTypes = view . modelXbrl . roleTypes . get ( viewTblELR ) <EOL> if modelRoleTypes is not None and len ( modelRoleTypes ) > <NUM_LIT:0> : <EOL> view . roledefinition = modelRoleTypes [ <NUM_LIT:0> ] . definition <EOL> if view . roledefinition is None or view . roledefinition == "<STR_LIT>" : <EOL> view . roledefinition = os . path . basename ( viewTblELR ) <EOL> try : <EOL> for table in tblAxisRelSet . rootConcepts : <EOL> return resolveTableAxesStructure ( view , table , tblAxisRelSet ) <EOL> except ResolutionException as ex : <EOL> view . modelXbrl . error ( ex . code , ex . message , exc_info = True , ** ex . kwargs ) ; <EOL> return ( None , None , None , None ) <EOL> def resolveTableAxesStructure ( view , table , tblAxisRelSet ) : <EOL> view . dataCols = <NUM_LIT:0> <EOL> view . dataRows = <NUM_LIT:0> <EOL> view . dataFirstCol = <NUM_LIT:0> <EOL> view . dataFirstRow = <NUM_LIT:0> <EOL> view . colHdrNonStdRoles = [ ] <EOL> view . colHdrDocRow = False <EOL> view . colHdrCodeRow = False <EOL> view . colHdrRows = <NUM_LIT:0> <EOL> view . rowHdrNonStdRoles = [ ] <EOL> view . rowHdrCols = <NUM_LIT:0> <EOL> view . rowHdrColWidth = [ <NUM_LIT:0> , ] <EOL> view . rowNonAbstractHdrSpanMin = [ <NUM_LIT:0> , ] <EOL> view . rowHdrDocCol = False <EOL> view . rowHdrCodeCol = False <EOL> view . zAxisRows = <NUM_LIT:0> <EOL> view . aspectModel = table . aspectModel <EOL> view . zmostOrdCntx = None <EOL> view . modelTable = table <EOL> view . topRollup = { "<STR_LIT:x>" : ROLLUP_NOT_ANALYZED , "<STR_LIT:y>" : ROLLUP_NOT_ANALYZED } <EOL> view . aspectEntryObjectId = <NUM_LIT:0> <EOL> view . modelTable = table <EOL> view . rendrCntx = table . renderingXPathContext <EOL> xTopStructuralNode = yTopStructuralNode = zTopStructuralNode = None <EOL> tblAxisRels = tblAxisRelSet . fromModelObject ( table ) <EOL> facts = view . modelXbrl . factsInInstance <EOL> if facts : <EOL> facts = table . filteredFacts ( view . rendrCntx , view . modelXbrl . factsInInstance ) <EOL> view . breakdownNodes = defaultdict ( list ) <EOL> for tblAxisRel in tblAxisRels : <EOL> definitionNode = tblAxisRel . toModelObject <EOL> addBreakdownNode ( view , tblAxisRel . axisDisposition , definitionNode ) <EOL> for disposition in ( "<STR_LIT:z>" , "<STR_LIT:x>" , "<STR_LIT:y>" ) : <EOL> for i , tblAxisRel in enumerate ( tblAxisRels ) : <EOL> definitionNode = tblAxisRel . toModelObject <EOL> if ( tblAxisRel . axisDisposition == disposition and <EOL> isinstance ( definitionNode , ( ModelEuAxisCoord , ModelBreakdown , ModelDefinitionNode ) ) ) : <EOL> if disposition == "<STR_LIT:x>" and xTopStructuralNode is None : <EOL> xTopStructuralNode = StructuralNode ( None , definitionNode , definitionNode , view . zmostOrdCntx , tableNode = table , rendrCntx = view . rendrCntx ) <EOL> xTopStructuralNode . hasOpenNode = False <EOL> if isinstance ( definitionNode , ( ModelBreakdown , ModelClosedDefinitionNode ) ) and definitionNode . parentChildOrder is not None : <EOL> view . xAxisChildrenFirst . set ( definitionNode . parentChildOrder == "<STR_LIT>" ) <EOL> view . xTopRollup = CHILD_ROLLUP_LAST if definitionNode . parentChildOrder == "<STR_LIT>" else CHILD_ROLLUP_FIRST <EOL> expandDefinition ( view , xTopStructuralNode , definitionNode , definitionNode , <NUM_LIT:1> , disposition , facts , i , tblAxisRels ) <EOL> view . dataCols = xTopStructuralNode . leafNodeCount <EOL> break <EOL> elif disposition == "<STR_LIT:y>" and yTopStructuralNode is None : <EOL> yTopStructuralNode = StructuralNode ( None , definitionNode , definitionNode , view . zmostOrdCntx , tableNode = table , rendrCntx = view . rendrCntx ) <EOL> yTopStructuralNode . hasOpenNode = False <EOL> if isinstance ( definitionNode , ( ModelBreakdown , ModelClosedDefinitionNode ) ) and definitionNode . parentChildOrder is not None : <EOL> view . yAxisChildrenFirst . set ( definitionNode . parentChildOrder == "<STR_LIT>" ) <EOL> view . yTopRollup = CHILD_ROLLUP_LAST if definitionNode . parentChildOrder == "<STR_LIT>" else CHILD_ROLLUP_FIRST <EOL> expandDefinition ( view , yTopStructuralNode , definitionNode , definitionNode , <NUM_LIT:1> , disposition , facts , i , tblAxisRels ) <EOL> view . dataRows = yTopStructuralNode . leafNodeCount <EOL> break <EOL> elif disposition == "<STR_LIT:z>" and zTopStructuralNode is None : <EOL> zTopStructuralNode = StructuralNode ( None , definitionNode , definitionNode , tableNode = table , rendrCntx = view . rendrCntx ) <EOL> zTopStructuralNode . _choiceStructuralNodes = [ ] <EOL> zTopStructuralNode . hasOpenNode = False <EOL> expandDefinition ( view , zTopStructuralNode , definitionNode , definitionNode , <NUM_LIT:1> , disposition , facts , i , tblAxisRels ) <EOL> break <EOL> '''<STR_LIT>''' <EOL> view . colHdrTopRow = view . zAxisRows + <NUM_LIT:1> <EOL> for i in range ( view . rowHdrCols ) : <EOL> if view . rowNonAbstractHdrSpanMin [ i ] : <EOL> lastRowMinWidth = view . rowNonAbstractHdrSpanMin [ i ] - sum ( view . rowHdrColWidth [ i ] for j in range ( i , view . rowHdrCols - <NUM_LIT:1> ) ) <EOL> if lastRowMinWidth > view . rowHdrColWidth [ view . rowHdrCols - <NUM_LIT:1> ] : <EOL> view . rowHdrColWidth [ view . rowHdrCols - <NUM_LIT:1> ] = lastRowMinWidth <EOL> view . rowHdrWrapLength = <NUM_LIT:200> + sum ( view . rowHdrColWidth [ : view . rowHdrCols + <NUM_LIT:1> ] ) <EOL> view . dataFirstRow = view . colHdrTopRow + view . colHdrRows + len ( view . colHdrNonStdRoles ) <EOL> view . dataFirstCol = <NUM_LIT:1> + view . rowHdrCols + len ( view . rowHdrNonStdRoles ) <EOL> for hdrNonStdRoles in ( view . colHdrNonStdRoles , view . rowHdrNonStdRoles ) : <EOL> iCodeRole = - <NUM_LIT:1> <EOL> for i , hdrNonStdRole in enumerate ( hdrNonStdRoles ) : <EOL> if '<STR_LIT:code>' in os . path . basename ( hdrNonStdRole ) . lower ( ) : <EOL> iCodeRole = i <EOL> break <EOL> if iCodeRole >= <NUM_LIT:0> and len ( hdrNonStdRoles ) > <NUM_LIT:1> and iCodeRole < len ( hdrNonStdRoles ) - <NUM_LIT:1> : <EOL> del hdrNonStdRoles [ iCodeRole ] <EOL> hdrNonStdRoles . append ( hdrNonStdRole ) <EOL> if view . topRollup [ "<STR_LIT:x>" ] : <EOL> view . xAxisChildrenFirst . set ( view . topRollup [ "<STR_LIT:x>" ] == CHILD_ROLLUP_LAST ) <EOL> if view . topRollup [ "<STR_LIT:y>" ] : <EOL> view . yAxisChildrenFirst . set ( view . topRollup [ "<STR_LIT:y>" ] == CHILD_ROLLUP_LAST ) <EOL> return ( tblAxisRelSet , xTopStructuralNode , yTopStructuralNode , zTopStructuralNode ) <EOL> def sortkey ( obj ) : <EOL> if isinstance ( obj , ModelObject ) : <EOL> return obj . objectIndex <EOL> return obj <EOL> def addBreakdownNode ( view , disposition , node ) : <EOL> if isinstance ( node , ModelBreakdown ) : <EOL> axisBreakdowns = view . breakdownNodes [ disposition ] <EOL> if node not in axisBreakdowns : <EOL> axisBreakdowns . append ( node ) <EOL> def childContainsOpenNodes ( childStructuralNode ) : <EOL> if isinstance ( childStructuralNode . definitionNode , ModelFilterDefinitionNode ) and ( childStructuralNode . isLabeled or any ( [ node . isEntryPrototype ( default = False ) for node in childStructuralNode . childStructuralNodes ] ) ) : <EOL> return True <EOL> else : <EOL> for node in childStructuralNode . childStructuralNodes : <EOL> if childContainsOpenNodes ( node ) : <EOL> return True <EOL> return False <EOL> def expandDefinition ( view , structuralNode , breakdownNode , definitionNode , depth , axisDisposition , facts , i = None , tblAxisRels = None , processOpenDefinitionNode = True ) : <EOL> subtreeRelationships = view . axisSubtreeRelSet . fromModelObject ( definitionNode ) <EOL> def checkLabelWidth ( structuralNode , checkBoundFact = False ) : <EOL> if axisDisposition == "<STR_LIT:y>" : <EOL> label = structuralNode . header ( lang = view . lang , <EOL> returnGenLabel = not checkBoundFact , <EOL> returnMsgFormatString = not checkBoundFact ) <EOL> if label : <EOL> widestWordLen = max ( len ( w ) * RENDER_UNITS_PER_CHAR for w in label . split ( ) ) <EOL> while structuralNode . depth >= len ( view . rowHdrColWidth ) : <EOL> view . rowHdrColWidth . append ( <NUM_LIT:0> ) <EOL> if definitionNode . isAbstract or not subtreeRelationships : <EOL> if widestWordLen > view . rowHdrColWidth [ structuralNode . depth ] : <EOL> view . rowHdrColWidth [ structuralNode . depth ] = widestWordLen <EOL> else : <EOL> if widestWordLen > view . rowNonAbstractHdrSpanMin [ structuralNode . depth ] : <EOL> view . rowNonAbstractHdrSpanMin [ structuralNode . depth ] = widestWordLen <EOL> if axisDisposition == "<STR_LIT:z>" and structuralNode . aspects is None : <EOL> structuralNode . aspects = view . zOrdinateChoices . get ( definitionNode , None ) <EOL> if structuralNode and isinstance ( definitionNode , ( ModelBreakdown , ModelEuAxisCoord , ModelDefinitionNode ) ) : <EOL> try : <EOL> ordCardinality , ordDepth = definitionNode . cardinalityAndDepth ( structuralNode ) <EOL> if ( not definitionNode . isAbstract and <EOL> isinstance ( definitionNode , ModelClosedDefinitionNode ) and <EOL> ordCardinality == <NUM_LIT:0> ) : <EOL> view . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = ( view . modelTable , definitionNode ) , xlinkLabel = definitionNode . xlinkLabel , axis = definitionNode . localName ) <EOL> nestedDepth = depth + ordDepth <EOL> cartesianProductNestedArgs = [ view , nestedDepth , axisDisposition , facts , tblAxisRels , i ] <EOL> if axisDisposition == "<STR_LIT:z>" : <EOL> if depth == <NUM_LIT:1> : <EOL> view . zAxisRows += <NUM_LIT:1> <EOL> elif axisDisposition == "<STR_LIT:x>" : <EOL> if ordDepth : <EOL> if nestedDepth - <NUM_LIT:1> > view . colHdrRows : <EOL> view . colHdrRows = nestedDepth - <NUM_LIT:1> <EOL> '''<STR_LIT>''' <EOL> hdrNonStdRoles = view . colHdrNonStdRoles <EOL> elif axisDisposition == "<STR_LIT:y>" : <EOL> if ordDepth : <EOL> if nestedDepth - <NUM_LIT:1> > view . rowHdrCols : <EOL> view . rowHdrCols = nestedDepth - <NUM_LIT:1> <EOL> for j in range ( <NUM_LIT:1> + ordDepth ) : <EOL> view . rowHdrColWidth . append ( RENDER_UNITS_PER_CHAR ) <EOL> view . rowNonAbstractHdrSpanMin . append ( <NUM_LIT:0> ) <EOL> checkLabelWidth ( structuralNode , checkBoundFact = False ) <EOL> '''<STR_LIT>''' <EOL> hdrNonStdRoles = view . rowHdrNonStdRoles <EOL> if axisDisposition in ( "<STR_LIT:x>" , "<STR_LIT:y>" ) : <EOL> hdrNonStdPosition = - <NUM_LIT:1> <EOL> for rel in view . modelXbrl . relationshipSet ( XbrlConst . elementLabel ) . fromModelObject ( definitionNode ) : <EOL> if rel . toModelObject is not None and rel . toModelObject . role != XbrlConst . genStandardLabel : <EOL> labelLang = rel . toModelObject . xmlLang <EOL> labelRole = rel . toModelObject . role <EOL> if ( labelLang == view . lang or labelLang . startswith ( view . lang ) or view . lang . startswith ( labelLang ) <EOL> or ( "<STR_LIT:code>" in labelRole ) ) : <EOL> labelRole = rel . toModelObject . role <EOL> if labelRole in hdrNonStdRoles : <EOL> hdrNonStdPosition = hdrNonStdRoles . index ( labelRole ) <EOL> else : <EOL> hdrNonStdRoles . insert ( hdrNonStdPosition + <NUM_LIT:1> , labelRole ) <EOL> isCartesianProductExpanded = False <EOL> if not isinstance ( definitionNode , ModelFilterDefinitionNode ) : <EOL> isCartesianProductExpanded = True <EOL> for axisSubtreeRel in subtreeRelationships : <EOL> childDefinitionNode = axisSubtreeRel . toModelObject <EOL> if childDefinitionNode . isRollUp : <EOL> structuralNode . rollUpStructuralNode = StructuralNode ( structuralNode , breakdownNode , childDefinitionNode , ) <EOL> if not structuralNode . childStructuralNodes : <EOL> structuralNode . subtreeRollUp = CHILD_ROLLUP_FIRST <EOL> else : <EOL> structuralNode . subtreeRollUp = CHILD_ROLLUP_LAST <EOL> if not view . topRollup . get ( axisDisposition ) : <EOL> view . topRollup [ axisDisposition ] = structuralNode . subtreeRollUp <EOL> else : <EOL> if ( isinstance ( definitionNode , ( ModelBreakdown , ModelCompositionDefinitionNode ) ) and <EOL> isinstance ( childDefinitionNode , ModelRelationshipDefinitionNode ) ) : <EOL> childStructuralNode = structuralNode <EOL> else : <EOL> childStructuralNode = StructuralNode ( structuralNode , breakdownNode , childDefinitionNode ) <EOL> if axisDisposition != "<STR_LIT:z>" : <EOL> structuralNode . childStructuralNodes . append ( childStructuralNode ) <EOL> if axisDisposition != "<STR_LIT:z>" : <EOL> expandDefinition ( view , childStructuralNode , breakdownNode , childDefinitionNode , depth + ordDepth , axisDisposition , facts , i , tblAxisRels ) <EOL> if not childContainsOpenNodes ( childStructuralNode ) : <EOL> cartesianProductExpander ( childStructuralNode , * cartesianProductNestedArgs ) <EOL> else : <EOL> childStructuralNode . indent = depth - <NUM_LIT:1> <EOL> if structuralNode . choiceStructuralNodes is not None : <EOL> structuralNode . choiceStructuralNodes . append ( childStructuralNode ) <EOL> expandDefinition ( view , childStructuralNode , breakdownNode , childDefinitionNode , depth + <NUM_LIT:1> , axisDisposition , facts ) <EOL> if processOpenDefinitionNode : <EOL> if isinstance ( definitionNode , ModelRelationshipDefinitionNode ) : <EOL> structuralNode . isLabeled = False <EOL> selfStructuralNodes = { } if definitionNode . axis . endswith ( '<STR_LIT>' ) else None <EOL> for rel in definitionNode . relationships ( structuralNode ) : <EOL> if not isinstance ( rel , list ) : <EOL> relChildStructuralNode = addRelationship ( breakdownNode , definitionNode , rel , structuralNode , cartesianProductNestedArgs , selfStructuralNodes ) <EOL> else : <EOL> addRelationships ( breakdownNode , definitionNode , rel , relChildStructuralNode , cartesianProductNestedArgs ) <EOL> if axisDisposition == "<STR_LIT:z>" : <EOL> if structuralNode . choiceStructuralNodes and structuralNode . choiceStructuralNodes [ <NUM_LIT:0> ] . definitionNode == definitionNode : <EOL> del structuralNode . choiceStructuralNodes [ <NUM_LIT:0> ] <EOL> def flattenChildNodesToChoices ( childStructuralNodes , indent ) : <EOL> while childStructuralNodes : <EOL> choiceStructuralNode = childStructuralNodes . pop ( <NUM_LIT:0> ) <EOL> choiceStructuralNode . indent = indent <EOL> structuralNode . choiceStructuralNodes . append ( choiceStructuralNode ) <EOL> flattenChildNodesToChoices ( choiceStructuralNode . childStructuralNodes , indent + <NUM_LIT:1> ) <EOL> if structuralNode . childStructuralNodes : <EOL> flattenChildNodesToChoices ( structuralNode . childStructuralNodes , <NUM_LIT:0> ) <EOL> if isinstance ( definitionNode , ModelConceptRelationshipDefinitionNode ) : <EOL> if ( definitionNode . _sourceQname != XbrlConst . qnXfiRoot and <EOL> definitionNode . _sourceQname not in view . modelXbrl . qnameConcepts ) : <EOL> view . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , xlinkLabel = definitionNode . xlinkLabel , source = definitionNode . _sourceQname ) <EOL> elif isinstance ( definitionNode , ModelDimensionRelationshipDefinitionNode ) : <EOL> dim = view . modelXbrl . qnameConcepts . get ( definitionNode . _dimensionQname ) <EOL> if dim is None or not dim . isExplicitDimension : <EOL> view . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , xlinkLabel = definitionNode . xlinkLabel , dimension = definitionNode . _dimensionQname ) <EOL> domMbr = view . modelXbrl . qnameConcepts . get ( definitionNode . _sourceQname ) <EOL> if domMbr is None or not domMbr . isDomainMember : <EOL> view . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , xlinkLabel = definitionNode . xlinkLabel , source = definitionNode . _sourceQname ) <EOL> if ( definitionNode . _axis in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) and <EOL> ( not isinstance ( definitionNode . _generations , _NUM_TYPES ) or definitionNode . _generations > <NUM_LIT:1> ) ) : <EOL> view . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , xlinkLabel = definitionNode . xlinkLabel , axis = definitionNode . _axis , generations = definitionNode . _generations ) <EOL> elif isinstance ( definitionNode , ModelSelectionDefinitionNode ) : <EOL> structuralNode . setHasOpenNode ( ) <EOL> structuralNode . isLabeled = False <EOL> isCartesianProductExpanded = True <EOL> varQn = definitionNode . variableQname <EOL> if varQn : <EOL> selections = sorted ( structuralNode . evaluate ( definitionNode , definitionNode . evaluate ) or [ ] , <EOL> key = lambda obj : sortkey ( obj ) ) <EOL> if isinstance ( selections , ( list , set , tuple ) ) and len ( selections ) > <NUM_LIT:1> : <EOL> for selection in selections : <EOL> childStructuralNode = StructuralNode ( structuralNode , breakdownNode , definitionNode , contextItemFact = selection ) <EOL> childStructuralNode . variables [ varQn ] = selection <EOL> childStructuralNode . indent = <NUM_LIT:0> <EOL> if axisDisposition == "<STR_LIT:z>" : <EOL> structuralNode . choiceStructuralNodes . append ( childStructuralNode ) <EOL> childStructuralNode . zSelection = True <EOL> else : <EOL> structuralNode . childStructuralNodes . append ( childStructuralNode ) <EOL> expandDefinition ( view , childStructuralNode , breakdownNode , definitionNode , depth , axisDisposition , facts , processOpenDefinitionNode = False ) <EOL> cartesianProductExpander ( childStructuralNode , * cartesianProductNestedArgs ) <EOL> else : <EOL> structuralNode . variables [ varQn ] = selections <EOL> elif isinstance ( definitionNode , ModelFilterDefinitionNode ) : <EOL> structuralNode . setHasOpenNode ( ) <EOL> structuralNode . isLabeled = False <EOL> isCartesianProductExpanded = True <EOL> structuralNode . abstract = True <EOL> filteredFactsPartitions = structuralNode . evaluate ( definitionNode , <EOL> definitionNode . filteredFactsPartitions , <EOL> evalArgs = ( facts , ) ) <EOL> if structuralNode . _rendrCntx . formulaOptions . traceVariableFilterWinnowing : <EOL> view . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , xlinkLabel = definitionNode . xlinkLabel , <EOL> factsPartitions = str ( filteredFactsPartitions ) ) <EOL> if axisDisposition != "<STR_LIT:z>" : <EOL> childList = structuralNode . childStructuralNodes <EOL> if structuralNode . isEntryPrototype ( default = True ) : <EOL> for i in range ( getattr ( view , "<STR_LIT>" , <EOL> <NUM_LIT:0> if filteredFactsPartitions else <NUM_LIT:1> ) ) : <EOL> view . aspectEntryObjectId += <NUM_LIT:1> <EOL> filteredFactsPartitions . append ( [ FactPrototype ( view , { "<STR_LIT>" : OPEN_ASPECT_ENTRY_SURROGATE + str ( view . aspectEntryObjectId ) } ) ] ) <EOL> if structuralNode . isEntryPrototype ( default = False ) : <EOL> break <EOL> else : <EOL> childList = structuralNode . choiceStructuralNodes <EOL> for factsPartition in filteredFactsPartitions : <EOL> childStructuralNode = StructuralNode ( structuralNode , breakdownNode , definitionNode , contextItemFact = factsPartition [ <NUM_LIT:0> ] ) <EOL> childStructuralNode . indent = <NUM_LIT:0> <EOL> childStructuralNode . depth -= <NUM_LIT:1> <EOL> childList . append ( childStructuralNode ) <EOL> checkLabelWidth ( childStructuralNode , checkBoundFact = True ) <EOL> cartesianProductNestedArgs [ <NUM_LIT:3> ] = factsPartition <EOL> if subtreeRelationships : <EOL> for axisSubtreeRel in subtreeRelationships : <EOL> child2DefinitionNode = axisSubtreeRel . toModelObject <EOL> child2StructuralNode = StructuralNode ( childStructuralNode , breakdownNode , child2DefinitionNode ) <EOL> childStructuralNode . childStructuralNodes . append ( child2StructuralNode ) <EOL> expandDefinition ( view , child2StructuralNode , breakdownNode , child2DefinitionNode , depth + ordDepth , axisDisposition , factsPartition ) <EOL> cartesianProductExpander ( child2StructuralNode , * cartesianProductNestedArgs ) <EOL> else : <EOL> cartesianProductExpander ( childStructuralNode , * cartesianProductNestedArgs ) <EOL> childList . sort ( key = lambda childStructuralNode : <EOL> childStructuralNode . header ( lang = view . lang , <EOL> returnGenLabel = False , <EOL> returnMsgFormatString = False ) <EOL> or '<STR_LIT>' ) <EOL> elif isinstance ( definitionNode , ModelTupleDefinitionNode ) : <EOL> structuralNode . abstract = True <EOL> matchingTupleFacts = structuralNode . evaluate ( definitionNode , <EOL> definitionNode . filteredFacts , <EOL> evalArgs = ( facts , ) ) <EOL> for tupleFact in matchingTupleFacts : <EOL> childStructuralNode = StructuralNode ( structuralNode , breakdownNode , definitionNode , contextItemFact = tupleFact ) <EOL> childStructuralNode . indent = <NUM_LIT:0> <EOL> structuralNode . childStructuralNodes . append ( childStructuralNode ) <EOL> expandDefinition ( view , childStructuralNode , breakdownNode , definitionNode , depth , axisDisposition , [ tupleFact ] ) <EOL> if ( structuralNode . childStructuralNodes and <EOL> any ( sOC . header ( lang = view . lang ) for sOC in structuralNode . childStructuralNodes ) ) : <EOL> structuralNode . childStructuralNodes . sort ( key = lambda childStructuralNode : childStructuralNode . header ( lang = view . lang ) or '<STR_LIT>' ) <EOL> elif isinstance ( definitionNode , ModelRuleDefinitionNode ) : <EOL> for constraintSet in definitionNode . constraintSets . values ( ) : <EOL> for aspect in constraintSet . aspectsCovered ( ) : <EOL> if not constraintSet . aspectValueDependsOnVars ( aspect ) : <EOL> if aspect == Aspect . CONCEPT : <EOL> conceptQname = definitionNode . aspectValue ( view . rendrCntx , Aspect . CONCEPT ) <EOL> concept = view . modelXbrl . qnameConcepts . get ( conceptQname ) <EOL> if concept is None or not concept . isItem or concept . isDimensionItem or concept . isHypercubeItem : <EOL> view . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , xlinkLabel = definitionNode . xlinkLabel , concept = conceptQname ) <EOL> elif isinstance ( aspect , QName ) : <EOL> dim = view . modelXbrl . qnameConcepts . get ( aspect ) <EOL> memQname = definitionNode . aspectValue ( view . rendrCntx , aspect ) <EOL> mem = view . modelXbrl . qnameConcepts . get ( memQname ) <EOL> if dim is None or not dim . isDimensionItem : <EOL> view . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , xlinkLabel = definitionNode . xlinkLabel , concept = aspect ) <EOL> if isinstance ( memQname , QName ) and ( mem is None or not mem . isDomainMember ) : <EOL> view . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , xlinkLabel = definitionNode . xlinkLabel , concept = memQname ) <EOL> if axisDisposition == "<STR_LIT:z>" : <EOL> if structuralNode . choiceStructuralNodes : <EOL> choiceNodeIndex = view . zOrdinateChoices . get ( definitionNode , <NUM_LIT:0> ) <EOL> if isinstance ( choiceNodeIndex , dict ) : <EOL> structuralNode . aspects = choiceNodeIndex <EOL> structuralNode . choiceNodeIndex = - <NUM_LIT:1> <EOL> elif choiceNodeIndex < len ( structuralNode . choiceStructuralNodes ) : <EOL> structuralNode . choiceNodeIndex = choiceNodeIndex <EOL> else : <EOL> structuralNode . choiceNodeIndex = <NUM_LIT:0> <EOL> view . zmostOrdCntx = structuralNode <EOL> if not isCartesianProductExpanded or ( axisDisposition == "<STR_LIT:z>" and structuralNode . choiceStructuralNodes is not None ) : <EOL> cartesianProductExpander ( structuralNode , * cartesianProductNestedArgs ) <EOL> if not structuralNode . childStructuralNodes : <EOL> subOrdContext = StructuralNode ( structuralNode , breakdownNode , definitionNode ) <EOL> except ResolutionException as ex : <EOL> if sys . version [ <NUM_LIT:0> ] >= '<STR_LIT:3>' : <EOL> raise ex . with_traceback ( ex . __traceback__ ) <EOL> else : <EOL> raise ex <EOL> except Exception as ex : <EOL> e = ResolutionException ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = definitionNode , node = definitionNode . qname , error = str ( ex ) <EOL> ) <EOL> if sys . version [ <NUM_LIT:0> ] >= '<STR_LIT:3>' : <EOL> raise e . with_traceback ( ex . __traceback__ ) <EOL> else : <EOL> raise e <EOL> def cartesianProductExpander ( childStructuralNode , view , depth , axisDisposition , facts , tblAxisRels , i ) : <EOL> if i is not None : <EOL> for j , tblRel in enumerate ( tblAxisRels [ i + <NUM_LIT:1> : ] ) : <EOL> tblObj = tblRel . toModelObject <EOL> if isinstance ( tblObj , ( ModelEuAxisCoord , ModelDefinitionNode ) ) and axisDisposition == tblRel . axisDisposition : <EOL> if axisDisposition == "<STR_LIT:z>" : <EOL> subOrdTblCntx = StructuralNode ( childStructuralNode , tblObj , tblObj ) <EOL> subOrdTblCntx . _choiceStructuralNodes = [ ] <EOL> subOrdTblCntx . indent = <NUM_LIT:0> <EOL> depth = <NUM_LIT:0> <EOL> childStructuralNode . childStructuralNodes . append ( subOrdTblCntx ) <EOL> else : <EOL> subOrdTblCntx = childStructuralNode <EOL> if isinstance ( childStructuralNode . definitionNode , ModelClosedDefinitionNode ) : <EOL> matchingFacts = childStructuralNode . evaluate ( childStructuralNode . definitionNode , <EOL> childStructuralNode . definitionNode . filteredFacts , <EOL> evalArgs = ( facts , ) ) <EOL> else : <EOL> matchingFacts = facts <EOL> subOrdTblCntx . abstract = True <EOL> expandDefinition ( view , subOrdTblCntx , tblObj , tblObj , <EOL> depth , <EOL> axisDisposition , matchingFacts , j + i + <NUM_LIT:1> , tblAxisRels ) <EOL> break <EOL> def addRelationship ( breakdownNode , relDefinitionNode , rel , structuralNode , cartesianProductNestedArgs , selfStructuralNodes = None ) : <EOL> variableQname = relDefinitionNode . variableQname <EOL> conceptQname = relDefinitionNode . conceptQname <EOL> coveredAspect = relDefinitionNode . coveredAspect ( structuralNode ) <EOL> if not coveredAspect : <EOL> return None <EOL> if selfStructuralNodes is not None : <EOL> fromConceptQname = rel . fromModelObject . qname <EOL> if fromConceptQname in selfStructuralNodes : <EOL> childStructuralNode = selfStructuralNodes [ fromConceptQname ] <EOL> else : <EOL> childStructuralNode = StructuralNode ( structuralNode , breakdownNode , relDefinitionNode ) <EOL> structuralNode . childStructuralNodes . append ( childStructuralNode ) <EOL> selfStructuralNodes [ fromConceptQname ] = childStructuralNode <EOL> if variableQname : <EOL> childStructuralNode . variables [ variableQname ] = [ ] <EOL> if conceptQname : <EOL> childStructuralNode . variables [ conceptQname ] = fromConceptQname <EOL> childStructuralNode . aspects [ coveredAspect ] = fromConceptQname <EOL> relChildStructuralNode = StructuralNode ( childStructuralNode , breakdownNode , relDefinitionNode ) <EOL> childStructuralNode . childStructuralNodes . append ( relChildStructuralNode ) <EOL> else : <EOL> relChildStructuralNode = StructuralNode ( structuralNode , breakdownNode , relDefinitionNode ) <EOL> structuralNode . childStructuralNodes . append ( relChildStructuralNode ) <EOL> preferredLabel = rel . preferredLabel <EOL> if preferredLabel == XbrlConst . periodStartLabel : <EOL> relChildStructuralNode . tagSelector = "<STR_LIT>" <EOL> elif preferredLabel == XbrlConst . periodStartLabel : <EOL> relChildStructuralNode . tagSelector = "<STR_LIT>" <EOL> if variableQname : <EOL> relChildStructuralNode . variables [ variableQname ] = rel <EOL> toConceptQname = rel . toModelObject . qname <EOL> if conceptQname : <EOL> relChildStructuralNode . variables [ conceptQname ] = toConceptQname <EOL> relChildStructuralNode . aspects [ coveredAspect ] = toConceptQname <EOL> cartesianProductExpander ( relChildStructuralNode , * cartesianProductNestedArgs ) <EOL> return relChildStructuralNode <EOL> def addRelationships ( breakdownNode , relDefinitionNode , rels , structuralNode , cartesianProductNestedArgs ) : <EOL> childStructuralNode = None <EOL> for rel in rels : <EOL> if not isinstance ( rel , list ) : <EOL> childStructuralNode = addRelationship ( breakdownNode , relDefinitionNode , rel , structuralNode , cartesianProductNestedArgs ) <EOL> elif childStructuralNode is None : <EOL> childStructuralNode = StructuralNode ( structuralNode , breakdownNode , relDefinitionNode ) <EOL> structuralNode . childStructuralNodes . append ( childStructuralNode ) <EOL> addRelationships ( breakdownNode , relDefinitionNode , rel , childStructuralNode , cartesianProductNestedArgs ) <EOL> else : <EOL> addRelationships ( breakdownNode , relDefinitionNode , rel , childStructuralNode , cartesianProductNestedArgs ) </s>
