def createFacts(facts, parent): for fact in facts: if fact.isItem: attrs = {"contextRef": fact.contextID} if fact.id: attrs["id"] = fact.id if fact.isNumeric: attrs["unitRef"] = fact.unitID if fact.get("decimals"): attrs["decimals"] = fact.get("decimals") if fact.get("precision"): attrs["precision"] = fact.get("precision") if fact.isNil: attrs[XbrlConst.qnXsiNil] = "true" text = None else: text = fact.xValue if fact.xValid else fact.textValue newFact = targetInstance.createFact(fact.qname, attributes=attrs, text=text, parent=parent) newFactForOldObjId[fact.objectIndex] = newFact if filingFiles and fact.concept is not None and fact.concept.isTextBlock: # check for img and other filing references for xmltext in [text] + CDATApattern.findall(text): try: for elt in XML("<body>\n{0}\n</body>\n".format(xmltext)): if elt.tag in ("a", "img") and not isHttpUrl(attrValue) and not os.path.isabs(attrvalue): for attrTag, attrValue in elt.items(): if attrTag in ("href", "src"): filingFiles.add(attrValue) except (XMLSyntaxError, UnicodeDecodeError): pass elif fact.isTuple: newTuple = targetInstance.createFact(fact.qname, parent=parent) newFactForOldObjId[fact.objectIndex] = newTuple createFacts(fact.modelTupleFacts, newTuple)
def __init__(self, modelXbrl): self.isInline = modelXbrl.modelDocument.type == ModelDocument.Type.INLINEXBRL self.url = modelXbrl.modelDocument.uri self.basename = modelXbrl.modelDocument.basename for attrName in Report.REPORT_ATTRS: setattr(self, self.lc(attrName), None) self.instanceName = modelXbrl.modelDocument.basename for f in modelXbrl.facts: cntx = f.context if cntx is not None and cntx.isStartEndPeriod and not cntx.hasSegment: if f.qname is not None and f.qname.localName in Report.REPORT_ATTRS and f.xValue: setattr(self, self.lc(f.qname.localName), f.xValue) self.reportedFiles = {modelXbrl.modelDocument.basename} self.renderedFiles = set() self.hasUsGaapTaxonomy = False sourceDir = os.path.dirname(modelXbrl.modelDocument.filepath) # add referenced files that are xbrl-referenced local documents refDocUris = set() def addRefDocs(doc): for refDoc in doc.referencesDocument.keys(): _file = refDoc.filepath if refDoc.uri not in refDocUris: refDocUris.add(refDoc.uri) if refDoc.filepath and refDoc.filepath.startswith(sourceDir): self.reportedFiles.add(refDoc.filepath[len(sourceDir)+1:]) # add file name within source directory addRefDocs(refDoc) if refDoc.type == ModelDocument.Type.SCHEMA and refDoc.targetNamespace: nsAuthority = authority(refDoc.targetNamespace, includeScheme=False) nsPath = refDoc.targetNamespace.split('/') if len(nsPath) > 2: if nsAuthority in ("fasb.org", "xbrl.us") and nsPath[-2] == "us-gaap": self.hasUsGaapTaxonomy = True addRefDocs(modelXbrl.modelDocument) # add referenced files that are html-referenced image and other files def addLocallyReferencedFile(elt): if elt.tag in ("a", "img", "{http://www.w3.org/1999/xhtml}a", "{http://www.w3.org/1999/xhtml}img"): for attrTag, attrValue in elt.items(): if attrTag in ("href", "src") and not isHttpUrl(attrValue) and not os.path.isabs(attrValue): attrValue = attrValue.partition('#')[0] # remove anchor if attrValue: # ignore anchor references to base document attrValue = os.path.normpath(attrValue) # change url path separators to host separators file = os.path.join(sourceDir,attrValue) if modelXbrl.fileSource.isInArchive(file, checkExistence=True) or os.path.exists(file): self.reportedFiles.add(attrValue) # add file name within source directory for fact in modelXbrl.facts: if fact.concept is not None and fact.isItem and fact.concept.isTextBlock: # check for img and other filing references so that referenced files are included in the zip. text = fact.textValue for xmltext in [text] + CDATApattern.findall(text): try: for elt in XML("<body>\n{0}\n</body>\n".format(xmltext)).iter(): addLocallyReferencedFile(elt) except (XMLSyntaxError, UnicodeDecodeError): pass # TODO: Why ignore UnicodeDecodeError? # footnote or other elements for elt in modelXbrl.modelDocument.xmlRootElement.iter("{http://www.w3.org/1999/xhtml}a", "{http://www.w3.org/1999/xhtml}img"): addLocallyReferencedFile(elt)
def createFacts(facts, parent): for fact in facts: if fact.isItem: # HF does not de-duplicate, which is currently-desired behavior modelConcept = fact.concept # isItem ensures concept is not None attrs = {"contextRef": fact.contextID} if fact.id: attrs["id"] = fact.id if fact.isNumeric: attrs["unitRef"] = fact.unitID if fact.get("decimals"): attrs["decimals"] = fact.get("decimals") if fact.get("precision"): attrs["precision"] = fact.get("precision") if fact.isNil: attrs[XbrlConst.qnXsiNil] = "true" text = None elif (not (modelConcept.baseXsdType == "token" and modelConcept.isEnumeration) and fact.xValid): text = fact.xValue # may need a special case for QNames (especially if prefixes defined below root) else: text = fact.textValue for attrName, attrValue in fact.items(): if attrName.startswith("{"): attrs[qname( attrName, fact.nsmap )] = attrValue # using qname allows setting prefix in extracted instance newFact = targetInstance.createFact(fact.qname, attributes=attrs, text=text, parent=parent) # if fact.isFraction, create numerator and denominator newFactForOldObjId[fact.objectIndex] = newFact if filingFiles is not None and fact.concept is not None and fact.concept.isTextBlock: # check for img and other filing references so that referenced files are included in the zip. for xmltext in [text] + CDATApattern.findall(text): try: for elt in XML("<body>\n{0}\n</body>\n".format( xmltext)).iter(): addLocallyReferencedFile(elt, filingFiles) except (XMLSyntaxError, UnicodeDecodeError): pass # TODO: Why ignore UnicodeDecodeError? elif fact.isTuple: attrs = {} if fact.id: attrs["id"] = fact.id if fact.isNil: attrs[XbrlConst.qnXsiNil] = "true" for attrName, attrValue in fact.items(): if attrName.startswith("{"): attrs[qname(attrName, fact.nsmap)] = attrValue newTuple = targetInstance.createFact(fact.qname, attributes=attrs, parent=parent) newFactForOldObjId[fact.objectIndex] = newTuple createFacts(fact.modelTupleFacts, newTuple)
def createFacts(facts, parent): for fact in facts: if fact.isItem: # HF does not de-duplicate, which is currently-desired behavior attrs = {"contextRef": fact.contextID} if fact.id: attrs["id"] = fact.id if fact.isNumeric: attrs["unitRef"] = fact.unitID if fact.get("decimals"): attrs["decimals"] = fact.get("decimals") if fact.get("precision"): attrs["precision"] = fact.get("precision") if fact.isNil: attrs[XbrlConst.qnXsiNil] = "true" text = None else: text = fact.xValue if fact.xValid else fact.textValue if fact.concept is not None and fact.concept.baseXsdType in ( "string", "normalizedString"): # default xmlLang = fact.xmlLang if xmlLang is not None and xmlLang != baseXmlLang: attrs[ "{http://www.w3.org/XML/1998/namespace}lang"] = xmlLang newFact = targetInstance.createFact(fact.qname, attributes=attrs, text=text, parent=parent) # if fact.isFraction, create numerator and denominator newFactForOldObjId[fact.objectIndex] = newFact if filingFiles is not None and fact.concept is not None and fact.concept.isTextBlock: # check for img and other filing references so that referenced files are included in the zip. for xmltext in [text] + CDATApattern.findall(text): try: for elt in XML("<body>\n{0}\n</body>\n".format( xmltext)).iter(): addLocallyReferencedFile(elt, filingFiles) except (XMLSyntaxError, UnicodeDecodeError): pass # TODO: Why ignore UnicodeDecodeError? elif fact.isTuple: newTuple = targetInstance.createFact(fact.qname, parent=parent) newFactForOldObjId[fact.objectIndex] = newTuple createFacts(fact.modelTupleFacts, newTuple)
def createFacts(facts, parent): for fact in facts: if fact.isItem: attrs = {"contextRef": fact.contextID} if fact.id: attrs["id"] = fact.id if fact.isNumeric: attrs["unitRef"] = fact.unitID if fact.get("decimals"): attrs["decimals"] = fact.get("decimals") if fact.get("precision"): attrs["precision"] = fact.get("precision") if fact.isNil: attrs[XbrlConst.qnXsiNil] = "true" text = None else: text = fact.xValue if fact.xValid else fact.textValue newFact = targetInstance.createFact(fact.qname, attributes=attrs, text=text, parent=parent) newFactForOldObjId[fact.objectIndex] = newFact if filingFiles and fact.concept is not None and fact.concept.isTextBlock: # check for img and other filing references for xmltext in [text] + CDATApattern.findall(text): try: for elt in XML( "<body>\n{0}\n</body>\n".format(xmltext)): if elt.tag in ("a", "img") and not isHttpUrl( attrValue) and not os.path.isabs( attrvalue): for attrTag, attrValue in elt.items(): if attrTag in ("href", "src"): filingFiles.add(attrValue) except (XMLSyntaxError, UnicodeDecodeError): pass elif fact.isTuple: newTuple = targetInstance.createFact(fact.qname, parent=parent) newFactForOldObjId[fact.objectIndex] = newTuple createFacts(fact.modelTupleFacts, newTuple)
def createFacts(facts, parent): for fact in facts: if fact.isItem: # HF does not de-duplicate, which is currently-desired behavior attrs = {"contextRef": fact.contextID} if fact.id: attrs["id"] = fact.id if fact.isNumeric: attrs["unitRef"] = fact.unitID if fact.get("decimals"): attrs["decimals"] = fact.get("decimals") if fact.get("precision"): attrs["precision"] = fact.get("precision") if fact.isNil: attrs[XbrlConst.qnXsiNil] = "true" text = None else: text = fact.xValue if fact.xValid else fact.textValue if fact.concept is not None and fact.concept.baseXsdType in ("string", "normalizedString"): # default xmlLang = fact.xmlLang if xmlLang is not None and xmlLang != defaultXmlLang: attrs["{http://www.w3.org/XML/1998/namespace}lang"] = xmlLang newFact = targetInstance.createFact(fact.qname, attributes=attrs, text=text, parent=parent) # if fact.isFraction, create numerator and denominator newFactForOldObjId[fact.objectIndex] = newFact if filingFiles is not None and fact.concept is not None and fact.concept.isTextBlock: # check for img and other filing references so that referenced files are included in the zip. for xmltext in [text] + CDATApattern.findall(text): try: for elt in XML("<body>\n{0}\n</body>\n".format(xmltext)).iter(): addLocallyReferencedFile(elt, filingFiles) except (XMLSyntaxError, UnicodeDecodeError): pass # TODO: Why ignore UnicodeDecodeError? elif fact.isTuple: newTuple = targetInstance.createFact(fact.qname, parent=parent) newFactForOldObjId[fact.objectIndex] = newTuple createFacts(fact.modelTupleFacts, newTuple)
def __init__(self, modelXbrl): self.isInline = modelXbrl.modelDocument.type == ModelDocument.Type.INLINEXBRL self.url = modelXbrl.modelDocument.uri self.basename = modelXbrl.modelDocument.basename for attrName in Report.REPORT_ATTRS: setattr(self, self.lc(attrName), None) self.instanceName = modelXbrl.modelDocument.basename for f in modelXbrl.facts: cntx = f.context if cntx is not None and cntx.isStartEndPeriod and not cntx.hasSegment: if f.qname is not None and f.qname.localName in Report.REPORT_ATTRS and f.xValue: setattr(self, self.lc(f.qname.localName), f.xValue) self.reportedFiles = {modelXbrl.modelDocument.basename} self.renderedFiles = set() self.hasUsGaapTaxonomy = False sourceDir = os.path.dirname(modelXbrl.modelDocument.filepath) # add referenced files that are xbrl-referenced local documents refDocUris = set() def addRefDocs(doc): for refDoc in doc.referencesDocument.keys(): _file = refDoc.filepath if refDoc.uri not in refDocUris: refDocUris.add(refDoc.uri) if refDoc.filepath and refDoc.filepath.startswith( sourceDir): self.reportedFiles.add(refDoc.filepath[len(sourceDir) + 1:]) addRefDocs(refDoc) if refDoc.type == ModelDocument.Type.SCHEMA and refDoc.targetNamespace: nsAuthority = authority(refDoc.targetNamespace, includeScheme=False) nsPath = refDoc.targetNamespace.split('/') if len(nsPath) > 2: if nsAuthority in ("fasb.org", "xbrl.us" ) and nsPath[-2] == "us-gaap": self.hasUsGaapTaxonomy = True addRefDocs(modelXbrl.modelDocument) # add referenced files that are html-referenced image and other files def addLocallyReferencedFile(elt): if elt.tag in ("a", "img", "{http://www.w3.org/1999/xhtml}a", "{http://www.w3.org/1999/xhtml}img"): for attrTag, attrValue in elt.items(): if attrTag in ("href", "src") and not isHttpUrl( attrValue) and not os.path.isabs(attrValue): file = os.path.join(sourceDir, attrValue) if os.path.exists(file): self.reportedFiles.add( os.path.join(sourceDir, attrValue)) for fact in modelXbrl.facts: if fact.concept is not None and fact.isItem and fact.concept.isTextBlock: # check for img and other filing references so that referenced files are included in the zip. text = fact.textValue for xmltext in [text] + CDATApattern.findall(text): try: for elt in XML("<body>\n{0}\n</body>\n".format( xmltext)).iter(): addLocallyReferencedFile(elt) except (XMLSyntaxError, UnicodeDecodeError): pass # TODO: Why ignore UnicodeDecodeError? # footnote or other elements for elt in modelXbrl.modelDocument.xmlRootElement.iter( "{http://www.w3.org/1999/xhtml}a", "{http://www.w3.org/1999/xhtml}img"): addLocallyReferencedFile(elt)