Fixed pep8 issues

This commit is contained in:
Alex Gaynor 2013-10-31 15:03:53 -07:00
parent 484713ffd0
commit c1ea0a0d23
2 changed files with 10 additions and 8 deletions

View file

@ -28,7 +28,9 @@ class Fernet(object):
def _encrypt_from_parts(self, data, current_time, iv):
if isinstance(data, six.text_type):
raise TypeError("Unicode-objects must be encoded before encryption")
raise TypeError(
"Unicode-objects must be encoded before encryption"
)
padder = padding.PKCS7(ciphers.AES.block_size).padder()
padded_data = padder.update(data) + padder.finalize()
@ -49,7 +51,9 @@ class Fernet(object):
def decrypt(self, data, ttl=None, current_time=None):
if isinstance(data, six.text_type):
raise TypeError("Unicode-objects must be encoded before decryption")
raise TypeError(
"Unicode-objects must be encoded before decryption"
)
if current_time is None:
current_time = int(time.time())

View file

@ -40,21 +40,19 @@ class TestFernet(object):
)
def test_verify(self, secret, now, src, ttl_sec, token):
f = Fernet(base64.urlsafe_b64decode(secret.encode("ascii")))
current_time = calendar.timegm(iso8601.parse_date(now).utctimetuple())
payload = f.decrypt(
token.encode("ascii"),
ttl=ttl_sec,
current_time=calendar.timegm(iso8601.parse_date(now).utctimetuple())
token.encode("ascii"), ttl=ttl_sec, current_time=current_time
)
assert payload == src
@json_parametrize(("secret", "token", "now", "ttl_sec"), "invalid.json")
def test_invalid(self, secret, token, now, ttl_sec):
f = Fernet(base64.urlsafe_b64decode(secret.encode("ascii")))
current_time = calendar.timegm(iso8601.parse_date(now).utctimetuple())
with pytest.raises(InvalidToken):
f.decrypt(
token.encode("ascii"),
ttl=ttl_sec,
current_time=calendar.timegm(iso8601.parse_date(now).utctimetuple())
token.encode("ascii"), ttl=ttl_sec, current_time=current_time
)
def test_unicode(self):