summaryrefslogtreecommitdiffstats
path: root/contrib/python/PyJWT/py3/jwt/api_jwt.py
diff options
context:
space:
mode:
authorAlexSm <[email protected]>2024-01-09 18:56:40 +0100
committerGitHub <[email protected]>2024-01-09 18:56:40 +0100
commite95f266d2a3e48e62015220588a4fd73d5d5a5cb (patch)
treea8a784b6931fe52ad5f511cfef85af14e5f63991 /contrib/python/PyJWT/py3/jwt/api_jwt.py
parent50a65e3b48a82d5b51f272664da389f2e0b0c99a (diff)
Library import 6 (#888)
Diffstat (limited to 'contrib/python/PyJWT/py3/jwt/api_jwt.py')
-rw-r--r--contrib/python/PyJWT/py3/jwt/api_jwt.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/contrib/python/PyJWT/py3/jwt/api_jwt.py b/contrib/python/PyJWT/py3/jwt/api_jwt.py
index f3b55d360ea..7d2177bf535 100644
--- a/contrib/python/PyJWT/py3/jwt/api_jwt.py
+++ b/contrib/python/PyJWT/py3/jwt/api_jwt.py
@@ -1,4 +1,5 @@
import json
+import warnings
from calendar import timegm
from collections.abc import Iterable, Mapping
from datetime import datetime, timedelta, timezone
@@ -66,14 +67,23 @@ class PyJWT:
self,
jwt: str,
key: str = "",
- algorithms: List[str] = None,
- options: Dict = None,
+ algorithms: Optional[List[str]] = None,
+ options: Optional[Dict] = None,
**kwargs,
) -> Dict[str, Any]:
- if options is None:
- options = {"verify_signature": True}
- else:
- options.setdefault("verify_signature", True)
+ options = dict(options or {}) # shallow-copy or initialize an empty dict
+ options.setdefault("verify_signature", True)
+
+ # If the user has set the legacy `verify` argument, and it doesn't match
+ # what the relevant `options` entry for the argument is, inform the user
+ # that they're likely making a mistake.
+ if "verify" in kwargs and kwargs["verify"] != options["verify_signature"]:
+ warnings.warn(
+ "The `verify` argument to `decode` does nothing in PyJWT 2.0 and newer. "
+ "The equivalent is setting `verify_signature` to False in the `options` dictionary. "
+ "This invocation has a mismatch between the kwarg and the option entry.",
+ category=DeprecationWarning,
+ )
if not options["verify_signature"]:
options.setdefault("verify_exp", False)
@@ -98,7 +108,7 @@ class PyJWT:
try:
payload = json.loads(decoded["payload"])
except ValueError as e:
- raise DecodeError("Invalid payload string: %s" % e)
+ raise DecodeError(f"Invalid payload string: {e}")
if not isinstance(payload, dict):
raise DecodeError("Invalid payload string: must be a json object")
@@ -112,8 +122,8 @@ class PyJWT:
self,
jwt: str,
key: str = "",
- algorithms: List[str] = None,
- options: Dict = None,
+ algorithms: Optional[List[str]] = None,
+ options: Optional[Dict] = None,
**kwargs,
) -> Dict[str, Any]:
decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs)