Skip to content

Commit

Permalink
Merge pull request #100 from hermfischer-wf/edgar24.1-upd4
Browse files Browse the repository at this point in the history
  • Loading branch information
austinmatherne-wk committed Apr 5, 2024
2 parents 2f238a8 + 2b95c6b commit ac1a3cc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 37 deletions.
7 changes: 4 additions & 3 deletions Filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
usGaapOrIfrsPattern = re.compile(".*/fasb[.]org/(us-gaap|srt)/20|.*/xbrl[.]ifrs[.]org/taxonomy/[0-9-]{10}/ifrs-full", re.I)
deiPattern = re.compile(".*/xbrl[.]sec[.]gov/dei/20", re.I)

def mainFun(controller, modelXbrl, outputFolderName, transform=None, suplSuffix=None, rFilePrefix=None, altFolder=None, altTransform=None, altSuffix=None):
def mainFun(controller, modelXbrl, outputFolderName, transform=None, suplSuffix=None, rFilePrefix=None, altFolder=None, altTransform=None, altSuffix=None, zipDir=None):
if "EdgarRenderer/Filing.py#mainFun" in modelXbrl.arelleUnitTests:
raise arelle.PythonUtil.pyNamedObject(modelXbrl.arelleUnitTests["EdgarRenderer/Filing.py#mainFun"], "EdgarRenderer/Filing.py#mainFun")
_funStartedAt = time.time()
filing = Filing(controller, modelXbrl, outputFolderName, transform, suplSuffix, rFilePrefix, altFolder, altTransform, altSuffix)
filing = Filing(controller, modelXbrl, outputFolderName, transform, suplSuffix, rFilePrefix, altFolder, altTransform, altSuffix, zipDir)
controller.logDebug("Filing initialized {:.3f} secs.".format(time.time() - _funStartedAt)); _funStartedAt = time.time()
filing.populateAndLinkClasses()
controller.logDebug("Filing populateAndLinkClasses {:.3f} secs.".format(time.time() - _funStartedAt)); _funStartedAt = time.time()
Expand Down Expand Up @@ -160,7 +160,7 @@ def mainFun(controller, modelXbrl, outputFolderName, transform=None, suplSuffix=


class Filing(object):
def __init__(self, controller, modelXbrl, outputFolderName, transform, suplSuffix, rFilePrefix, altFolder, altTransform, altSuffix):
def __init__(self, controller, modelXbrl, outputFolderName, transform, suplSuffix, rFilePrefix, altFolder, altTransform, altSuffix, zipDir):
self.modelXbrl = modelXbrl
self.transform = transform
self.suplSuffix = suplSuffix
Expand Down Expand Up @@ -290,6 +290,7 @@ def __init__(self, controller, modelXbrl, outputFolderName, transform, suplSuffi
if controller.reportZip:
self.fileNameBase = None
self.reportZip = controller.reportZip
self.zipDir = zipDir or ""
elif outputFolderName is not None:
# self.fileNameBase = os.path.normpath(os.path.join(os.path.dirname(controller.webCache.normalizeUrl(modelXbrl.fileSource.basefile)) ,outputFolderName))
self.fileNameBase = outputFolderName
Expand Down
10 changes: 6 additions & 4 deletions Inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
DEFAULT_DISTINGUISHING_SUFFIX = "_htm." # suffix tacked onto the base name of the source inline document
USUAL_INSTANCE_EXTS = {"xml", "xbrl"}

def saveTargetDocumentIfNeeded(cntlr, options, modelXbrl, filing, suffix="_htm.", iext=".xml", altFolder=None, suplSuffix=None):
def saveTargetDocumentIfNeeded(cntlr, options, modelXbrl, filing, suffix="_htm.", iext=".xml", altFolder=None, suplSuffix=None, zipDir=None):
if (modelXbrl is None): return
if modelXbrl.modelDocument.type not in (Type.INLINEXBRL, Type.INLINEXBRLDOCUMENTSET):
cntlr.logTrace(_("No Inline XBRL document."))
Expand Down Expand Up @@ -60,6 +60,7 @@ def saveTargetDocumentIfNeeded(cntlr, options, modelXbrl, filing, suffix="_htm."

filingZip = None
filingFiles = None
_zipDir = None
if options.saveTargetFiling:
targetFilename = os.path.basename(targetFilename)
if cntlr.reportZip:
Expand All @@ -81,9 +82,10 @@ def addRefDocs(doc):
else:
if cntlr.reportZip:
filingZip = cntlr.reportZip
_zipDir = zipDir # use zipDir for rest API returned redline/redact extracted instance

saveTargetDocument(filing, modelXbrl, targetFilename, targetSchemaRefs,
outputZip=filingZip, filingFiles=filingFiles, suffix=suffix, iext=iext, suplSuffix=suplSuffix)
outputZip=filingZip, filingFiles=filingFiles, suffix=suffix, iext=iext, suplSuffix=suplSuffix, zipDir=_zipDir)

if options.saveTargetFiling:
instDir = os.path.dirname(modelDocument.uri) # TODO: will this work if the modelDocument was remote?
Expand All @@ -102,7 +104,7 @@ def addRefDocs(doc):

def saveTargetDocument(filing, modelXbrl, targetDocumentFilename, targetDocumentSchemaRefs,
outputZip=None, filingFiles=None,
suffix=DEFAULT_DISTINGUISHING_SUFFIX, iext=DEFAULT_INSTANCE_EXT, suplSuffix=None):
suffix=DEFAULT_DISTINGUISHING_SUFFIX, iext=DEFAULT_INSTANCE_EXT, suplSuffix=None, zipDir=None):
sourceDir = os.path.dirname(modelXbrl.modelDocument.filepath)
targetUrlParts = targetDocumentFilename.rpartition(".")
targetUrl = targetUrlParts[0] + suffix + targetUrlParts[2]
Expand All @@ -113,7 +115,7 @@ def saveTargetDocument(filing, modelXbrl, targetDocumentFilename, targetDocument
# no lang on xbrl:xbrl, specific xml:lang on elements which aren't en-US
baseXmlLang=None, defaultXmlLang="en-US", skipInvalid=True)
if outputZip:
targetInstance.saveInstance(overrideFilepath=targetUrl, outputZip=outputZip, updateFileHistory=False, xmlcharrefreplace=True, edgarcharrefreplace=True)
targetInstance.saveInstance(overrideFilepath=targetUrl, outputZip=outputZip, updateFileHistory=False, xmlcharrefreplace=True, edgarcharrefreplace=True, zipDir=zipDir)
else:
fh = io.StringIO();
targetInstance.saveInstance(overrideFilepath=targetUrl, outputFile=fh, updateFileHistory=False, xmlcharrefreplace=True, edgarcharrefreplace=True, skipInvalid=True)
Expand Down
8 changes: 4 additions & 4 deletions IoManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ def absPathOnPythonPath(controller, filename): # if filename is relative, find
controller.logDebug("No such location {} found in sys path dirs {}.".format(filename, pathdirs))
return None

def writeXmlDoc(filing, etree, reportZip, reportFolder, filename):
def writeXmlDoc(filing, etree, reportZip, reportFolder, filename, zipDir=""):
xmlText = treeToString(etree.getroottree(), method='xml', with_tail=False, pretty_print=True, encoding='utf-8', xml_declaration=True)
if reportZip:
reportZip.writestr(filename, xmlText)
reportZip.writestr(zipDir + filename, xmlText)
elif reportFolder is not None:
filing.writeFile(os.path.join(reportFolder, filename), xmlText)

def writeHtmlDoc(filing, root, reportZip, reportFolder, filename):
def writeHtmlDoc(filing, root, reportZip, reportFolder, filename, zipDir=""):
htmlText = treeToString(root, method='html', with_tail=False, pretty_print=True, encoding='utf-8')
if reportZip:
reportZip.writestr(filename, htmlText)
reportZip.writestr(zipDir + filename, htmlText)
elif reportFolder is not None:
filing.writeFile(os.path.join(reportFolder, filename), htmlText)

Expand Down
6 changes: 3 additions & 3 deletions Report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ def writeXmlFile(self, baseNameBeforeExtension, tree, reportSummary):
reportSummary.xmlFileName = baseName
xmlText = treeToString(tree, xml_declaration=True, encoding='utf-8', pretty_print=True)
if self.filing.reportZip:
self.filing.reportZip.writestr(baseName, xmlText)
self.filing.reportZip.writestr(self.filing.zipDir + baseName, xmlText)
self.controller.renderedFiles.add(baseName)
elif self.filing.fileNameBase is not None:
self.controller.writeFile(os.path.join(self.filing.fileNameBase, baseName), xmlText)
Expand All @@ -1178,7 +1178,7 @@ def writeHtmlFile(self, baseNameBeforeExtension, tree, reportSummary):
result = self.filing.transform(tree,**keywordArgs)
htmlText = treeToString(result,method='html',with_tail=False,pretty_print=True,encoding='us-ascii')
if self.filing.reportZip:
self.filing.reportZip.writestr(baseName, htmlText)
self.filing.reportZip.writestr(self.filing.zipDir + baseName, htmlText)
self.controller.renderedFiles.add(baseName)
elif self.filing.fileNameBase is not None:
self.controller.writeFile(os.path.join(self.filing.fileNameBase, baseName), htmlText)
Expand Down Expand Up @@ -1886,7 +1886,7 @@ def insertEmbeddingOrBarChartEmbeddingIntoETree(self, embedding, cellETree):
fig.savefig(file, bbox_inches='tight', dpi=150)
file.seek(0)
if self.filing.reportZip:
self.filing.reportZip.writestr(pngname, file.read())
self.filing.reportZip.writestr(self.filing.zipDir + pngname, file.read())
else:
self.filing.controller.writeFile(os.path.join(self.filing.fileNameBase, pngname), file.read())
file.close()
Expand Down
4 changes: 2 additions & 2 deletions Xlout.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def close(self):
del self.simplified_transform


def save(self, suffix=""):
def save(self, suffix="", zipDir=""):
if len(self.wb.worksheets)>1:
self.wb.remove(self.wb.worksheets[0])
if not (self.controller.reportZip or self.outputFolderName is not None):
Expand All @@ -69,7 +69,7 @@ def save(self, suffix=""):
file.seek(0)
outputFileName = OUTPUT_FILE_NAME + suffix
if self.controller.reportZip:
self.controller.reportZip.writestr(outputFileName, file.read())
self.controller.reportZip.writestr(zipDir + outputFileName, file.read())
else:
self.controller.writeFile(os.path.join(self.outputFolderName, outputFileName), file.read())
file.close()
Expand Down
Loading

0 comments on commit ac1a3cc

Please sign in to comment.