Exemplo n.º 1
0
    def __init__(self, modelXbrl, arcrole, linkrole=None, linkqname=None, arcqname=None, includeProhibits=False):
        self.isChanged = False
        self.modelXbrl = modelXbrl
        self.arcrole = arcrole
        self.linkrole = linkrole
        self.linkqname = linkqname
        self.arcqname = arcqname

        relationshipSetKey = (arcrole, linkrole, linkqname, arcqname, includeProhibits) 
            
        # base sets does not care about the #includeProhibits
        if not isinstance(arcrole,(tuple,frozenset)):
            modelLinks = self.modelXbrl.baseSets.get((arcrole, linkrole, linkqname, arcqname), [])
        else: # arcrole is a set of arcroles
            modelLinks = []
            for ar in arcrole:
                modelLinks.extend(self.modelXbrl.baseSets.get((ar, linkrole, linkqname, arcqname), []))
            
        # gather arcs
        relationships = {}
        isDimensionRel =  self.arcrole == "XBRL-dimensions" # all dimensional relationship arcroles
        isFormulaRel =  self.arcrole == "XBRL-formulae" # all formula relationship arcroles
        isTableRenderingRel = self.arcrole == "Table-rendering"
        isFootnoteRel =  self.arcrole == "XBRL-footnotes" # all footnote relationship arcroles
        if not isinstance(arcrole,(tuple,frozenset)):
            arcrole = (arcrole,)
        
        for modelLink in modelLinks:
            arcs = []
            linkEltQname = modelLink.qname
            for linkChild in modelLink:
                linkChildArcrole = linkChild.get("{http://www.w3.org/1999/xlink}arcrole")
                if linkChild.get("{http://www.w3.org/1999/xlink}type") == "arc" and linkChildArcrole:
                    linkChildQname = linkChild
                    if isFootnoteRel:
                        arcs.append(linkChild)
                    elif isDimensionRel: 
                        if XbrlConst.isDimensionArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isFormulaRel:
                        if XbrlConst.isFormulaArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isTableRenderingRel:
                        if XbrlConst.isTableRenderingArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif (linkChildArcrole in arcrole and 
                          (arcqname is None or arcqname == linkChildQname) and 
                          (linkqname is None or linkqname == linkEltQname)):
                        arcs.append(linkChild)
                        
            # build network
            for arcElement in arcs:
                fromLabel = arcElement.get("{http://www.w3.org/1999/xlink}from")
                toLabel = arcElement.get("{http://www.w3.org/1999/xlink}to")
                for fromResource in modelLink.labeledResources[fromLabel]:
                    for toResource in modelLink.labeledResources[toLabel]:
                        if isinstance(fromResource,ModelResource) and isinstance(toResource,ModelResource):
                            modelRel = ModelDtsObject.ModelRelationship(modelLink.modelDocument, arcElement, fromResource.dereference(), toResource.dereference())
                            modelRelEquivalenceKey = modelRel.equivalenceKey    # this is a complex tuple to compute, get once for below
                            if modelRelEquivalenceKey not in relationships or \
                               modelRel.priorityOver(relationships[modelRelEquivalenceKey]):
                                relationships[modelRelEquivalenceKey] = modelRel

        #reduce effective arcs and order relationships...
        self.modelRelationshipsFrom = None
        self.modelRelationshipsTo = None
        self.modelConceptRoots = None
        self.modellinkRoleUris = None
        orderRels = defaultdict(list)
        for modelRel in relationships.values():
            if includeProhibits or not modelRel.isProhibited:
                orderRels[modelRel.order].append(modelRel)
        self.modelRelationships = [modelRel
                                   for order in sorted(orderRels.keys())
                                   for modelRel in orderRels[order]]
        modelXbrl.relationshipSets[relationshipSetKey] = self
