diff options
author | Bastien Vallet <bastien.vallet@gmail.com> | 2019-11-13 03:39:43 +0100 |
---|---|---|
committer | José Padilla <jpadilla@webapplicate.com> | 2019-11-12 21:39:43 -0500 |
commit | 8c93b2a314788798680febadfc5cac05b8dee5a5 (patch) | |
tree | 503f806f86b7e3b5024be1a8aedb06d2ef2fc27c | |
parent | c404473271a199a7445b0e2a348e47893988bbc7 (diff) | |
download | pyjwt-8c93b2a314788798680febadfc5cac05b8dee5a5.tar.gz |
Remove Python 2.7 compatibility (#457)
* Remove py27 support
* [py27] Remove useless compatibility files
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | appveyor.yml | 9 | ||||
-rw-r--r-- | jwt/__main__.py | 4 | ||||
-rw-r--r-- | jwt/compat.py | 64 | ||||
-rwxr-xr-x | setup.py | 9 | ||||
-rw-r--r-- | tests/compat.py | 12 | ||||
-rw-r--r-- | tests/test_api_jws.py | 8 | ||||
-rw-r--r-- | tox.ini | 7 |
8 files changed, 31 insertions, 87 deletions
diff --git a/.travis.yml b/.travis.yml index d0123bb..98eb22a 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 2dad7d7..ac139e9 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 c20a41f..1493e50 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 918ff4a..b4fec15 100644 --- a/jwt/compat.py +++ b/jwt/compat.py @@ -4,20 +4,10 @@ versions of python, and compatibility wrappers around optional packages. """ # 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 @@ try: 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) @@ -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 @@ setup( "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 6d9dec9..0000000 --- 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 b502124..5e1b2eb 100644 --- a/tests/test_api_jws.py +++ b/tests/test_api_jws.py @@ -13,8 +13,6 @@ from jwt.exceptions import ( ) 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 @@ class TestJWS: def test_decode_works_with_unicode_token(self, jws): secret = "secret" - unicode_jws = text_type( + unicode_jws = ( "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9" ".eyJoZWxsbyI6ICJ3b3JsZCJ9" ".tvagLDLoaiJKxOKqpBXSEGy7SYSifZhjntgm9ctpyj8" @@ -732,13 +730,13 @@ class TestJWS: 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) @@ -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] |