Skip to content

Commit

Permalink
Merge 016b296 into ff5a194
Browse files Browse the repository at this point in the history
  • Loading branch information
rapto committed Feb 21, 2023
2 parents ff5a194 + 016b296 commit 2f89905
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/z3c/rml/rml2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def go(xmlInputName, outputFileName=None, outDir=None, dtdDir=None):
# it is already a file-like object
xmlFile = xmlInputName
xmlInputName = 'input.pdf'
should_close_xml = False
else:
xmlFile = open(xmlInputName, 'rb')
should_close_xml = True
root = etree.parse(xmlFile).getroot()
doc = document.Document(root)
doc.filename = xmlInputName
Expand All @@ -67,18 +69,21 @@ def go(xmlInputName, outputFileName=None, outDir=None, dtdDir=None):
# it is already a file-like object
outputFile = outputFileName
outputFileName = 'output.pdf'
should_close_output = False
else:
if outDir is not None:
outputFileName = os.path.join(outDir, outputFileName)
outputFile = open(outputFileName, 'wb')
should_close_output = True

# Create a Reportlab canvas by processing the document
try:
doc.process(outputFile)
finally:
if outputFile:
if outputFile and should_close_output:
outputFile.close()
xmlFile.close()
if should_close_xml:
xmlFile.close()


def main(args=None):
Expand Down

0 comments on commit 2f89905

Please sign in to comment.