Exemplo n.º 2
0
 def linkbaseDiscover(self, linkbaseElement, inInstance=False):
     for lbElement in linkbaseElement.iterchildren():
         if isinstance(lbElement,ModelObject):
             lbLn = lbElement.localName
             lbNs = lbElement.namespaceURI
             if lbNs == XbrlConst.link:
                 if lbLn == "roleRef" or lbLn == "arcroleRef":
                     href = self.discoverHref(lbElement)
                     if href is None:
                         self.modelXbrl.error("xbrl:hrefMissing",
                                 _("Linkbase reference for %(linkbaseRefElement)s href attribute missing or malformed"),
                                 modelObject=lbElement, linkbaseRefElement=lbLn)
                     else:
                         self.hrefObjects.append(href)
                     continue
             if lbElement.get("{http://www.w3.org/1999/xlink}type") == "extended":
                 if isinstance(lbElement, ModelLink):
                     self.schemalocateElementNamespace(lbElement)
                     arcrolesFound = set()
                     dimensionArcFound = False
                     formulaArcFound = False
                     tableRenderingArcFound = False
                     linkQn = qname(lbElement)
                     linkrole = lbElement.get("{http://www.w3.org/1999/xlink}role")
                     isStandardExtLink = XbrlConst.isStandardResourceOrExtLinkElement(lbElement)
                     if inInstance:
                         #index footnote links even if no arc children
                         baseSetKeys = (("XBRL-footnotes",None,None,None), 
                                        ("XBRL-footnotes",linkrole,None,None))
                         for baseSetKey in baseSetKeys:
                             self.modelXbrl.baseSets[baseSetKey].append(lbElement)
                     for linkElement in lbElement.iterchildren():
                         if isinstance(linkElement,ModelObject):
                             self.schemalocateElementNamespace(linkElement)
                             xlinkType = linkElement.get("{http://www.w3.org/1999/xlink}type")
                             modelResource = None
                             if xlinkType == "locator":
                                 nonDTS = linkElement.namespaceURI != XbrlConst.link or linkElement.localName != "loc"
                                 # only link:loc elements are discovered or processed
                                 href = self.discoverHref(linkElement, nonDTS=nonDTS)
                                 if href is None:
                                     if isStandardExtLink:
                                         self.modelXbrl.error("xbrl:hrefMissing",
                                                 _("Locator href attribute missing or malformed in standard extended link"),
                                                 modelObejct=linkElement)
                                     else:
                                         self.modelXbrl.warning("arelle:hrefWarning",
                                                 _("Locator href attribute missing or malformed in non-standard extended link"),
                                                 modelObejct=linkElement)
                                 else:
                                     linkElement.modelHref = href
                                     modelResource = linkElement
                             elif xlinkType == "arc":
                                 arcQn = qname(linkElement)
                                 arcrole = linkElement.get("{http://www.w3.org/1999/xlink}arcrole")
                                 if arcrole not in arcrolesFound:
                                     if linkrole == "":
                                         linkrole = XbrlConst.defaultLinkRole
                                     #index by both arcrole and linkrole#arcrole and dimensionsions if applicable
                                     baseSetKeys = [(arcrole, linkrole, linkQn, arcQn)]
                                     baseSetKeys.append((arcrole, linkrole, None, None))
                                     baseSetKeys.append((arcrole, None, None, None))
                                     if XbrlConst.isDimensionArcrole(arcrole) and not dimensionArcFound:
                                         baseSetKeys.append(("XBRL-dimensions", None, None, None)) 
                                         baseSetKeys.append(("XBRL-dimensions", linkrole, None, None))
                                         dimensionArcFound = True
                                     if XbrlConst.isFormulaArcrole(arcrole) and not formulaArcFound:
                                         baseSetKeys.append(("XBRL-formulae", None, None, None)) 
                                         baseSetKeys.append(("XBRL-formulae", linkrole, None, None))
                                         formulaArcFound = True
                                     if XbrlConst.isTableRenderingArcrole(arcrole) and not tableRenderingArcFound:
                                         baseSetKeys.append(("Table-rendering", None, None, None)) 
                                         baseSetKeys.append(("Table-rendering", linkrole, None, None)) 
                                         tableRenderingArcFound = True
                                         self.modelXbrl.hasTableRendering = True
                                     for baseSetKey in baseSetKeys:
                                         self.modelXbrl.baseSets[baseSetKey].append(lbElement)
                                     arcrolesFound.add(arcrole)
                             elif xlinkType == "resource": 
                                 # create resource and make accessible by id for document
                                 modelResource = linkElement
                             if modelResource is not None:
                                 lbElement.labeledResources[linkElement.get("{http://www.w3.org/1999/xlink}label")] \
                                     .append(modelResource)
                 else:
                     self.modelXbrl.error("xbrl:schemaDefinitionMissing",
                             _("Linkbase extended link %(element)s missing schema definition"),
                             modelObject=lbElement, element=lbElement.prefixedName)
