Skip to content

Commit

Permalink
catch errors, implement feedback from reddit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kareeeeem committed Nov 12, 2014
1 parent a76be29 commit f968a96
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions jpglitch.py
Expand Up @@ -8,14 +8,13 @@


def pairwise(iterable):
def pairwise(iterable):
"""Awesome function from the itertools cookbook
https://docs.python.org/2/library/itertools.html
s -> (s0,s1), (s1,s2), (s2, s3), ...
"""
a, b = tee(iterable)
next(b, None)
return izip(a, b)
"""Awesome function from the itertools cookbook
https://docs.python.org/2/library/itertools.html
s -> (s0,s1), (s1,s2), (s2, s3), ...
"""
a, b = tee(iterable)
next(b, None)
return izip(a, b)


class Jpeg(object):
Expand All @@ -26,7 +25,7 @@ def __init__(self, image_bytes, amount, seed, iterations):
try:
self.header_length = self.get_header_length()
except ValueError as e:
click.fail(e.message)
raise click.BadParameter(message=e.message)

self.parameters = {
'amount': amount,
Expand Down Expand Up @@ -104,8 +103,9 @@ def save_image(self, name):
im.save(name)
return
except IOError:
if self.parameters['iterations'] == 0:
click.fail('This image is beyond repair, maybe try again?')
if self.parameters['iterations'] == 1:
raise click.BadParameter(message='This image is beyond\
repair, maybe try again?', param_hint=['image'])

self.parameters['iterations'] -= 1
self.glitch_bytes()
Expand Down

0 comments on commit f968a96

Please sign in to comment.