Skip to content

Commit 086d96f

Browse files
committed
Fixed some PEP8 errors from the last commit.
1 parent d732c1d commit 086d96f

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

jwt/api.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from collections import Mapping
66
from datetime import datetime, timedelta
77

8+
from .algorithms import Algorithm, _register_default_algorithms # NOQA
89
from .compat import string_types, text_type, timedelta_total_seconds
910
from .exceptions import (
1011
DecodeError, ExpiredSignatureError,
1112
InvalidAudienceError, InvalidIssuerError
1213
)
1314
from .utils import base64url_decode, base64url_encode
1415

15-
from jwt.algorithms import Algorithm, _register_default_algorithms # NOQA
1616

1717
class PyJWT(object):
1818
def __init__(self):
@@ -83,17 +83,15 @@ def encode(self, payload, key, algorithm='HS256', headers=None, json_encoder=Non
8383

8484
return b'.'.join(segments)
8585

86-
8786
def decode(self, jwt, key='', verify=True, **kwargs):
8887
payload, signing_input, header, signature = self._load(jwt)
8988

9089
if verify:
9190
self._verify_signature(payload, signing_input, header, signature,
92-
key, **kwargs)
91+
key, **kwargs)
9392

9493
return payload
9594

96-
9795
def _load(self, jwt):
9896
if isinstance(jwt, text_type):
9997
jwt = jwt.encode('utf-8')
@@ -132,7 +130,6 @@ def _load(self, jwt):
132130

133131
return (payload, signing_input, header, signature)
134132

135-
136133
def _verify_signature(self, payload, signing_input, header, signature,
137134
key='', verify_expiration=True, leeway=0,
138135
audience=None, issuer=None):

tests/test_api.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def test_load_verify_valid_jwt(self):
259259
decoded_payload, signing, header, signature = self.jwt._load(example_jwt)
260260

261261
self.jwt._verify_signature(decoded_payload, signing, header,
262-
signature, example_secret)
262+
signature, example_secret)
263263

264264
self.assertEqual(decoded_payload, example_payload)
265265

@@ -295,7 +295,7 @@ def test_verify_signature_no_secret(self):
295295
self.assertRaises(
296296
DecodeError,
297297
lambda: self.jwt._verify_signature(decoded_payload, signing,
298-
header, signature))
298+
header, signature))
299299

300300
def test_custom_headers(self):
301301
right_secret = 'foo'
@@ -321,7 +321,7 @@ def test_unicode_secret(self):
321321
decoded_payload, signing, header, signature = self.jwt._load(jwt_message)
322322

323323
self.jwt._verify_signature(decoded_payload, signing, header,
324-
signature, secret)
324+
signature, secret)
325325

326326
self.assertEqual(decoded_payload, self.payload)
327327

@@ -336,7 +336,7 @@ def test_nonascii_secret(self):
336336
decoded_payload, signing, header, signature = self.jwt._load(jwt_message)
337337

338338
self.jwt._verify_signature(decoded_payload, signing,
339-
header, signature, secret)
339+
header, signature, secret)
340340

341341
self.assertEqual(decoded_payload, self.payload)
342342

@@ -351,7 +351,7 @@ def test_bytes_secret(self):
351351
decoded_payload, signing, header, signature = self.jwt._load(jwt_message)
352352

353353
self.jwt._verify_signature(decoded_payload, signing,
354-
header, signature, secret)
354+
header, signature, secret)
355355

356356
self.assertEqual(decoded_payload, self.payload)
357357

@@ -496,7 +496,7 @@ def test_decode_skip_expiration_verification(self):
496496

497497
decoded_payload, signing, header, signature = self.jwt._load(jwt_message)
498498
self.jwt._verify_signature(decoded_payload, signing, header,
499-
signature, secret, verify_expiration=False)
499+
signature, secret, verify_expiration=False)
500500

501501
def test_decode_skip_notbefore_verification(self):
502502
self.payload['nbf'] = time.time() + 10
@@ -507,7 +507,7 @@ def test_decode_skip_notbefore_verification(self):
507507

508508
decoded_payload, signing, header, signature = self.jwt._load(jwt_message)
509509
self.jwt._verify_signature(decoded_payload, signing, header,
510-
signature, secret, verify_expiration=False)
510+
signature, secret, verify_expiration=False)
511511

512512
def test_decode_with_expiration_with_leeway(self):
513513
self.payload['exp'] = utc_timestamp() - 2
@@ -521,7 +521,7 @@ def test_decode_with_expiration_with_leeway(self):
521521
self.jwt.decode(jwt_message, secret, leeway=leeway)
522522

