<s> from arelle import XmlUtil <EOL> from arelle . ModelValue import QName <EOL> from arelle . ModelObject import ModelObject <EOL> Aspect = None <EOL> class FactPrototype ( ) : <EOL> def __init__ ( self , v , aspectValues = None ) : <EOL> global Aspect <EOL> if Aspect is None : <EOL> from arelle . ModelFormulaObject import Aspect <EOL> self . modelXbrl = v . modelXbrl <EOL> if aspectValues is None : <EOL> aspectValues = { } <EOL> self . aspectEntryObjectId = aspectValues . get ( "<STR_LIT>" , None ) <EOL> if Aspect . CONCEPT in aspectValues : <EOL> qname = aspectValues [ Aspect . CONCEPT ] <EOL> self . qname = qname <EOL> self . concept = v . modelXbrl . qnameConcepts . get ( qname ) <EOL> self . isItem = self . concept is not None and self . concept . isItem <EOL> self . isTuple = self . concept is not None and self . concept . isTuple <EOL> else : <EOL> self . qname = None <EOL> self . concept = None <EOL> self . isItem = False <EOL> self . isTuple = False <EOL> if Aspect . LOCATION in aspectValues : <EOL> self . parent = aspectValues [ Aspect . LOCATION ] <EOL> try : <EOL> self . isTuple = self . parent . isTuple <EOL> except AttributeError : <EOL> self . isTuple = False <EOL> else : <EOL> self . parent = v . modelXbrl . modelDocument . xmlRootElement <EOL> self . isNumeric = self . concept is not None and self . concept . isNumeric <EOL> self . context = ContextPrototype ( v , aspectValues ) <EOL> if Aspect . UNIT in aspectValues : <EOL> self . unit = UnitPrototype ( v , aspectValues ) <EOL> else : <EOL> self . unit = None <EOL> self . factObjectId = None <EOL> def clear ( self ) : <EOL> if self . context is not None : <EOL> self . context . clear ( ) <EOL> self . __dict__ . clear ( ) <EOL> def objectId ( self ) : <EOL> return "<STR_LIT>" + str ( self . qname ) <EOL> def getparent ( self ) : <EOL> return self . parent <EOL> @ property <EOL> def propertyView ( self ) : <EOL> dims = self . context . qnameDims <EOL> return ( ( "<STR_LIT>" , str ( self . qname ) if self . concept is not None else "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" . format ( len ( dims ) ) , <EOL> tuple ( dimVal . propertyView if dimVal is not None else ( str ( dim . qname ) , "<STR_LIT:None>" ) <EOL> for dim , dimVal in sorted ( dims . items ( ) , key = lambda i : i [ <NUM_LIT:0> ] ) <EOL> if hasattr ( dimVal , '<STR_LIT>' ) ) ) <EOL> if dims else ( ) , <EOL> ) <EOL> @ property <EOL> def viewConcept ( self ) : <EOL> return self <EOL> class ContextPrototype ( ) : <EOL> def __init__ ( self , v , aspectValues ) : <EOL> self . modelXbrl = v . modelXbrl <EOL> self . segDimVals = { } <EOL> self . scenDimVals = { } <EOL> self . qnameDims = { } <EOL> self . entityIdentifierHash = self . entityIdentifier = None <EOL> self . isStartEndPeriod = self . isInstantPeriod = self . isForeverPeriod = False <EOL> for aspect , aspectValue in aspectValues . items ( ) : <EOL> if aspect == Aspect . PERIOD_TYPE : <EOL> if aspectValue == "<STR_LIT>" : <EOL> self . isForeverPeriod = True <EOL> elif aspectValue == "<STR_LIT>" : <EOL> self . isInstantPeriod = True <EOL> elif aspectValue == "<STR_LIT>" : <EOL> self . isStartEndPeriod = True <EOL> elif aspect == Aspect . START : <EOL> self . isStartEndPeriod = True <EOL> self . startDatetime = aspectValue <EOL> elif aspect == Aspect . END : <EOL> self . isStartEndPeriod = True <EOL> self . endDatetime = aspectValue <EOL> elif aspect == Aspect . INSTANT : <EOL> self . isInstantPeriod = True <EOL> self . endDatetime = self . instantDatetime = aspectValue <EOL> elif isinstance ( aspect , QName ) : <EOL> try : <EOL> contextElement = aspectValue . contextElement <EOL> aspectValue = ( aspectValue . memberQname or aspectValue . typedMember ) <EOL> except AttributeError : <EOL> contextElement = v . modelXbrl . qnameDimensionContextElement . get ( aspect ) <EOL> if v . modelXbrl . qnameDimensionDefaults . get ( aspect ) != aspectValue : <EOL> try : <EOL> dimConcept = v . modelXbrl . qnameConcepts [ aspect ] <EOL> dimValPrototype = DimValuePrototype ( v , dimConcept , aspect , aspectValue , contextElement ) <EOL> self . qnameDims [ aspect ] = dimValPrototype <EOL> if contextElement != "<STR_LIT>" : <EOL> self . segDimVals [ dimConcept ] = dimValPrototype <EOL> else : <EOL> self . scenDimVals [ dimConcept ] = dimValPrototype <EOL> except KeyError : <EOL> pass <EOL> elif isinstance ( aspectValue , ModelObject ) : <EOL> if aspect == Aspect . PERIOD : <EOL> context = aspectValue . getparent ( ) <EOL> for contextPeriodAttribute in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) : <EOL> setattr ( self , contextPeriodAttribute , getattr ( context , contextPeriodAttribute , None ) ) <EOL> elif aspect == Aspect . ENTITY_IDENTIFIER : <EOL> context = aspectValue . getparent ( ) . getparent ( ) <EOL> for entityIdentAttribute in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> setattr ( self , entityIdentAttribute , getattr ( context , entityIdentAttribute , None ) ) <EOL> def clear ( self ) : <EOL> try : <EOL> for dim in self . qnameDims . values ( ) : <EOL> if isinstance ( dim , DimValuePrototype ) : <EOL> dim . clear ( ) <EOL> except AttributeError : <EOL> pass <EOL> self . __dict__ . clear ( ) <EOL> def dimValue ( self , dimQname ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . qnameDims [ dimQname ] <EOL> except KeyError : <EOL> try : <EOL> return self . modelXbrl . qnameDimensionDefaults [ dimQname ] <EOL> except KeyError : <EOL> return None <EOL> def dimValues ( self , contextElement , oppositeContextElement = False ) : <EOL> if not oppositeContextElement : <EOL> return self . segDimVals if contextElement == "<STR_LIT>" else self . scenDimVals <EOL> else : <EOL> return self . scenDimVals if contextElement == "<STR_LIT>" else self . segDimVals <EOL> def nonDimValues ( self , contextElement ) : <EOL> return [ ] <EOL> def isEntityIdentifierEqualTo ( self , cntx2 ) : <EOL> return self . entityIdentifierHash is None or self . entityIdentifierHash == cntx2 . entityIdentifierHash <EOL> def isPeriodEqualTo ( self , cntx2 ) : <EOL> if self . isForeverPeriod : <EOL> return cntx2 . isForeverPeriod <EOL> elif self . isStartEndPeriod : <EOL> if not cntx2 . isStartEndPeriod : <EOL> return False <EOL> return self . startDatetime == cntx2 . startDatetime and self . endDatetime == cntx2 . endDatetime <EOL> elif self . isInstantPeriod : <EOL> if not cntx2 . isInstantPeriod : <EOL> return False <EOL> return self . instantDatetime == cntx2 . instantDatetime <EOL> else : <EOL> return False <EOL> class DimValuePrototype ( ) : <EOL> def __init__ ( self , v , dimConcept , dimQname , mem , contextElement ) : <EOL> from arelle . ModelValue import QName <EOL> if dimConcept is None : <EOL> dimConcept = v . modelXbrl . qnameConcepts . get ( dimQname ) <EOL> self . dimension = dimConcept <EOL> self . dimensionQname = dimQname <EOL> self . contextElement = contextElement <EOL> if isinstance ( mem , QName ) : <EOL> self . isExplicit = True <EOL> self . isTyped = False <EOL> self . memberQname = mem <EOL> self . member = v . modelXbrl . qnameConcepts . get ( mem ) <EOL> self . typedMember = None <EOL> else : <EOL> self . isExplicit = False <EOL> self . isTyped = True <EOL> self . typedMember = mem <EOL> self . memberQname = None <EOL> self . member = None <EOL> def clear ( self ) : <EOL> self . __dict__ . clear ( ) <EOL> @ property <EOL> def propertyView ( self ) : <EOL> if self . isExplicit : <EOL> return ( str ( self . dimensionQname ) , str ( self . memberQname ) ) <EOL> else : <EOL> return ( str ( self . dimensionQname ) , <EOL> XmlUtil . xmlstring ( self . typedMember , stripXmlns = True , prettyPrint = True ) <EOL> if isinstance ( self . typedMember , ModelObject ) else "<STR_LIT:None>" ) <EOL> class UnitPrototype ( ) : <EOL> def __init__ ( self , v , aspectValues ) : <EOL> self . modelXbrl = v . modelXbrl <EOL> self . hash = self . measures = self . isSingleMeasure = None <EOL> for aspect , aspectValue in aspectValues . items ( ) : <EOL> if aspect == Aspect . UNIT : <EOL> for unitAttribute in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> setattr ( self , unitAttribute , getattr ( aspectValue , unitAttribute , None ) ) <EOL> def clear ( self ) : <EOL> self . __dict__ . clear ( ) <EOL> def isEqualTo ( self , unit2 ) : <EOL> if unit2 is None or unit2 . hash != self . hash : <EOL> return False <EOL> return unit2 is self or self . measures == unit2 . measures <EOL> @ property <EOL> def propertyView ( self ) : <EOL> measures = self . measures <EOL> if measures [ <NUM_LIT:1> ] : <EOL> return tuple ( ( '<STR_LIT>' , m ) for m in measures [ <NUM_LIT:0> ] ) + tuple ( ( '<STR_LIT>' , d ) for d in measures [ <NUM_LIT:1> ] ) <EOL> else : <EOL> return tuple ( ( '<STR_LIT>' , m ) for m in measures [ <NUM_LIT:0> ] ) <EOL> class XbrlPrototype ( ) : <EOL> def __init__ ( self , modelManager , uri , * arg , ** kwarg ) : <EOL> self . modelManager = modelManager <EOL> self . errors = [ ] <EOL> self . skipDTS = False <EOL> from arelle . PrototypeDtsObject import DocumentPrototype <EOL> self . modelDocument = DocumentPrototype ( self , uri ) <EOL> def close ( self ) : <EOL> self . modelDocument . clear ( ) <EOL> self . __dict__ . clear ( ) </s>
