diff --git a/.travis.yml b/.travis.yml index d0123bb9..98eb22a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,12 @@ language: python matrix: include: - - python: 2.7 - env: TOXENV=py27-crypto,py27-nocrypto,py27-contrib_crypto - - python: 3.4 - env: TOXENV=py34-crypto,py34-nocrypto - python: 3.5 env: TOXENV=py35-crypto,py35-nocrypto,py35-contrib_crypto - python: 3.6 env: TOXENV=py36-crypto,py36-nocrypto,py36-contrib_crypto - python: 3.7 env: TOXENV=lint,typing,py37-crypto,py37-nocrypto,py37-contrib_crypto - dist: xenial install: - pip install -U pip - pip install -U tox coveralls diff --git a/appveyor.yml b/appveyor.yml index 2dad7d7b..ac139e97 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,14 @@ environment: matrix: - - PYTHON: "C:\\Python27-x64" - TOX_ENV: "py27-crypto" - - PYTHON: "C:\\Python35-x64" TOX_ENV: "py35-crypto" + - PYTHON: "C:\\Python36-x64" + TOX_ENV: "py36-crypto" + + - PYTHON: "C:\\Python37-x64" + TOX_ENV: "py37-crypto" + init: - SET PATH=%PYTHON%;%PATH% - python -c "import sys;sys.stdout.write(sys.version)" diff --git a/jwt/__main__.py b/jwt/__main__.py index c20a41f8..1493e500 100644 --- a/jwt/__main__.py +++ b/jwt/__main__.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python - -from __future__ import absolute_import, print_function +#!/usr/bin/env python3 import argparse import json diff --git a/jwt/compat.py b/jwt/compat.py index 918ff4a8..b4fec157 100644 --- a/jwt/compat.py +++ b/jwt/compat.py @@ -4,20 +4,10 @@ """ # flake8: noqa import hmac -import struct -import sys -PY3 = sys.version_info[0] == 3 - - -if PY3: - text_type = str - binary_type = bytes -else: - text_type = unicode - binary_type = str - -string_types = (text_type, binary_type) +text_type = str +binary_type = bytes +string_types = (str, bytes) try: # Importing ABCs from collections will be removed in PY3.8 @@ -25,48 +15,16 @@ except ImportError: from collections import Iterable, Mapping -try: - constant_time_compare = hmac.compare_digest -except AttributeError: - # Fallback for Python < 2.7 - def constant_time_compare(val1, val2): - """ - Returns True if the two strings are equal, False otherwise. - - The time taken is independent of the number of characters that match. - """ - if len(val1) != len(val2): - return False - - result = 0 - - for x, y in zip(val1, val2): - result |= ord(x) ^ ord(y) - - return result == 0 - - -# Use int.to_bytes if it exists (Python 3) -if getattr(int, "to_bytes", None): - - def bytes_from_int(val): - remaining = val - byte_length = 0 - - while remaining != 0: - remaining = remaining >> 8 - byte_length += 1 - return val.to_bytes(byte_length, "big", signed=False) +constant_time_compare = hmac.compare_digest -else: +def bytes_from_int(val): + remaining = val + byte_length = 0 - def bytes_from_int(val): - buf = [] - while val: - val, remainder = divmod(val, 256) - buf.append(remainder) + while remaining != 0: + remaining = remaining >> 8 + byte_length += 1 - buf.reverse() - return struct.pack("%sB" % len(buf), *buf) + return val.to_bytes(byte_length, "big", signed=False) diff --git a/setup.py b/setup.py index a33b1b81..907ac5e2 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 + import os import re import sys @@ -60,14 +60,13 @@ def get_version(package): "Natural Language :: English", "License :: OSI Approved :: MIT License", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Utilities", ], - python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", + python_requires=">=3, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", extras_require=EXTRAS_REQUIRE, entry_points={"console_scripts": ["pyjwt = jwt.__main__:main"]}, options={"bdist_wheel": {"universal": "1"}}, diff --git a/tests/compat.py b/tests/compat.py deleted file mode 100644 index 6d9dec9a..00000000 --- a/tests/compat.py +++ /dev/null @@ -1,12 +0,0 @@ -# flake8: noqa - -import sys - -PY3 = sys.version_info[0] == 3 - -if PY3: - string_types = (str,) - text_type = str -else: - string_types = (basestring,) - text_type = unicode diff --git a/tests/test_api_jws.py b/tests/test_api_jws.py index b5021245..5e1b2eb2 100644 --- a/tests/test_api_jws.py +++ b/tests/test_api_jws.py @@ -13,8 +13,6 @@ ) from jwt.utils import base64url_decode, force_bytes, force_unicode -from .compat import string_types, text_type - try: from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.serialization import ( @@ -107,7 +105,7 @@ def test_decode_fails_when_alg_is_not_on_method_algorithms_param( def test_decode_works_with_unicode_token(self, jws): secret = "secret" - unicode_jws = text_type( + unicode_jws = ( "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9" ".eyJoZWxsbyI6ICJ3b3JsZCJ9" ".tvagLDLoaiJKxOKqpBXSEGy7SYSifZhjntgm9ctpyj8" @@ -732,13 +730,13 @@ def test_encode_headers_parameter_adds_headers(self, jws, payload): headers = {"testheader": True} token = jws.encode(payload, "secret", headers=headers) - if not isinstance(token, string_types): + if not isinstance(token, str): token = token.decode() header = token[0 : token.index(".")].encode() header = base64url_decode(header) - if not isinstance(header, text_type): + if not isinstance(header, str): header = header.decode() header_obj = json.loads(header) diff --git a/tox.ini b/tox.ini index 0b62eabe..3434b3ae 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,10 @@ [tox] -envlist = lint, typing, py{27,34,35,36,37}-crypto, py{27,35,36,37}-contrib_crypto, py{27,35,36,37}-nocrypto +envlist = + lint + typing + py{35,36,37}-crypto + py{35,36,37}-contrib_crypto + py{35,36,37}-nocrypto [testenv]