Skip to content

Commit

Permalink
Appropriate error message for closed file, warn when returning null o…
Browse files Browse the repository at this point in the history
…bject, resolves #263
  • Loading branch information
mstamy2 committed May 19, 2016
1 parent b030b7f commit 26e5077
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 26e5077

Please sign in to comment.