Exemplo n.º 3
0
    def __init__(self,
                 modelXbrl,
                 arcrole,
                 linkrole=None,
                 linkqname=None,
                 arcqname=None,
                 includeProhibits=False):
        self.isChanged = False
        self.modelXbrl = modelXbrl
        self.arcrole = arcrole  # may be str, tuple or frozenset
        self.linkrole = linkrole  # may be str, tuple or frozenset
        self.linkqname = linkqname
        self.arcqname = arcqname

        relationshipSetKey = (arcrole, linkrole, linkqname, arcqname,
                              includeProhibits)

        # base sets does not care about the #includeProhibits
        if isinstance(arcrole,
                      (str, NoneType)) and isinstance(linkrole,
                                                      (str, NoneType)):
            modelLinks = self.modelXbrl.baseSets.get(
                (arcrole, linkrole, linkqname, arcqname), [])
        else:  # arcrole is a set of arcroles
            modelLinks = []
            for ar in (arcrole, ) if isinstance(arcrole,
                                                (str, NoneType)) else arcrole:
                for lr in (linkrole, ) if isinstance(linkrole,
                                                     (str,
                                                      NoneType)) else linkrole:
                    modelLinks.extend(
                        self.modelXbrl.baseSets.get(
                            (ar, lr, linkqname, arcqname), []))

        # gather arcs
        relationships = {}
        isDimensionRel = self.arcrole == "XBRL-dimensions"  # all dimensional relationship arcroles
        isFormulaRel = self.arcrole == "XBRL-formulae"  # all formula relationship arcroles
        isTableRenderingRel = self.arcrole == "Table-rendering"
        isFootnoteRel = self.arcrole == "XBRL-footnotes"  # all footnote relationship arcroles
        if not isinstance(arcrole, (tuple, frozenset)):
            arcrole = (arcrole, )

        for modelLink in modelLinks:
            arcs = []
            linkEltQname = modelLink.qname
            for linkChild in modelLink:
                linkChildArcrole = linkChild.get(
                    "{http://www.w3.org/1999/xlink}arcrole")
                if linkChild.get("{http://www.w3.org/1999/xlink}type"
                                 ) == "arc" and linkChildArcrole:
                    if isFootnoteRel:  # arcrole is fact-footnote or other custom footnote relationship
                        arcs.append(linkChild)
                    elif isDimensionRel:
                        if XbrlConst.isDimensionArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isFormulaRel:
                        if XbrlConst.isFormulaArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isTableRenderingRel:
                        if XbrlConst.isTableRenderingArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif (linkChildArcrole in arcrole
                          and (arcqname is None or arcqname == linkChild.qname)
                          and
                          (linkqname is None or linkqname == linkEltQname)):
                        arcs.append(linkChild)

            # build network
            for arcElement in arcs:
                fromLabel = arcElement.get(
                    "{http://www.w3.org/1999/xlink}from")
                toLabel = arcElement.get("{http://www.w3.org/1999/xlink}to")
                for fromResource in modelLink.labeledResources[fromLabel]:
                    for toResource in modelLink.labeledResources[toLabel]:
                        if isinstance(
                                fromResource,
                            (ModelResource, LocPrototype)) and isinstance(
                                toResource, (ModelResource, LocPrototype)):
                            modelRel = ModelDtsObject.ModelRelationship(
                                modelLink.modelDocument, arcElement,
                                fromResource.dereference(),
                                toResource.dereference())
                            modelRelEquivalenceHash = modelRel.equivalenceHash
                            if modelRelEquivalenceHash not in relationships:
                                relationships[
                                    modelRelEquivalenceHash] = modelRel
                            else:  # use equivalenceKey instead of hash
                                otherRel = relationships[
                                    modelRelEquivalenceHash]
                                if otherRel is not USING_EQUIVALENCE_KEY:  # move equivalentRel to use key instead of hasn
                                    if modelRel.isIdenticalTo(otherRel):
                                        continue  # skip identical arc
                                    relationships[
                                        otherRel.equivalenceKey] = otherRel
                                    relationships[
                                        modelRelEquivalenceHash] = USING_EQUIVALENCE_KEY
                                modelRelEquivalenceKey = modelRel.equivalenceKey  # this is a complex tuple to compute, get once for below
                                if modelRelEquivalenceKey not in relationships or \
                                   modelRel.priorityOver(relationships[modelRelEquivalenceKey]):
                                    relationships[
                                        modelRelEquivalenceKey] = modelRel

        #reduce effective arcs and order relationships...
        self.modelRelationshipsFrom = None
        self.modelRelationshipsTo = None
        self.modelConceptRoots = None
        self.modellinkRoleUris = None
        orderRels = defaultdict(list)
        for modelRel in relationships.values():
            if (modelRel is not USING_EQUIVALENCE_KEY
                    and (includeProhibits or not modelRel.isProhibited)):
                orderRels[modelRel.order].append(modelRel)
        self.modelRelationships = [
            modelRel for order in sorted(orderRels.keys())
            for modelRel in orderRels[order]
        ]
        modelXbrl.relationshipSets[relationshipSetKey] = self
