#NEWLINE# def createContext( self , entityIdentScheme , entityIdentValue , periodType , periodStart , periodEndInstant , priItem , dims , segOCCs , scenOCCs , afterSibling = None , beforeSibling = None , id = None ) : #NEWLINE# #INDENT# 'Creates a new ModelContext and validates (integrates into modelDocument object model).\n        \n        :param entityIdentScheme: Scheme to match\n        :type entityIdentScheme: str\n        :param entityIdentValue: Entity identifier value to match\n        :type entityIdentValue: str\n        :param periodType: Period type to match ("instant", "duration", or "forever")\n        :type periodType: str\n        :param periodStart: Date or dateTime of period start\n        :type periodStart: ModelValue.DateTime, datetime.date or datetime.datetime\n        :param periodEndInstant: Date or dateTime of period send\n        :type periodEndInstant: ModelValue.DateTime, datetime.date or datetime.datetime\n        :param dims: Dimensions\n        :type dims: ModelDimension or QName\n        :param segOCCs: Segment non-dimensional nodes\n        :type segOCCs: lxml element\n        :param scenOCCs: Scenario non-dimensional nodes\n        :type scenOCCs: lxml element\n        :param beforeSibling: lxml element in instance to insert new concept before\n        :type beforeSibling: ModelObject\n        :param afterSibling: lxml element in instance to insert new concept after\n        :type afterSibling: ModelObject\n        :param id: id to assign to new context, if absent an id will be generated\n        :type id: str\n        :returns: ModelContext -- New model context object\n        ' #NEWLINE# xbrlElt = self . modelDocument . xmlRootElement #NEWLINE# if ( afterSibling == AUTO_LOCATE_ELEMENT ) : #NEWLINE# #INDENT# afterSibling = XmlUtil . lastChild ( xbrlElt , XbrlConst . xbrli , ( 'schemaLocation' , 'roleType' , 'arcroleType' , 'context' ) ) #NEWLINE# #UNINDENT# cntxId = ( id if id else 'c-{0:02n}' . format ( ( len ( self . contexts ) + 1 ) ) ) #NEWLINE# newCntxElt = XmlUtil . addChild ( xbrlElt , XbrlConst . xbrli , 'context' , attributes = ( 'id' , cntxId ) , afterSibling = afterSibling , beforeSibling = beforeSibling ) #NEWLINE# entityElt = XmlUtil . addChild ( newCntxElt , XbrlConst . xbrli , 'entity' ) #NEWLINE# XmlUtil . addChild ( entityElt , XbrlConst . xbrli , 'identifier' , attributes = ( 'scheme' , entityIdentScheme ) , text = entityIdentValue ) #NEWLINE# periodElt = XmlUtil . addChild ( newCntxElt , XbrlConst . xbrli , 'period' ) #NEWLINE# if ( periodType == 'forever' ) : #NEWLINE# #INDENT# XmlUtil . addChild ( periodElt , XbrlConst . xbrli , 'forever' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( periodType == 'instant' ) : #NEWLINE# #INDENT# XmlUtil . addChild ( periodElt , XbrlConst . xbrli , 'instant' , text = XmlUtil . dateunionValue ( periodEndInstant , subtractOneDay = True ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( periodType == 'duration' ) : #NEWLINE# #INDENT# XmlUtil . addChild ( periodElt , XbrlConst . xbrli , 'startDate' , text = XmlUtil . dateunionValue ( periodStart ) ) #NEWLINE# XmlUtil . addChild ( periodElt , XbrlConst . xbrli , 'endDate' , text = XmlUtil . dateunionValue ( periodEndInstant , subtractOneDay = True ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# segmentElt = None #NEWLINE# scenarioElt = None #NEWLINE# from arelle.ModelInstanceObject import ModelDimensionValue #NEWLINE# if dims : #NEWLINE# #INDENT# ' in theory we have to check full set of dimensions for validity in source or any other\n                context element, but for shortcut will see if each dimension is already reported in an\n                unambiguous valid contextElement\n            ' #NEWLINE# if ( priItem is not None ) : #NEWLINE# #INDENT# dims [ 2 ] = priItem #NEWLINE# fp = FactPrototype ( self , dims ) #NEWLINE# del dims [ 2 ] #NEWLINE# if ( not isFactDimensionallyValid ( self , fp , setPrototypeContextElements = True ) ) : #NEWLINE# #INDENT# self . info ( 'arelle:info' , _ ( 'Create context for %(priItem)s, cannot determine valid context elements, no suitable hypercubes' ) , modelObject = self , priItem = priItem ) #NEWLINE# #UNINDENT# fpDims = fp . context . qnameDims #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fpDims = dims #NEWLINE# #UNINDENT# for dimQname in sorted ( fpDims . keys ( ) ) : #NEWLINE# #INDENT# dimValue = fpDims [ dimQname ] #NEWLINE# if isinstance ( dimValue , ( DimValuePrototype , ModelDimensionValue ) ) : #NEWLINE# #INDENT# dimMemberQname = dimValue . memberQname #NEWLINE# contextEltName = dimValue . contextElement #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dimMemberQname = None #NEWLINE# contextEltName = None #NEWLINE# #UNINDENT# if ( contextEltName == 'segment' ) : #NEWLINE# #INDENT# if ( segmentElt is None ) : #NEWLINE# #INDENT# segmentElt = XmlUtil . addChild ( entityElt , XbrlConst . xbrli , 'segment' ) #NEWLINE# #UNINDENT# contextElt = segmentElt #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( contextEltName == 'scenario' ) : #NEWLINE# #INDENT# if ( scenarioElt is None ) : #NEWLINE# #INDENT# scenarioElt = XmlUtil . addChild ( newCntxElt , XbrlConst . xbrli , 'scenario' ) #NEWLINE# #UNINDENT# contextElt = scenarioElt #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( self . info ( 'arelleLinfo' , _ ( 'Create context, %(dimension)s, cannot determine context element, either no all relationship or validation issue' ) , modelObject = self , dimension = dimQname ) , ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# dimAttr = ( 'dimension' , XmlUtil . addQnameValue ( xbrlElt , dimQname ) ) #NEWLINE# if dimValue . isTyped : #NEWLINE# #INDENT# dimElt = XmlUtil . addChild ( contextElt , XbrlConst . xbrldi , 'xbrldi:typedMember' , attributes = dimAttr ) #NEWLINE# if ( isinstance ( dimValue , ( ModelDimensionValue , DimValuePrototype ) ) and dimValue . isTyped ) : #NEWLINE# #INDENT# XmlUtil . copyNodes ( dimElt , dimValue . typedMember ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if dimMemberQname : #NEWLINE# #INDENT# dimElt = XmlUtil . addChild ( contextElt , XbrlConst . xbrldi , 'xbrldi:explicitMember' , attributes = dimAttr , text = XmlUtil . addQnameValue ( xbrlElt , dimMemberQname ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if segOCCs : #NEWLINE# #INDENT# if ( segmentElt is None ) : #NEWLINE# #INDENT# segmentElt = XmlUtil . addChild ( entityElt , XbrlConst . xbrli , 'segment' ) #NEWLINE# #UNINDENT# XmlUtil . copyNodes ( segmentElt , segOCCs ) #NEWLINE# #UNINDENT# if scenOCCs : #NEWLINE# #INDENT# if ( scenarioElt is None ) : #NEWLINE# #INDENT# scenarioElt = XmlUtil . addChild ( newCntxElt , XbrlConst . xbrli , 'scenario' ) #NEWLINE# #UNINDENT# XmlUtil . copyNodes ( scenarioElt , scenOCCs ) #NEWLINE# #UNINDENT# XmlValidate . validate ( self , newCntxElt ) #NEWLINE# self . modelDocument . contextDiscover ( newCntxElt ) #NEWLINE# return newCntxElt