Пример #1
0
def loadUtr(modelManager): # Build a dictionary of item types that are constrained by the UTR
    utrItemTypeEntries = defaultdict(dict)
    # print('UTR LOADED FROM '+utrUrl);
    modelManager.cntlr.showStatus(_("Loading Unit Type Registry"))
    file = None
    try:
        from arelle.FileSource import openXmlFileStream
        # normalize any relative paths to config directory
        file = openXmlFileStream(modelManager.cntlr, modelManager.disclosureSystem.utrUrl, stripDeclaration=True)[0]
        xmldoc = etree.parse(file)
        for unitElt in xmldoc.iter(tag="{http://www.xbrl.org/2009/utr}unit"):
            u = UtrEntry()
            u.id = unitElt.get("id")
            u.unitId = unitElt.findtext("{http://www.xbrl.org/2009/utr}unitId")
            u.nsUnit = (unitElt.findtext("{http://www.xbrl.org/2009/utr}nsUnit") or None) # None if empty entry
            u.itemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}itemType")
            u.nsItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}nsItemType")
            u.numeratorItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}numeratorItemType")
            u.nsNumeratorItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}nsNumeratorItemType")
            u.denominatorItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}denominatorItemType")
            u.nsDenominatorItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}nsDenominatorItemType")
            u.isSimple = u.numeratorItemType is None and u.denominatorItemType is None
            # TO DO: This indexing scheme assumes that there are no name clashes in item types of the registry.
            (utrItemTypeEntries[u.itemType])[u.id] = u
        modelManager.disclosureSystem.utrItemTypeEntries = utrItemTypeEntries  
    except (EnvironmentError,
            etree.LxmlError) as err:
        modelManager.cntlr.addToLog("Unit Type Registry Import error: {0}".format(err))
        etree.clear_error_log()
    if file:
        file.close()
Пример #2
0
def loadUtr(
    modelManager
):  # Build a dictionary of item types that are constrained by the UTR
    modelManager.disclosureSystem.utrItemTypeEntries = utrItemTypeEntries = defaultdict(
        dict)
    # print('UTR LOADED FROM '+utrUrl);
    # skip status message as it hides prior activity during which this might have just obtained symbols
    # modelManager.cntlr.showStatus(_("Loading Unit Type Registry"))
    file = None
    try:
        from arelle.FileSource import openXmlFileStream
        # normalize any relative paths to config directory
        file = openXmlFileStream(modelManager.cntlr,
                                 modelManager.disclosureSystem.utrUrl,
                                 stripDeclaration=True)[0]
        xmldoc = etree.parse(file)
        for unitElt in xmldoc.iter(tag="{http://www.xbrl.org/2009/utr}unit"):
            u = UtrEntry()
            u.id = unitElt.get("id")
            u.unitId = unitElt.findtext("{http://www.xbrl.org/2009/utr}unitId")
            u.nsUnit = (
                unitElt.findtext("{http://www.xbrl.org/2009/utr}nsUnit")
                or None)  # None if empty entry
            u.itemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}itemType")
            u.nsItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}nsItemType")
            u.numeratorItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}numeratorItemType")
            u.nsNumeratorItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}nsNumeratorItemType")
            u.denominatorItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}denominatorItemType")
            u.nsDenominatorItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}nsDenominatorItemType")
            u.isSimple = u.numeratorItemType is None and u.denominatorItemType is None
            u.symbol = unitElt.findtext("{http://www.xbrl.org/2009/utr}symbol")
            # TO DO: This indexing scheme assumes that there are no name clashes in item types of the registry.
            (utrItemTypeEntries[u.itemType])[u.id] = u
    except (EnvironmentError, etree.LxmlError) as err:
        modelManager.cntlr.addToLog(
            "Unit Type Registry Import error: {0}".format(err))
        etree.clear_error_log()
    if file:
        file.close()