Exemplo n.º 4
0
    def __init__(self,
                 modelXbrl,
                 arcrole,
                 linkrole=None,
                 linkqname=None,
                 arcqname=None,
                 includeProhibits=False):
        self.isChanged = False
        self.modelXbrl = modelXbrl
        self.arcrole = arcrole
        self.linkrole = linkrole
        self.linkqname = linkqname
        self.arcqname = arcqname

        baseSetKey = (arcrole, linkrole, linkqname, arcqname)
        relationshipSetKey = (arcrole, linkrole, linkqname, arcqname,
                              includeProhibits)

        # base sets does not care about the #includeProhibits
        if baseSetKey in self.modelXbrl.baseSets:
            modelLinks = self.modelXbrl.baseSets[baseSetKey]
        else:
            modelLinks = []

        # gather arcs
        relationships = {}
        isDimensionRel = self.arcrole == "XBRL-dimensions"  # all dimensional relationship arcroles
        isFormulaRel = self.arcrole == "XBRL-formulae"  # all formula relationship arcroles
        isTableRenderingRel = self.arcrole == "Table-rendering"
        isFootnoteRel = self.arcrole == "XBRL-footnotes"  # all footnote relationship arcroles

        for modelLink in modelLinks:
            arcs = []
            linkEltQname = modelLink.qname
            for linkChild in modelLink:
                linkChildArcrole = linkChild.get(
                    "{http://www.w3.org/1999/xlink}arcrole")
                if linkChild.get("{http://www.w3.org/1999/xlink}type"
                                 ) == "arc" and linkChildArcrole:
                    linkChildQname = linkChild
                    if isFootnoteRel:
                        arcs.append(linkChild)
                    elif isDimensionRel:
                        if XbrlConst.isDimensionArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isFormulaRel:
                        if XbrlConst.isFormulaArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isTableRenderingRel:
                        if XbrlConst.isTableRenderingArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif arcrole == linkChildArcrole and \
                         (arcqname is None or arcqname == linkChildQname) and \
                         (linkqname is None or linkqname == linkEltQname):
                        arcs.append(linkChild)

            # build network
            for arcElement in arcs:
                arcrole = arcElement.get(
                    "{http://www.w3.org/1999/xlink}arcrole")
                fromLabel = arcElement.get(
                    "{http://www.w3.org/1999/xlink}from")
                toLabel = arcElement.get("{http://www.w3.org/1999/xlink}to")
                for fromResource in modelLink.labeledResources[fromLabel]:
                    for toResource in modelLink.labeledResources[toLabel]:
                        if isinstance(fromResource,
                                      ModelResource) and isinstance(
                                          toResource, ModelResource):
                            modelRel = ModelDtsObject.ModelRelationship(
                                modelLink.modelDocument, arcElement,
                                fromResource.dereference(),
                                toResource.dereference())
                            modelRelEquivalenceKey = modelRel.equivalenceKey  # this is a complex tuple to compute, get once for below
                            if modelRelEquivalenceKey not in relationships or \
                               modelRel.priorityOver(relationships[modelRelEquivalenceKey]):
                                relationships[
                                    modelRelEquivalenceKey] = modelRel

        #reduce effective arcs and order relationships...
        self.modelRelationshipsFrom = None
        self.modelRelationshipsTo = None
        self.modelConceptRoots = None
        self.modellinkRoleUris = None
        orderRels = defaultdict(list)
        for modelRel in relationships.values():
            if includeProhibits or not modelRel.isProhibited:
                orderRels[modelRel.order].append(modelRel)
        self.modelRelationships = [
            modelRel for order in sorted(orderRels.keys())
            for modelRel in orderRels[order]
        ]
        modelXbrl.relationshipSets[relationshipSetKey] = self
