# HG changeset patch # User Bernhard Herzog # Date 1464290478 -7200 # Node ID 607694092e2e43c27179a98822c67feb3817abb9 # Parent 799eb0bf4fafd794cc9defcc4208bee1dd6f2f28 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 diff -r 799eb0bf4faf -r 607694092e2e odfcast/convert.py --- 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.")