changeset 91:607694092e2e

Extend CheckView to behave more like the actual merge. Now the merged file is also written to a temporary file in order to make sure the merge object actually reads all the contents of the input file. As it turns out, some contents of the input file are only read on demand and simply appending the file to the merge does not trigger this. Part of mpuls/issue5709
author Bernhard Herzog <bh@intevation.de>
date Thu, 26 May 2016 21:21:18 +0200
parents 799eb0bf4faf
children 2200ae1e7bdb
files odfcast/convert.py
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/odfcast/convert.py	Tue Apr 21 17:11:17 2015 +0200
+++ b/odfcast/convert.py	Thu May 26 21:21:18 2016 +0200
@@ -247,8 +247,6 @@
     def post(self):
         log.debug("Checking a PDF document's readiness for merging")
 
-        merger = PdfFileMerger(strict=False)
-
         ffile = request.files['file']
         if not ffile.filename:
             return ErrorResponse(
@@ -256,13 +254,21 @@
                 details="Please upload a file for conversion",
                 html_error_code=400)
 
-        try:
-            merger.append(ffile, import_bookmarks=False)
-        except Exception, e:
-            log.exception("Error merging file %s" % ffile)
-            return MergeErrorResponse(details=str(e))
+        with tempfile.TemporaryFile() as outfile:
+            merger = PdfFileMerger(strict=False)
+            try:
+                merger.append(ffile, import_bookmarks=False)
+            except Exception, e:
+                log.exception("Error testing merger.append of %s" % ffile)
+                return MergeErrorResponse(details=str(e))
 
-        merger.close()
+            try:
+                merger.write(outfile)
+            except Exception, e:
+                log.exception("Error testing merger.write of merged %s" % ffile)
+                return MergeErrorResponse(details=str(e))
+
+            merger.close()
 
         log.debug("PDF document %s checked." % ffile)
         return Response("Okay.")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)