Exemplo n.º 5
0
    def __init__(self, modelXbrl, arcrole, linkrole=None, linkqname=None, arcqname=None, includeProhibits=False):
        self.isChanged = False
        self.modelXbrl = modelXbrl
        self.arcrole = arcrole
        self.linkrole = linkrole
        self.linkqname = linkqname
        self.arcqname = arcqname

        baseSetKey = (arcrole, linkrole, linkqname, arcqname)
        relationshipSetKey = (arcrole, linkrole, linkqname, arcqname, includeProhibits)

        # base sets does not care about the #includeProhibits
        if baseSetKey in self.modelXbrl.baseSets:
            modelLinks = self.modelXbrl.baseSets[baseSetKey]
        else:
            modelLinks = []

        # gather arcs
        relationships = {}
        isDimensionRel = self.arcrole == "XBRL-dimensions"  # all dimensional relationship arcroles
        isFormulaRel = self.arcrole == "XBRL-formulae"  # all formula relationship arcroles
        isEuRenderingRel = self.arcrole == "EU-rendering"
        isFootnoteRel = self.arcrole == "XBRL-footnotes"  # all footnote relationship arcroles

        for modelLink in modelLinks:
            arcs = []
            linkEltQname = modelLink.qname
            for linkChild in modelLink.element.childNodes:
                if (
                    linkChild.nodeType == 1
                    and linkChild.getAttributeNS(XbrlConst.xlink, "type") == "arc"
                    and linkChild.hasAttributeNS(XbrlConst.xlink, "arcrole")
                ):
                    linkChildArcrole = linkChild.getAttributeNS(XbrlConst.xlink, "arcrole")
                    linkChildQname = linkChild
                    if isFootnoteRel:
                        arcs.append(linkChild)
                    elif isDimensionRel:
                        if XbrlConst.isDimensionArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isFormulaRel:
                        if XbrlConst.isFormulaArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isEuRenderingRel:
                        if XbrlConst.isEuRenderingArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif (
                        arcrole == linkChildArcrole
                        and (arcqname is None or arcqname == linkChildQname)
                        and (linkqname is None or linkqname == linkEltQname)
                    ):
                        arcs.append(linkChild)

            # build network
            for arcElement in arcs:
                arcrole = arcElement.getAttributeNS(XbrlConst.xlink, "arcrole")
                fromLabel = arcElement.getAttributeNS(XbrlConst.xlink, "from")
                toLabel = arcElement.getAttributeNS(XbrlConst.xlink, "to")
                for fromResource in modelLink.labeledResources[fromLabel]:
                    for toResource in modelLink.labeledResources[toLabel]:
                        modelRel = ModelObject.createRelationship(
                            modelLink.modelDocument, arcElement, fromResource.dereference(), toResource.dereference()
                        )
                        modelRelEquivalenceKey = (
                            modelRel.equivalenceKey
                        )  # this is a complex tuple to compute, get once for below
                        if modelRelEquivalenceKey not in relationships or modelRel.priorityOver(
                            relationships[modelRelEquivalenceKey]
                        ):
                            relationships[modelRelEquivalenceKey] = modelRel

        # reduce effective arcs and order relationships...
        self.modelRelationships = []
        self.modelRelationshipsFrom = None
        self.modelRelationshipsTo = None
        self.modelConceptRoots = None
        self.modellinkRoleUris = None
        orderRels = defaultdict(list)
        for modelRel in relationships.values():
            if includeProhibits or not modelRel.isProhibited:
                orderRels[modelRel.order].append(modelRel)
        for order in sorted(orderRels.keys()):
            for modelRel in orderRels[order]:
                self.modelRelationships.append(modelRel)
        modelXbrl.relationshipSets[relationshipSetKey] = self