523523
self.jwt._verify_signature(decoded_payload, signing, header,
524-
signature, secret, leeway=leeway)
524+
signature, secret, leeway=leeway)
525525

526526
# With 1 seconds, should fail
527527
for leeway in (1, timedelta(seconds=1)):
@@ -532,8 +532,8 @@ def test_decode_with_expiration_with_leeway(self):
532532
self.assertRaises(
533533
ExpiredSignatureError,
534534
lambda: self.jwt._verify_signature(decoded_payload, signing,
535-
header, signature, secret,
536-
leeway=leeway))
535+
header, signature, secret,
536+
leeway=leeway))
537537

538538
def test_decode_with_notbefore_with_leeway(self):
539539
self.payload['nbf'] = utc_timestamp() + 10
@@ -546,7 +546,7 @@ def test_decode_with_notbefore_with_leeway(self):
546546
self.jwt.decode(jwt_message, secret, leeway=13)
547547

548548
self.jwt._verify_signature(decoded_payload, signing, header,
549-
signature, secret, leeway=13)
549+
signature, secret, leeway=13)
550550

551551
# With 1 seconds, should fail
552552
self.assertRaises(
@@ -556,7 +556,7 @@ def test_decode_with_notbefore_with_leeway(self):
556556
self.assertRaises(
557557
ExpiredSignatureError,
558558
lambda: self.jwt._verify_signature(decoded_payload, signing,
559-
header, signature, secret, leeway=1))
559+
header, signature, secret, leeway=1))
560560

561561
def test_encode_decode_with_algo_none(self):
562562
jwt_message = self.jwt.encode(self.payload, key=None, algorithm=None)
@@ -574,7 +574,7 @@ def test_encode_decode_with_rsa_sha256(self):
574574
priv_rsakey = load_pem_private_key(ensure_bytes(rsa_priv_file.read()),
575575
password=None, backend=default_backend())
576576
jwt_message = self.jwt.encode(self.payload, priv_rsakey,
577-
algorithm='RS256')
577+
algorithm='RS256')
578578

579579
with open('tests/keys/testkey_rsa.pub', 'r') as rsa_pub_file:
580580
pub_rsakey = load_ssh_public_key(ensure_bytes(rsa_pub_file.read()),
@@ -588,7 +588,7 @@ def test_encode_decode_with_rsa_sha256(self):
588588
with open('tests/keys/testkey_rsa', 'r') as rsa_priv_file:
589589
priv_rsakey = rsa_priv_file.read()
590590
jwt_message = self.jwt.encode(self.payload, priv_rsakey,
591-
algorithm='RS256')
591+
algorithm='RS256')
592592

593593
with open('tests/keys/testkey_rsa.pub', 'r') as rsa_pub_file:
594594
pub_rsakey = rsa_pub_file.read()
@@ -604,7 +604,7 @@ def test_encode_decode_with_rsa_sha384(self):
604604
priv_rsakey = load_pem_private_key(ensure_bytes(rsa_priv_file.read()),
605605
password=None, backend=default_backend())
606606
jwt_message = self.jwt.encode(self.payload, priv_rsakey,
607-
algorithm='RS384')
607+
algorithm='RS384')
608608

609609
with open('tests/keys/testkey_rsa.pub', 'r') as rsa_pub_file:
610610
pub_rsakey = load_ssh_public_key(ensure_bytes(rsa_pub_file.read()),
@@ -615,7 +615,7 @@ def test_encode_decode_with_rsa_sha384(self):
615615
with open('tests/keys/testkey_rsa', 'r') as rsa_priv_file:
616616
priv_rsakey = rsa_priv_file.read()
617617
jwt_message = self.jwt.encode(self.payload, priv_rsakey,
618-
algorithm='RS384')
618+
algorithm='RS384')
619619

620620
with open('tests/keys/testkey_rsa.pub', 'r') as rsa_pub_file:
621621
pub_rsakey = rsa_pub_file.read()
@@ -631,7 +631,7 @@ def test_encode_decode_with_rsa_sha512(self):
631631
priv_rsakey = load_pem_private_key(ensure_bytes(rsa_priv_file.read()),
632632
password=None, backend=default_backend())
633633
jwt_message = self.jwt.encode(self.payload, priv_rsakey,
634-
algorithm='RS512')
634+
algorithm='RS512')
635635