Пример #3
0
    def loadStandardTaxonomiesDict(self):
        if self.selection:
            self.standardTaxonomiesDict = defaultdict(set)
            self.familyHrefs = defaultdict(set)
            self.standardLocalHrefs = defaultdict(set)
            self.standardAuthorities = set()
            self.standardPrefixes = {}
            if not self.standardTaxonomiesUrl:
                return
            basename = os.path.basename(self.standardTaxonomiesUrl)
            self.modelManager.cntlr.showStatus(_("parsing {0}").format(basename))
            file = None
            try:
                from arelle.FileSource import openXmlFileStream
                for filepath in (self.standardTaxonomiesUrl, 
                                 os.path.join(self.modelManager.cntlr.configDir,"xbrlschemafiles.xml")):
                    file = openXmlFileStream(self.modelManager.cntlr, filepath, stripDeclaration=True)[0]
                    xmldoc = etree.parse(file)
                    file.close()
                    for locElt in xmldoc.iter(tag="Loc"):
                        href = None
                        localHref = None
                        namespaceUri = None
                        prefix = None
                        attType = None
                        family = None
                        elements = None
                        version = None
                        for childElt in locElt.iterchildren():
                            ln = childElt.tag
                            value = childElt.text.strip()
                            if ln == "Href":
                                href = value
                            elif ln == "LocalHref":
                                localHref = value
                            elif ln == "Namespace":
                                namespaceUri = value
                            elif ln == "Prefix":
                                prefix = value
                            elif ln == "AttType":
                                attType = value
                            elif ln == "Family":
                                family = value
                            elif ln == "Elements":
                                elements = value
                            elif ln == "Version":
                                version = value
                        if href:
                            if namespaceUri and (attType == "SCH" or attType == "ENT"):
                                self.standardTaxonomiesDict[namespaceUri].add(href)
                                if localHref:
                                    self.standardLocalHrefs[namespaceUri].add(localHref)
                                authority = UrlUtil.authority(namespaceUri)
                                self.standardAuthorities.add(authority)
                                if family == "BASE":
                                    self.baseTaxonomyNamespaces.add(namespaceUri)
                                if prefix:
                                    self.standardPrefixes[namespaceUri] = prefix
                            if href not in self.standardTaxonomiesDict:
                                self.standardTaxonomiesDict[href] = "Allowed" + attType
                            if family:
                                self.familyHrefs[family].add(ErxlLoc(family, version, href, attType, elements, namespaceUri))
                        elif attType == "SCH" and family == "BASE":
                            self.baseTaxonomyNamespaces.add(namespaceUri)

            except (EnvironmentError,
                    etree.LxmlError) as err:
                self.modelManager.cntlr.addToLog("{0}: import error: {1}".format(basename,err))
                etree.clear_error_log()
                if file:
                    file.close()