Exemplo n.º 6
0
 def linkbaseDiscover(self, linkbaseElement, inInstance=False):
     for lbElement in linkbaseElement.childNodes:
         if lbElement.nodeType == 1: #element
             lbLn = lbElement.localName
             lbNs = lbElement.namespaceURI
             if lbNs == XbrlConst.link:
                 if lbLn == "roleRef" or lbLn == "arcroleRef":
                     href = self.discoverHref(lbElement)
                     if href is None:
                         self.modelXbrl.error(
                                 "Linkbase in {0} {1} href attribute missing or malformed".format(
                                   os.path.basename(self.uri),
                                   lbLn),
                                 "err", "xbrl:hrefMissing")
                     else:
                         self.hrefObjects.append(href)
                     continue
             if lbElement.getAttributeNS(XbrlConst.xlink, "type") == "extended":
                 self.schemalocateElementNamespace(lbElement)
                 arcrolesFound = set()
                 dimensionArcFound = False
                 formulaArcFound = False
                 euRenderingArcFound = False
                 linkQn = qname(lbElement)
                 linkrole = lbElement.getAttributeNS(XbrlConst.xlink, "role")
                 modelLink = ModelObject.createLink(self, lbElement)
                 if inInstance:
                     #index footnote links even if no arc children
                     baseSetKeys = (("XBRL-footnotes",None,None,None), 
                                    ("XBRL-footnotes",linkrole,None,None))
                     for baseSetKey in baseSetKeys:
                         self.modelXbrl.baseSets[baseSetKey].append(modelLink)
                 for linkElement in lbElement.childNodes:
                     if linkElement.nodeType == 1: #element
                         self.schemalocateElementNamespace(linkElement)
                         xlinkType = linkElement.getAttributeNS(XbrlConst.xlink, "type")
                         modelResource = None
                         if xlinkType == "locator":
                             nonDTS = linkElement.namespaceURI != XbrlConst.link or linkElement.localName != "loc"
                             # only link:loc elements are discovered or processed
                             href = self.discoverHref(linkElement, nonDTS=nonDTS)
                             if href is None:
                                 self.modelXbrl.error(
                                         "Linkbase in {0} {1} href attribute missing or malformed".format(
                                           os.path.basename(self.uri),
                                           lbLn),
                                         "err", "xbrl:hrefMissing")
                             else:
                                 modelResource = ModelObject.createLocator(self, linkElement, href)
                         elif xlinkType == "arc":
                             arcQn = qname(linkElement)
                             arcrole = linkElement.getAttributeNS(XbrlConst.xlink, "arcrole")
                             if arcrole not in arcrolesFound:
                                 if linkrole == "":
                                     linkrole = XbrlConst.defaultLinkRole
                                 #index by both arcrole and linkrole#arcrole and dimensionsions if applicable
                                 baseSetKeys = [(arcrole, linkrole, linkQn, arcQn)]
                                 baseSetKeys.append((arcrole, linkrole, None, None))
                                 baseSetKeys.append((arcrole, None, None, None))
                                 if XbrlConst.isDimensionArcrole(arcrole) and not dimensionArcFound:
                                     baseSetKeys.append(("XBRL-dimensions", None, None, None)) 
                                     baseSetKeys.append(("XBRL-dimensions", linkrole, None, None))
                                     dimensionArcFound = True
                                 if XbrlConst.isFormulaArcrole(arcrole) and not formulaArcFound:
                                     baseSetKeys.append(("XBRL-formulae", None, None, None)) 
                                     baseSetKeys.append(("XBRL-formulae", linkrole, None, None))
                                     formulaArcFound = True
                                 if XbrlConst.isEuRenderingArcrole(arcrole) and not euRenderingArcFound:
                                     baseSetKeys.append(("EU-rendering", None, None, None)) 
                                     baseSetKeys.append(("EU-rendering", linkrole, None, None)) 
                                     euRenderingArcFound = True
                                     self.modelXbrl.hasEuRendering = True
                                 for baseSetKey in baseSetKeys:
                                     self.modelXbrl.baseSets[baseSetKey].append(modelLink)
                                 arcrolesFound.add(arcrole)
                         elif xlinkType == "resource": 
                             # create resource and make accessible by id for document
                             modelResource = ModelObject.createResource(self, linkElement)
                         if modelResource is not None:
                             if linkElement.hasAttribute("id"):
                                 self.idObjects[linkElement.getAttribute("id")] = modelResource
                             modelLink.labeledResources[linkElement.getAttributeNS(XbrlConst.xlink, "label")] \
                                 .append(modelResource)
                         else:
                             XmlUtil.markIdAttributes(linkElement)
