From 30d4c5a7f91e2425211b51c479f2f1e7a37f98b9 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Mon, 26 Nov 2018 00:28:26 +0900 Subject: [PATCH] Import collection ABC's from correct module (#384) * Move ABCs imports to compat.py to reuse the imports from other modules * Import collection ABC's from correct module --- jwt/api_jws.py | 3 +-- jwt/api_jwt.py | 7 +------ jwt/compat.py | 5 +++++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/jwt/api_jws.py b/jwt/api_jws.py index 8039e9be..a9354adb 100644 --- a/jwt/api_jws.py +++ b/jwt/api_jws.py @@ -1,7 +1,6 @@ import binascii import json import warnings -from collections import Mapping try: # import required by mypy to perform type checking, not used for normal execution from typing import Callable, Dict, List, Optional, Union # NOQA @@ -11,7 +10,7 @@ from .algorithms import ( Algorithm, get_default_algorithms, has_crypto, requires_cryptography # NOQA ) -from .compat import binary_type, string_types, text_type +from .compat import Mapping, binary_type, string_types, text_type from .exceptions import ( DecodeError, InvalidAlgorithmError, InvalidSignatureError, InvalidTokenError diff --git a/jwt/api_jwt.py b/jwt/api_jwt.py index 0836ec07..85504acf 100644 --- a/jwt/api_jwt.py +++ b/jwt/api_jwt.py @@ -2,11 +2,6 @@ import warnings from calendar import timegm from datetime import datetime, timedelta -try: - # Importing ABCs from collections will be removed in PY3.8 - from collections.abc import Iterable, Mapping -except ImportError: - from collections import Iterable, Mapping try: # import required by mypy to perform type checking, not used for normal execution from typing import Callable, Dict, List, Optional, Union # NOQA @@ -15,7 +10,7 @@ from .api_jws import PyJWS from .algorithms import Algorithm, get_default_algorithms # NOQA -from .compat import string_types +from .compat import Iterable, Mapping, string_types from .exceptions import ( DecodeError, ExpiredSignatureError, ImmatureSignatureError, InvalidAudienceError, InvalidIssuedAtError, diff --git a/jwt/compat.py b/jwt/compat.py index c30f109c..e79e258e 100644 --- a/jwt/compat.py +++ b/jwt/compat.py @@ -20,6 +20,11 @@ string_types = (text_type, binary_type) +try: + # Importing ABCs from collections will be removed in PY3.8 + from collections.abc import Iterable, Mapping +except ImportError: + from collections import Iterable, Mapping try: constant_time_compare = hmac.compare_digest