Пример #4
0
def loadUtr(
    modelXbrl
):  # Build a dictionary of item types that are constrained by the UTR
    modelManager = modelXbrl.modelManager
    modelManager.disclosureSystem.utrItemTypeEntries = utrItemTypeEntries = defaultdict(
        dict)
    # print('UTR LOADED FROM '+utrUrl);
    # skip status message as it hides prior activity during which this might have just obtained symbols
    # modelManager.cntlr.showStatus(_("Loading Unit Type Registry"))
    file = None
    try:
        from arelle.FileSource import openXmlFileStream
        # normalize any relative paths to config directory
        unitDupCheck = set()
        file = openXmlFileStream(modelManager.cntlr,
                                 modelManager.disclosureSystem.utrUrl,
                                 stripDeclaration=True)[0]
        xmldoc = etree.parse(file)
        for unitElt in xmldoc.iter(tag="{http://www.xbrl.org/2009/utr}unit"):
            u = UtrEntry()
            u.id = unitElt.get("id")
            u.unitId = unitElt.findtext("{http://www.xbrl.org/2009/utr}unitId")
            u.nsUnit = (
                unitElt.findtext("{http://www.xbrl.org/2009/utr}nsUnit")
                or None)  # None if empty entry
            u.itemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}itemType")
            u.nsItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}nsItemType")
            u.numeratorItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}numeratorItemType")
            u.nsNumeratorItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}nsNumeratorItemType")
            u.denominatorItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}denominatorItemType")
            u.nsDenominatorItemType = unitElt.findtext(
                "{http://www.xbrl.org/2009/utr}nsDenominatorItemType")
            u.isSimple = all(
                e is None
                for e in (u.numeratorItemType, u.nsNumeratorItemType,
                          u.denominatorItemType, u.nsDenominatorItemType))
            u.symbol = unitElt.findtext("{http://www.xbrl.org/2009/utr}symbol")
            u.status = unitElt.findtext("{http://www.xbrl.org/2009/utr}status")
            if u.status == "REC":
                # TO DO: This indexing scheme assumes that there are no name clashes in item types of the registry.
                (utrItemTypeEntries[u.itemType])[u.id] = u
            unitDupKey = (u.unitId, u.nsUnit, u.status)
            if unitDupKey in unitDupCheck:
                modelXbrl.error(
                    "arelleUtrLoader:entryDuplication",
                    "Unit Type Registry entry duplication: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                    modelObject=modelXbrl,
                    id=u.id,
                    unitId=u.unitId,
                    nsUnit=u.nsUnit,
                    status=u.status)
            unitDupCheck.add(unitDupKey)
            if u.isSimple:
                if not u.itemType:
                    modelXbrl.error(
                        "arelleUtrLoader:simpleDefMissingField",
                        "Unit Type Registry simple unit definition missing item type: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                        modelObject=modelXbrl,
                        id=u.id,
                        unitId=u.unitId,
                        nsUnit=u.nsUnit,
                        status=u.status)
                if u.numeratorItemType or u.denominatorItemType or u.nsNumeratorItemType or u.nsDenominatorItemType:
                    modelXbrl.error(
                        "arelleUtrLoader",
                        "Unit Type Registry simple unit definition may not have complex fields: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                        modelObject=modelXbrl,
                        id=u.id,
                        unitId=u.unitId,
                        nsUnit=u.nsUnit,
                        status=u.status)
            else:
                if u.symbol:
                    modelXbrl.error(
                        "arelleUtrLoader:complexDefSymbol",
                        "Unit Type Registry complex unit definition may not have symbol: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                        modelObject=modelXbrl,
                        id=u.id,
                        unitId=u.unitId,
                        nsUnit=u.nsUnit,
                        status=u.status)
                if not u.numeratorItemType or not u.denominatorItemType:
                    modelXbrl.error(
                        "arelleUtrLoader:complexDefMissingField",
                        "Unit Type Registry complex unit definition must have numerator and denominator fields: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                        modelObject=modelXbrl,
                        id=u.id,
                        unitId=u.unitId,
                        nsUnit=u.nsUnit,
                        status=u.status)
    except (EnvironmentError, etree.LxmlError) as err:
        modelManager.modelXbrl.error(
            "arelleUtrLoader:error",
            "Unit Type Registry Import error: %(error)s",
            modelObject=modelXbrl,
            error=err)
        etree.clear_error_log()
    if file:
        file.close()