Exemplo n.º 7
0
 def linkbaseDiscover(self, linkbaseElement, inInstance=False):
     for lbElement in linkbaseElement.iterchildren():
         if isinstance(lbElement, ModelObject):
             lbLn = lbElement.localName
             lbNs = lbElement.namespaceURI
             if lbNs == XbrlConst.link:
                 if lbLn == "roleRef" or lbLn == "arcroleRef":
                     href = self.discoverHref(lbElement)
                     if href is None:
                         self.modelXbrl.error(
                             "xmlSchema:requiredAttribute",
                             _("Linkbase reference for %(linkbaseRefElement)s href attribute missing or malformed"
                               ),
                             modelObject=lbElement,
                             linkbaseRefElement=lbLn)
                     else:
                         self.hrefObjects.append(href)
                     continue
             if lbElement.get(
                     "{http://www.w3.org/1999/xlink}type") == "extended":
                 if isinstance(lbElement, ModelLink):
                     self.schemalocateElementNamespace(lbElement)
                     arcrolesFound = set()
                     dimensionArcFound = False
                     formulaArcFound = False
                     tableRenderingArcFound = False
                     linkQn = qname(lbElement)
                     linkrole = lbElement.get(
                         "{http://www.w3.org/1999/xlink}role")
                     isStandardExtLink = XbrlConst.isStandardResourceOrExtLinkElement(
                         lbElement)
                     if inInstance:
                         #index footnote links even if no arc children
                         baseSetKeys = (("XBRL-footnotes", None, None,
                                         None), ("XBRL-footnotes", linkrole,
                                                 None, None))
                         for baseSetKey in baseSetKeys:
                             self.modelXbrl.baseSets[baseSetKey].append(
                                 lbElement)
                     for linkElement in lbElement.iterchildren():
                         if isinstance(linkElement, ModelObject):
                             self.schemalocateElementNamespace(linkElement)
                             xlinkType = linkElement.get(
                                 "{http://www.w3.org/1999/xlink}type")
                             modelResource = None
                             if xlinkType == "locator":
                                 nonDTS = linkElement.namespaceURI != XbrlConst.link or linkElement.localName != "loc"
                                 # only link:loc elements are discovered or processed
                                 href = self.discoverHref(linkElement,
                                                          nonDTS=nonDTS)
                                 if href is None:
                                     if isStandardExtLink:
                                         self.modelXbrl.error(
                                             "xmlSchema:requiredAttribute",
                                             _("Locator href attribute missing or malformed in standard extended link"
                                               ),
                                             modelObejct=linkElement)
                                     else:
                                         self.modelXbrl.warning(
                                             "arelle:hrefWarning",
                                             _("Locator href attribute missing or malformed in non-standard extended link"
                                               ),
                                             modelObejct=linkElement)
                                 else:
                                     linkElement.modelHref = href
                                     modelResource = linkElement
                             elif xlinkType == "arc":
                                 arcQn = qname(linkElement)
                                 arcrole = linkElement.get(
                                     "{http://www.w3.org/1999/xlink}arcrole"
                                 )
                                 if arcrole not in arcrolesFound:
                                     if linkrole == "":
                                         linkrole = XbrlConst.defaultLinkRole
                                     #index by both arcrole and linkrole#arcrole and dimensionsions if applicable
                                     baseSetKeys = [(arcrole, linkrole,
                                                     linkQn, arcQn)]
                                     baseSetKeys.append(
                                         (arcrole, linkrole, None, None))
                                     baseSetKeys.append(
                                         (arcrole, None, None, None))
                                     if XbrlConst.isDimensionArcrole(
                                             arcrole
                                     ) and not dimensionArcFound:
                                         baseSetKeys.append(
                                             ("XBRL-dimensions", None, None,
                                              None))
                                         baseSetKeys.append(
                                             ("XBRL-dimensions", linkrole,
                                              None, None))
                                         dimensionArcFound = True
                                     if XbrlConst.isFormulaArcrole(
                                             arcrole
                                     ) and not formulaArcFound:
                                         baseSetKeys.append(
                                             ("XBRL-formulae", None, None,
                                              None))
                                         baseSetKeys.append(
                                             ("XBRL-formulae", linkrole,
                                              None, None))
                                         formulaArcFound = True
                                     if XbrlConst.isTableRenderingArcrole(
                                             arcrole
                                     ) and not tableRenderingArcFound:
                                         baseSetKeys.append(
                                             ("Table-rendering", None, None,
                                              None))
                                         baseSetKeys.append(
                                             ("Table-rendering", linkrole,
                                              None, None))
                                         tableRenderingArcFound = True
                                         self.modelXbrl.hasTableRendering = True
                                     for baseSetKey in baseSetKeys:
                                         self.modelXbrl.baseSets[
                                             baseSetKey].append(lbElement)
                                     arcrolesFound.add(arcrole)
                             elif xlinkType == "resource":
                                 # create resource and make accessible by id for document
                                 modelResource = linkElement
                             if modelResource is not None:
                                 lbElement.labeledResources[linkElement.get("{http://www.w3.org/1999/xlink}label")] \
                                     .append(modelResource)
                 else:
                     self.modelXbrl.error(
                         "xbrl:schemaDefinitionMissing",
                         _("Linkbase extended link %(element)s missing schema definition"
                           ),
                         modelObject=lbElement,
                         element=lbElement.prefixedName)
