From 26e50775ed5fbc36982719b22040454bc1d96cac Mon Sep 17 00:00:00 2001 From: Matthew Stamy Date: Thu, 19 May 2016 17:16:16 -0500 Subject: [PATCH] Appropriate error message for closed file, warn when returning null object, resolves #263 --- PyPDF2/pdf.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index 9979414ff..13dbc38ee 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -571,6 +571,8 @@ def _sweepIndirectReferences(self, externMap, data): self._sweepIndirectReferences(externMap, realdata) return data else: + if data.pdf.stream.closed: + raise ValueError("I/O operation on closed file: {}".format(data.pdf.stream.name)) newobj = externMap.get(data.pdf, {}).get(data.generation, {}).get(data.idnum, None) if newobj == None: try: @@ -588,6 +590,9 @@ def _sweepIndirectReferences(self, externMap, data): return newobj_ido except ValueError: # Unable to resolve the Object, returning NullObject instead. + warnings.warn("Unable to resolve [{}: {}], returning NullObject instead".format( + data.__class__.__name__, data + )) return NullObject() return newobj else: