|
1 | 1 | import datetime |
2 | 2 | from warnings import warn |
3 | 3 |
|
| 4 | +# In Python 2.7 collections.abc is a part of the collections module. |
| 5 | +try: |
| 6 | + from collections.abc import Sequence, Set |
| 7 | +except ImportError: # pragma: no cover |
| 8 | + from collections import Sequence, Set |
| 9 | + |
4 | 10 | from flask import current_app |
5 | 11 |
|
6 | 12 | # Older versions of pyjwt do not have the requires_cryptography set. Also, |
@@ -44,9 +50,8 @@ def token_location(self): |
44 | 50 | locations = current_app.config['JWT_TOKEN_LOCATION'] |
45 | 51 | if isinstance(locations, str): |
46 | 52 | locations = (locations,) |
47 | | - elif not isinstance(locations, (tuple, list, frozenset, set)): |
48 | | - raise RuntimeError('JWT_TOKEN_LOCATION must be a tuple, a list, a frozenset ' |
49 | | - 'or a set') |
| 53 | + elif not isinstance(locations, (Sequence, Set)): |
| 54 | + raise RuntimeError('JWT_TOKEN_LOCATION must be a sequence or a set') |
50 | 55 | elif not locations: |
51 | 56 | raise RuntimeError('JWT_TOKEN_LOCATION must contain at least one ' |
52 | 57 | 'of "headers", "cookies", "query_string", or "json"') |
@@ -207,9 +212,8 @@ def blacklist_checks(self): |
207 | 212 | check_type = current_app.config['JWT_BLACKLIST_TOKEN_CHECKS'] |
208 | 213 | if isinstance(check_type, str): |
209 | 214 | check_type = (check_type,) |
210 | | - elif not isinstance(check_type, (tuple, list, frozenset, set)): |
211 | | - raise RuntimeError('JWT_BLACKLIST_TOKEN_CHECKS must be a tuple, a list, a ' |
212 | | - 'frozenset or a set') |
| 215 | + elif not isinstance(check_type, (Sequence, Set)): |
| 216 | + raise RuntimeError('JWT_BLACKLIST_TOKEN_CHECKS must be a sequence or a set') |
213 | 217 | for item in check_type: |
214 | 218 | if item not in ('access', 'refresh'): |
215 | 219 | err = 'JWT_BLACKLIST_TOKEN_CHECKS must be "access" or "refresh"' |
|
0 commit comments