Exemplo n.º 8
0
 def linkbaseDiscover(self, linkbaseElement, inInstance=False):
     for lbElement in linkbaseElement.childNodes:
         if lbElement.nodeType == 1:  #element
             lbLn = lbElement.localName
             lbNs = lbElement.namespaceURI
             if lbNs == XbrlConst.link:
                 if lbLn == "roleRef" or lbLn == "arcroleRef":
                     href = self.discoverHref(lbElement)
                     if href is None:
                         self.modelXbrl.error(
                             "Linkbase in {0} {1} href attribute missing or malformed"
                             .format(os.path.basename(self.uri),
                                     lbLn), "err", "xbrl:hrefMissing")
                     else:
                         self.hrefObjects.append(href)
                     continue
             if lbElement.getAttributeNS(XbrlConst.xlink,
                                         "type") == "extended":
                 self.schemalocateElementNamespace(lbElement)
                 arcrolesFound = set()
                 dimensionArcFound = False
                 formulaArcFound = False
                 euRenderingArcFound = False
                 linkQn = qname(lbElement)
                 linkrole = lbElement.getAttributeNS(
                     XbrlConst.xlink, "role")
                 modelLink = ModelObject.createLink(self, lbElement)
                 if inInstance:
                     #index footnote links even if no arc children
                     baseSetKeys = (("XBRL-footnotes", None, None, None),
                                    ("XBRL-footnotes", linkrole, None,
                                     None))
                     for baseSetKey in baseSetKeys:
                         self.modelXbrl.baseSets[baseSetKey].append(
                             modelLink)
                 for linkElement in lbElement.childNodes:
                     if linkElement.nodeType == 1:  #element
                         self.schemalocateElementNamespace(linkElement)
                         xlinkType = linkElement.getAttributeNS(
                             XbrlConst.xlink, "type")
                         modelResource = None
                         if xlinkType == "locator":
                             nonDTS = linkElement.namespaceURI != XbrlConst.link or linkElement.localName != "loc"
                             # only link:loc elements are discovered or processed
                             href = self.discoverHref(linkElement,
                                                      nonDTS=nonDTS)
                             if href is None:
                                 self.modelXbrl.error(
                                     "Linkbase in {0} {1} href attribute missing or malformed"
                                     .format(os.path.basename(self.uri),
                                             lbLn), "err",
                                     "xbrl:hrefMissing")
                             else:
                                 modelResource = ModelObject.createLocator(
                                     self, linkElement, href)
                         elif xlinkType == "arc":
                             arcQn = qname(linkElement)
                             arcrole = linkElement.getAttributeNS(
                                 XbrlConst.xlink, "arcrole")
                             if arcrole not in arcrolesFound:
                                 if linkrole == "":
                                     linkrole = XbrlConst.defaultLinkRole
                                 #index by both arcrole and linkrole#arcrole and dimensionsions if applicable
                                 baseSetKeys = [(arcrole, linkrole, linkQn,
                                                 arcQn)]
                                 baseSetKeys.append(
                                     (arcrole, linkrole, None, None))
                                 baseSetKeys.append(
                                     (arcrole, None, None, None))
                                 if XbrlConst.isDimensionArcrole(
                                         arcrole) and not dimensionArcFound:
                                     baseSetKeys.append(("XBRL-dimensions",
                                                         None, None, None))
                                     baseSetKeys.append(
                                         ("XBRL-dimensions", linkrole, None,
                                          None))
                                     dimensionArcFound = True
                                 if XbrlConst.isFormulaArcrole(
                                         arcrole) and not formulaArcFound:
                                     baseSetKeys.append(("XBRL-formulae",
                                                         None, None, None))
                                     baseSetKeys.append(
                                         ("XBRL-formulae", linkrole, None,
                                          None))
                                     formulaArcFound = True
                                 if XbrlConst.isEuRenderingArcrole(
                                         arcrole
                                 ) and not euRenderingArcFound:
                                     baseSetKeys.append(
                                         ("EU-rendering", None, None, None))
                                     baseSetKeys.append(
                                         ("EU-rendering", linkrole, None,
                                          None))
                                     euRenderingArcFound = True
                                     self.modelXbrl.hasEuRendering = True
                                 for baseSetKey in baseSetKeys:
                                     self.modelXbrl.baseSets[
                                         baseSetKey].append(modelLink)
                                 arcrolesFound.add(arcrole)
                         elif xlinkType == "resource":
                             # create resource and make accessible by id for document
                             modelResource = ModelObject.createResource(
                                 self, linkElement)
                         if modelResource is not None:
                             if linkElement.hasAttribute("id"):
                                 self.idObjects[linkElement.getAttribute(
                                     "id")] = modelResource
                             modelLink.labeledResources[linkElement.getAttributeNS(XbrlConst.xlink, "label")] \
                                 .append(modelResource)
                         else:
                             XmlUtil.markIdAttributes(linkElement)