Skip to content

Commit aaef35d

Browse files
authored
Merge pull request #77 from leplatrem/enable-flake8-check
Enable flake8 check in tox/TravisCI
2 parents c8550ff + e4ac977 commit aaef35d

File tree

11 files changed

+35
-34
lines changed

11 files changed

+35
-34
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ sudo: false
44
dist: precise
55
language: python
66
python:
7-
- "2.6"
87
- "2.7"
9-
- "3.3"
108
- "3.4"
119
- "3.5"
1210
- "3.6"
@@ -16,4 +14,10 @@ install:
1614
script:
1715
- tox
1816
after_success:
19-
- codecov
17+
- codecov
18+
matrix:
19+
include:
20+
- python: 3.6
21+
env:
22+
- TOX_ENV=flake8
23+
script: tox -e $TOX_ENV

jose/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
__version__ = "1.4.0"
2+
__version__ = '1.4.0'
33
__author__ = 'Michael Davis'
44
__license__ = 'MIT'
55
__copyright__ = 'Copyright 2016 Michael Davis'
6-
6+
__all__ = ['JOSEError', 'JWSError', 'JWTError', 'ExpiredSignatureError']
77

88
from .exceptions import JOSEError
99
from .exceptions import JWSError
10-
from .exceptions import ExpiredSignatureError
1110
from .exceptions import JWTError
11+
from .exceptions import ExpiredSignatureError

jose/backends/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
__all__ = ['ECKey', 'RSAKey']
3+
24
try:
35
from jose.backends.pycrypto_backend import RSAKey
46
except ImportError:

jose/backends/cryptography_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def _process_jwk(self, jwk_dict):
9191

9292
def sign(self, msg):
9393
if self.hash_alg.digest_size * 8 > self.prepared_key.curve.key_size:
94-
raise TypeError("this curve (%s) is too short "
95-
"for your digest (%d)" % (self.prepared_key.curve.name,
94+
raise TypeError('this curve (%s) is too short '
95+
'for your digest (%d)' % (self.prepared_key.curve.name,
9696
8*self.hash_alg.digest_size))
9797
signature = self.prepared_key.sign(msg, ec.ECDSA(self.hash_alg()))
9898
order = (2 ** self.prepared_key.curve.key_size) - 1
@@ -106,7 +106,7 @@ def verify(self, msg, sig):
106106
try:
107107
verifier.verify()
108108
return True
109-
except:
109+
except Exception:
110110
return False
111111

112112
def is_public(self):

jose/backends/ecdsa_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _process_jwk(self, jwk_dict):
8585
y = base64_to_long(jwk_dict.get('y'))
8686

8787
if not ecdsa.ecdsa.point_is_valid(self.curve.generator, x, y):
88-
raise JWKError("Point: %s, %s is not a valid point" % (x, y))
88+
raise JWKError('Point: %s, %s is not a valid point' % (x, y))
8989

9090
point = ecdsa.ellipticcurve.Point(self.curve.curve, x, y, self.curve.order)
9191
return ecdsa.keys.VerifyingKey.from_public_point(point, self.curve)
@@ -96,7 +96,7 @@ def sign(self, msg):
9696
def verify(self, msg, sig):
9797
try:
9898
return self.prepared_key.verify(sig, msg, hashfunc=self.hash_alg, sigdecode=ecdsa.util.sigdecode_string)
99-
except:
99+
except Exception:
100100
return False
101101

102102
def is_public(self):

jose/backends/pycrypto_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def sign(self, msg):
129129
def verify(self, msg, sig):
130130
try:
131131
return PKCS1_v1_5.new(self.prepared_key).verify(self.hash_alg.new(msg), sig)
132-
except Exception as e:
132+
except Exception:
133133
return False
134134

135135
def is_public(self):

jose/jwk.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99
from jose.utils import constant_time_string_compare
1010
from jose.backends.base import Key
1111

12-
try:
13-
from jose.backends import RSAKey
14-
except ImportError:
15-
pass
16-
17-
try:
18-
from jose.backends import ECKey
19-
except ImportError:
20-
pass
21-
2212

2313
def get_key(algorithm):
2414
if algorithm in ALGORITHMS.KEYS:
@@ -36,7 +26,7 @@ def get_key(algorithm):
3626

3727
def register_key(algorithm, key_class):
3828
if not issubclass(key_class, Key):
39-
raise TypeError("Key class not a subclass of jwk.Key")
29+
raise TypeError('Key class not a subclass of jwk.Key')
4030
ALGORITHMS.KEYS[algorithm] = key_class
4131
ALGORITHMS.SUPPORTED.add(algorithm)
4232
return True

jose/jws.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ def get_unverified_claims(token):
129129

130130
def _encode_header(algorithm, additional_headers=None):
131131
header = {
132-
"typ": "JWT",
133-
"alg": algorithm
132+
'typ': 'JWT',
133+
'alg': algorithm
134134
}
135135

136136
if additional_headers:
@@ -211,7 +211,7 @@ def _sig_matches_keys(keys, signing_input, signature, alg):
211211
try:
212212
if key.verify(signing_input, signature):
213213
return True
214-
except:
214+
except Exception:
215215
pass
216216
return False
217217

jose/jwt.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11

2-
import binascii
32
import json
4-
53
from calendar import timegm
64
from collections import Mapping
75
from datetime import datetime
@@ -168,7 +166,7 @@ def get_unverified_header(token):
168166
"""
169167
try:
170168
headers = jws.get_unverified_headers(token)
171-
except:
169+
except Exception:
172170
raise JWTError('Error decoding token headers.')
173171

174172
return headers
@@ -206,7 +204,7 @@ def get_unverified_claims(token):
206204
"""
207205
try:
208206
claims = jws.get_unverified_claims(token)
209-
except:
207+
except Exception:
210208
raise JWTError('Error decoding token claims.')
211209

212210
try:
@@ -384,6 +382,7 @@ def _validate_sub(claims, subject=None):
384382
if claims.get('sub') != subject:
385383
raise JWTClaimsError('Invalid subject')
386384

385+
387386
def _validate_jti(claims):
388387
"""Validates that the 'jti' claim is valid.
389388
@@ -433,7 +432,7 @@ def _validate_at_hash(claims, access_token, algorithm):
433432
except (TypeError, ValueError):
434433
msg = 'Unable to calculate at_hash to verify against token claims.'
435434
raise JWTClaimsError(msg)
436-
435+
437436
if claims['at_hash'] != expected_hash:
438437
raise JWTClaimsError('at_hash claim does not match access_token.')
439438

jose/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ def long_to_base64(data, size=0):
4040

4141

4242
def int_arr_to_long(arr):
43-
return long(''.join(["%02x" % byte for byte in arr]), 16)
43+
return long(''.join(['%02x' % byte for byte in arr]), 16)
4444

4545

4646
def base64_to_long(data):
4747
if isinstance(data, six.text_type):
48-
data = data.encode("ascii")
48+
data = data.encode('ascii')
4949

5050
# urlsafe_b64decode will happily convert b64encoded data
5151
_d = base64.urlsafe_b64decode(bytes(data) + b'==')

0 commit comments

Comments
 (0)