Пример #5
0
    def loadStandardTaxonomiesDict(self):
        if self.selection:
            self.standardTaxonomiesDict = defaultdict(set)
            self.familyHrefs = defaultdict(set)
            self.standardLocalHrefs = defaultdict(set)
            self.standardAuthorities = set()
            self.standardPrefixes = {}
            if not self.standardTaxonomiesUrl:
                return
            basename = os.path.basename(self.standardTaxonomiesUrl)
            self.modelManager.cntlr.showStatus(
                _("parsing {0}").format(basename))
            file = None
            try:
                from arelle.FileSource import openXmlFileStream
                for filepath in (self.standardTaxonomiesUrl,
                                 os.path.join(
                                     self.modelManager.cntlr.configDir,
                                     "xbrlschemafiles.xml")):
                    file = openXmlFileStream(self.modelManager.cntlr,
                                             filepath,
                                             stripDeclaration=True)[0]
                    xmldoc = etree.parse(file)
                    file.close()
                    for erxlElt in xmldoc.iter(tag="Erxl"):
                        v = erxlElt.get("version")
                        if v and re.match(r"[0-9]+([.][0-9]+)*$", v):
                            vSplit = v.split('.')  # at least 3 digits always!
                            self.version = tuple(
                                int(n) for n in vSplit) + tuple(
                                    0 for n in range(3 - len(vSplit)))
                        break
                    for locElt in xmldoc.iter(tag="Loc"):
                        href = None
                        localHref = None
                        namespaceUri = None
                        prefix = None
                        attType = None
                        family = None
                        elements = None
                        version = None
                        for childElt in locElt.iterchildren():
                            ln = childElt.tag
                            value = childElt.text.strip()
                            if ln == "Href":
                                href = value
                            elif ln == "LocalHref":
                                localHref = value
                            elif ln == "Namespace":
                                namespaceUri = value
                            elif ln == "Prefix":
                                prefix = value
                            elif ln == "AttType":
                                attType = value
                            elif ln == "Family":
                                family = value
                            elif ln == "Elements":
                                elements = value
                            elif ln == "Version":
                                version = value
                        if href:
                            if namespaceUri and (attType == "SCH"
                                                 or attType == "ENT"):
                                self.standardTaxonomiesDict[namespaceUri].add(
                                    href)
                                if localHref:
                                    self.standardLocalHrefs[namespaceUri].add(
                                        localHref)
                                authority = UrlUtil.authority(namespaceUri)
                                self.standardAuthorities.add(authority)
                                if family == "BASE":
                                    self.baseTaxonomyNamespaces.add(
                                        namespaceUri)
                                if prefix:
                                    self.standardPrefixes[
                                        namespaceUri] = prefix
                            if href not in self.standardTaxonomiesDict:
                                self.standardTaxonomiesDict[
                                    href] = "Allowed" + attType
                            if family:
                                self.familyHrefs[family].add(
                                    ErxlLoc(family, version, href, attType,
                                            elements, namespaceUri))
                        elif attType == "SCH" and family == "BASE":
                            self.baseTaxonomyNamespaces.add(namespaceUri)

            except (EnvironmentError, etree.LxmlError) as err:
                self.modelManager.cntlr.addToLog(
                    "{0}: import error: {1}".format(basename, err))
                etree.clear_error_log()
                if file:
                    file.close()
Пример #6
0
    def loadStandardTaxonomiesDict(self):
        if self.selection:
            self.standardTaxonomiesDict = defaultdict(set)
            self.standardLocalHrefs = defaultdict(set)
            self.standardAuthorities = set()
            if not self.standardTaxonomiesUrl:
                return
            basename = os.path.basename(self.standardTaxonomiesUrl)
            self.modelManager.cntlr.showStatus(
                _("parsing {0}").format(basename))
            file = None
            try:
                from arelle.FileSource import openXmlFileStream
                for filepath in (self.standardTaxonomiesUrl,
                                 os.path.join(
                                     self.modelManager.cntlr.configDir,
                                     "xbrlschemafiles.xml")):
                    file = openXmlFileStream(self.modelManager.cntlr,
                                             filepath,
                                             stripDeclaration=True)[0]
                    xmldoc = etree.parse(file)
                    file.close()
                    for locElt in xmldoc.iter(tag="Loc"):
                        href = None
                        localHref = None
                        namespaceUri = None
                        attType = None
                        family = None
                        for childElt in locElt.iterchildren():
                            ln = childElt.tag
                            value = childElt.text.strip()
                            if ln == "Href":
                                href = value
                            elif ln == "LocalHref":
                                localHref = value
                            elif ln == "Namespace":
                                namespaceUri = value
                            elif ln == "AttType":
                                attType = value
                            elif ln == "Family":
                                family = value
                        if href:
                            if namespaceUri and (attType == "SCH"
                                                 or attType == "ENT"):
                                self.standardTaxonomiesDict[namespaceUri].add(
                                    href)
                                if localHref:
                                    self.standardLocalHrefs[namespaceUri].add(
                                        localHref)
                                authority = UrlUtil.authority(namespaceUri)
                                self.standardAuthorities.add(authority)
                                if family == "BASE":
                                    self.baseTaxonomyNamespaces.add(
                                        namespaceUri)
                            if href not in self.standardTaxonomiesDict:
                                self.standardTaxonomiesDict[
                                    href] = "Allowed" + attType
                        elif attType == "SCH" and family == "BASE":
                            self.baseTaxonomyNamespaces.add(namespaceUri)

            except (EnvironmentError, etree.LxmlError) as err:
                self.modelManager.cntlr.addToLog(
                    "{0}: import error: {1}".format(basename, err))
                etree.clear_error_log()
                if file:
                    file.close()
