Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.

Allow more leniency #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions code/png.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,14 +1644,21 @@ def process_chunk(self, lenient=False):
All other chunk types are ignored.

If the optional `lenient` argument evaluates to `True`,
checksum failures will raise warnings rather than exceptions.
checksum failures and exceptions during processing
will raise warnings rather than exceptions.
"""

type, data = self.chunk(lenient=lenient)
method = '_process_' + type.decode('ascii')
m = getattr(self, method, None)
if m:
m(data)
try:
m(data)
except FormatError as e:
if lenient:
warnings.warn(e.args[0])
else:
raise

def _process_IHDR(self, data):
# http://www.w3.org/TR/PNG/#11IHDR
Expand Down