From a3dcc29edf8b919f8e37afede96136238b1646bf Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Thu, 7 Nov 2024 10:20:17 +0100 Subject: [PATCH] fix: compat for flask-oauthlib --- invenio_oauthclient/_compat.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/invenio_oauthclient/_compat.py b/invenio_oauthclient/_compat.py index 6cd1a955..10cc484b 100644 --- a/invenio_oauthclient/_compat.py +++ b/invenio_oauthclient/_compat.py @@ -2,12 +2,15 @@ # # This file is part of Invenio. # Copyright (C) 2015-2018 CERN. +# Copyright (C) 2024 Graz University of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Compat.""" +import urllib + import werkzeug try: @@ -23,6 +26,14 @@ def monkey_patch_werkzeug(): except ImportError: werkzeug.cached_property = werkzeug.utils.cached_property werkzeug.parse_options_header = werkzeug.http.parse_options_header - werkzeug.url_quote = werkzeug.urls.url_quote - werkzeug.url_decode = werkzeug.urls.url_decode - werkzeug.url_encode = werkzeug.urls.url_encode + werkzeug.url_quote = urllib.parse.quote + werkzeug.url_decode = urllib.parse.parse_qs + werkzeug.url_encode = urllib.parse.urlencode + + try: + # werkzeug >= 3.0 has removed following functions from werkzeug.urls + from werkzeug.urls import url_quote + except ImportError: + werkzeug.urls.url_quote = urllib.parse.quote + werkzeug.urls.url_decode = urllib.parse.parse_qs + werkzeug.urls.url_encode = urllib.parse.urlencode