Пример #7
0
def loadUtr(modelXbrl): # Build a dictionary of item types that are constrained by the UTR
    modelManager = modelXbrl.modelManager
    modelManager.disclosureSystem.utrItemTypeEntries = utrItemTypeEntries = defaultdict(dict)
    # print('UTR LOADED FROM '+utrUrl);
    # skip status message as it hides prior activity during which this might have just obtained symbols
    # modelManager.cntlr.showStatus(_("Loading Unit Type Registry"))
    file = None
    try:
        from arelle.FileSource import openXmlFileStream
        # normalize any relative paths to config directory
        unitDupCheck = set()
        file = openXmlFileStream(modelManager.cntlr, modelManager.disclosureSystem.utrUrl, stripDeclaration=True)[0]
        xmldoc = etree.parse(file)
        for unitElt in xmldoc.iter(tag="{http://www.xbrl.org/2009/utr}unit"):
            u = UtrEntry()
            u.id = unitElt.get("id")
            u.unitId = unitElt.findtext("{http://www.xbrl.org/2009/utr}unitId")
            u.nsUnit = (unitElt.findtext("{http://www.xbrl.org/2009/utr}nsUnit") or None) # None if empty entry
            u.itemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}itemType")
            u.nsItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}nsItemType")
            u.numeratorItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}numeratorItemType")
            u.nsNumeratorItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}nsNumeratorItemType")
            u.denominatorItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}denominatorItemType")
            u.nsDenominatorItemType = unitElt.findtext("{http://www.xbrl.org/2009/utr}nsDenominatorItemType")
            u.isSimple = all(e is None for e in (u.numeratorItemType, u.nsNumeratorItemType, u.denominatorItemType, u.nsDenominatorItemType))
            u.symbol = unitElt.findtext("{http://www.xbrl.org/2009/utr}symbol")
            u.status = unitElt.findtext("{http://www.xbrl.org/2009/utr}status")
            if u.status == "REC":
                # TO DO: This indexing scheme assumes that there are no name clashes in item types of the registry.
                (utrItemTypeEntries[u.itemType])[u.id] = u
            unitDupKey = (u.unitId, u.nsUnit, u.status)
            if unitDupKey in unitDupCheck:
                modelXbrl.error("arelleUtrLoader:entryDuplication",
                                "Unit Type Registry entry duplication: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                                modelObject=modelXbrl, id=u.id, unitId=u.unitId, nsUnit=u.nsUnit, status=u.status)
            unitDupCheck.add(unitDupKey)
            if u.isSimple:
                if not u.itemType:
                    modelXbrl.error("arelleUtrLoader:simpleDefMissingField",
                                    "Unit Type Registry simple unit definition missing item type: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                                    modelObject=modelXbrl, id=u.id, unitId=u.unitId, nsUnit=u.nsUnit, status=u.status)
                if u.numeratorItemType or u.denominatorItemType or u.nsNumeratorItemType or u.nsDenominatorItemType:
                    modelXbrl.error("arelleUtrLoader",
                                    "Unit Type Registry simple unit definition may not have complex fields: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                                    modelObject=modelXbrl, id=u.id, unitId=u.unitId, nsUnit=u.nsUnit, status=u.status)
            else:
                if u.symbol:
                    modelXbrl.error("arelleUtrLoader:complexDefSymbol",
                                    "Unit Type Registry complex unit definition may not have symbol: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                                    modelObject=modelXbrl, id=u.id, unitId=u.unitId, nsUnit=u.nsUnit, status=u.status)
                if not u.numeratorItemType or not u.denominatorItemType:
                    modelXbrl.error("arelleUtrLoader:complexDefMissingField",
                                    "Unit Type Registry complex unit definition must have numerator and denominator fields: id %(id)s unit %(unitId)s nsUnit %(nsUnit)s status %(status)s",
                                    modelObject=modelXbrl, id=u.id, unitId=u.unitId, nsUnit=u.nsUnit, status=u.status)
    except (EnvironmentError,
            etree.LxmlError) as err:
        modelManager.modelXbrl.error("arelleUtrLoader:error",
                                     "Unit Type Registry Import error: %(error)s",
                                     modelObject=modelXbrl, error=err)
        etree.clear_error_log()
    if file:
        file.close()