mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Merge pull request #4683 from cool-RR/2020-06-12-raise-from
Fix exception causes in PdfParser.py
This commit is contained in:
commit
5962c2e797
|
@ -251,8 +251,8 @@ class PdfDict(collections.UserDict):
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
try:
|
try:
|
||||||
value = self[key.encode("us-ascii")]
|
value = self[key.encode("us-ascii")]
|
||||||
except KeyError:
|
except KeyError as e:
|
||||||
raise AttributeError(key)
|
raise AttributeError(key) from e
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
value = decode_text(value)
|
value = decode_text(value)
|
||||||
if key.endswith("Date"):
|
if key.endswith("Date"):
|
||||||
|
@ -811,11 +811,11 @@ class PdfParser:
|
||||||
if m:
|
if m:
|
||||||
try:
|
try:
|
||||||
stream_len = int(result[b"Length"])
|
stream_len = int(result[b"Length"])
|
||||||
except (TypeError, KeyError, ValueError):
|
except (TypeError, KeyError, ValueError) as e:
|
||||||
raise PdfFormatError(
|
raise PdfFormatError(
|
||||||
"bad or missing Length in stream dict (%r)"
|
"bad or missing Length in stream dict (%r)"
|
||||||
% result.get(b"Length", None)
|
% result.get(b"Length", None)
|
||||||
)
|
) from e
|
||||||
stream_data = data[m.end() : m.end() + stream_len]
|
stream_data = data[m.end() : m.end() + stream_len]
|
||||||
m = cls.re_stream_end.match(data, m.end() + stream_len)
|
m = cls.re_stream_end.match(data, m.end() + stream_len)
|
||||||
check_format_condition(m, "stream end not found")
|
check_format_condition(m, "stream end not found")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user