636636
with open('tests/keys/testkey_rsa.pub', 'r') as rsa_pub_file:
637637
pub_rsakey = load_ssh_public_key(ensure_bytes(rsa_pub_file.read()),
@@ -645,7 +645,7 @@ def test_encode_decode_with_rsa_sha512(self):
645645
with open('tests/keys/testkey_rsa', 'r') as rsa_priv_file:
646646
priv_rsakey = rsa_priv_file.read()
647647
jwt_message = self.jwt.encode(self.payload, priv_rsakey,
648-
algorithm='RS512')
648+
algorithm='RS512')
649649

650650
with open('tests/keys/testkey_rsa.pub', 'r') as rsa_pub_file:
651651
pub_rsakey = rsa_pub_file.read()
@@ -674,7 +674,7 @@ def test_encode_decode_with_ecdsa_sha256(self):
674674
priv_eckey = load_pem_private_key(ensure_bytes(ec_priv_file.read()),
675675
password=None, backend=default_backend())
676676
jwt_message = self.jwt.encode(self.payload, priv_eckey,
677-
algorithm='ES256')
677+
algorithm='ES256')
678678

679679
with open('tests/keys/testkey_ec.pub', 'r') as ec_pub_file:
680680
pub_eckey = load_pem_public_key(ensure_bytes(ec_pub_file.read()),
@@ -688,7 +688,7 @@ def test_encode_decode_with_ecdsa_sha256(self):
688688
with open('tests/keys/testkey_ec', 'r') as ec_priv_file:
689689
priv_eckey = ec_priv_file.read()
690690
jwt_message = self.jwt.encode(self.payload, priv_eckey,
691-
algorithm='ES256')
691+
algorithm='ES256')
692692

693693
with open('tests/keys/testkey_ec.pub', 'r') as ec_pub_file:
694694
pub_eckey = ec_pub_file.read()
@@ -705,7 +705,7 @@ def test_encode_decode_with_ecdsa_sha384(self):
705705
priv_eckey = load_pem_private_key(ensure_bytes(ec_priv_file.read()),
706706
password=None, backend=default_backend())
707707
jwt_message = self.jwt.encode(self.payload, priv_eckey,
708-
algorithm='ES384')
708+
algorithm='ES384')
709709

710710
with open('tests/keys/testkey_ec.pub', 'r') as ec_pub_file:
711711
pub_eckey = load_pem_public_key(ensure_bytes(ec_pub_file.read()),
@@ -719,7 +719,7 @@ def test_encode_decode_with_ecdsa_sha384(self):
719719
with open('tests/keys/testkey_ec', 'r') as ec_priv_file:
720720
priv_eckey = ec_priv_file.read()
721721
jwt_message = self.jwt.encode(self.payload, priv_eckey,
722-
algorithm='ES384')
722+
algorithm='ES384')
723723

724724
with open('tests/keys/testkey_ec.pub', 'r') as ec_pub_file:
725725
pub_eckey = ec_pub_file.read()
@@ -735,7 +735,7 @@ def test_encode_decode_with_ecdsa_sha512(self):
735735
priv_eckey = load_pem_private_key(ensure_bytes(ec_priv_file.read()),
736736
password=None, backend=default_backend())
737737
jwt_message = self.jwt.encode(self.payload, priv_eckey,
738-
algorithm='ES512')
738+
algorithm='ES512')
739739

740740
with open('tests/keys/testkey_ec.pub', 'r') as ec_pub_file:
741741
pub_eckey = load_pem_public_key(ensure_bytes(ec_pub_file.read()), backend=default_backend())
@@ -748,7 +748,7 @@ def test_encode_decode_with_ecdsa_sha512(self):
748748
with open('tests/keys/testkey_ec', 'r') as ec_priv_file:
749749
priv_eckey = ec_priv_file.read()
750750
jwt_message = self.jwt.encode(self.payload, priv_eckey,
751-
algorithm='ES512')
751+
algorithm='ES512')
752752

753753
with open('tests/keys/testkey_ec.pub', 'r') as ec_pub_file:
754754
pub_eckey = ec_pub_file.read()
@@ -760,7 +760,7 @@ def test_encode_decode_with_ecdsa_sha512(self):
760760
def test_ecdsa_related_algorithms(self):
761761
self.jwt = PyJWT()
762762
jwt_algorithms = self.jwt._algorithms
763-
763+
764764
if has_crypto:
765765
self.assertTrue('ES256' in jwt_algorithms)
766766
self.assertTrue('ES384' in jwt_algorithms)

0 commit comments

Comments
 (0)