Skip to content

Commit

Permalink
Merge pull request #77 from leplatrem/enable-flake8-check
Browse files Browse the repository at this point in the history
Enable flake8 check in tox/TravisCI
  • Loading branch information
mpdavis authored Jan 16, 2018
2 parents c8550ff + e4ac977 commit aaef35d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 34 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ sudo: false
dist: precise
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
Expand All @@ -16,4 +14,10 @@ install:
script:
- tox
after_success:
- codecov
- codecov
matrix:
include:
- python: 3.6
env:
- TOX_ENV=flake8
script: tox -e $TOX_ENV
6 changes: 3 additions & 3 deletions jose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

__version__ = "1.4.0"
__version__ = '1.4.0'
__author__ = 'Michael Davis'
__license__ = 'MIT'
__copyright__ = 'Copyright 2016 Michael Davis'

__all__ = ['JOSEError', 'JWSError', 'JWTError', 'ExpiredSignatureError']

from .exceptions import JOSEError
from .exceptions import JWSError
from .exceptions import ExpiredSignatureError
from .exceptions import JWTError
from .exceptions import ExpiredSignatureError
2 changes: 2 additions & 0 deletions jose/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

__all__ = ['ECKey', 'RSAKey']

try:
from jose.backends.pycrypto_backend import RSAKey
except ImportError:
Expand Down
6 changes: 3 additions & 3 deletions jose/backends/cryptography_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def _process_jwk(self, jwk_dict):

def sign(self, msg):
if self.hash_alg.digest_size * 8 > self.prepared_key.curve.key_size:
raise TypeError("this curve (%s) is too short "
"for your digest (%d)" % (self.prepared_key.curve.name,
raise TypeError('this curve (%s) is too short '
'for your digest (%d)' % (self.prepared_key.curve.name,
8*self.hash_alg.digest_size))
signature = self.prepared_key.sign(msg, ec.ECDSA(self.hash_alg()))
order = (2 ** self.prepared_key.curve.key_size) - 1
Expand All @@ -106,7 +106,7 @@ def verify(self, msg, sig):
try:
verifier.verify()
return True
except:
except Exception:
return False

def is_public(self):
Expand Down
4 changes: 2 additions & 2 deletions jose/backends/ecdsa_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _process_jwk(self, jwk_dict):
y = base64_to_long(jwk_dict.get('y'))

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

point = ecdsa.ellipticcurve.Point(self.curve.curve, x, y, self.curve.order)
return ecdsa.keys.VerifyingKey.from_public_point(point, self.curve)
Expand All @@ -96,7 +96,7 @@ def sign(self, msg):
def verify(self, msg, sig):
try:
return self.prepared_key.verify(sig, msg, hashfunc=self.hash_alg, sigdecode=ecdsa.util.sigdecode_string)
except:
except Exception:
return False

def is_public(self):
Expand Down
2 changes: 1 addition & 1 deletion jose/backends/pycrypto_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def sign(self, msg):
def verify(self, msg, sig):
try:
return PKCS1_v1_5.new(self.prepared_key).verify(self.hash_alg.new(msg), sig)
except Exception as e:
except Exception:
return False

def is_public(self):
Expand Down
12 changes: 1 addition & 11 deletions jose/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
from jose.utils import constant_time_string_compare
from jose.backends.base import Key

try:
from jose.backends import RSAKey
except ImportError:
pass

try:
from jose.backends import ECKey
except ImportError:
pass


def get_key(algorithm):
if algorithm in ALGORITHMS.KEYS:
Expand All @@ -36,7 +26,7 @@ def get_key(algorithm):

def register_key(algorithm, key_class):
if not issubclass(key_class, Key):
raise TypeError("Key class not a subclass of jwk.Key")
raise TypeError('Key class not a subclass of jwk.Key')
ALGORITHMS.KEYS[algorithm] = key_class
ALGORITHMS.SUPPORTED.add(algorithm)
return True
Expand Down
6 changes: 3 additions & 3 deletions jose/jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def get_unverified_claims(token):

def _encode_header(algorithm, additional_headers=None):
header = {
"typ": "JWT",
"alg": algorithm
'typ': 'JWT',
'alg': algorithm
}

if additional_headers:
Expand Down Expand Up @@ -211,7 +211,7 @@ def _sig_matches_keys(keys, signing_input, signature, alg):
try:
if key.verify(signing_input, signature):
return True
except:
except Exception:
pass
return False

Expand Down
9 changes: 4 additions & 5 deletions jose/jwt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

import binascii
import json

from calendar import timegm
from collections import Mapping
from datetime import datetime
Expand Down Expand Up @@ -168,7 +166,7 @@ def get_unverified_header(token):
"""
try:
headers = jws.get_unverified_headers(token)
except:
except Exception:
raise JWTError('Error decoding token headers.')

return headers
Expand Down Expand Up @@ -206,7 +204,7 @@ def get_unverified_claims(token):
"""
try:
claims = jws.get_unverified_claims(token)
except:
except Exception:
raise JWTError('Error decoding token claims.')

try:
Expand Down Expand Up @@ -384,6 +382,7 @@ def _validate_sub(claims, subject=None):
if claims.get('sub') != subject:
raise JWTClaimsError('Invalid subject')


def _validate_jti(claims):
"""Validates that the 'jti' claim is valid.
Expand Down Expand Up @@ -433,7 +432,7 @@ def _validate_at_hash(claims, access_token, algorithm):
except (TypeError, ValueError):
msg = 'Unable to calculate at_hash to verify against token claims.'
raise JWTClaimsError(msg)

if claims['at_hash'] != expected_hash:
raise JWTClaimsError('at_hash claim does not match access_token.')

Expand Down
4 changes: 2 additions & 2 deletions jose/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def long_to_base64(data, size=0):


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


def base64_to_long(data):
if isinstance(data, six.text_type):
data = data.encode("ascii")
data = data.encode('ascii')

# urlsafe_b64decode will happily convert b64encoded data
_d = base64.urlsafe_b64decode(bytes(data) + b'==')
Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tox]
envlist = py{26,27,33,34,py}
envlist = py{27,34,35,36,py},flake8
skip_missing_interpreters = True

[testenv]
commands =
Expand All @@ -15,3 +16,8 @@ deps =
enum34
six

[testenv:flake8]
commands = flake8 jose
skip_install= True
deps =
flake8

0 comments on commit aaef35d

Please sign in to comment.