commit:     cdb28416ebd24408a642a398c4ed3980b713d9fb
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Feb  3 09:31:42 2024 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sat Feb  3 09:31:42 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=cdb28416

dev-python/flask-api: Backport >=dev-python/flask-3 support

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 .../flask-api/files/flask-api-3.1-flask-3.patch    | 84 ++++++++++++++++++++++
 ...k-api-3.1-r1.ebuild => flask-api-3.1-r2.ebuild} |  9 ++-
 2 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/dev-python/flask-api/files/flask-api-3.1-flask-3.patch 
b/dev-python/flask-api/files/flask-api-3.1-flask-3.patch
new file mode 100644
index 000000000000..92eddb8d8df0
--- /dev/null
+++ b/dev-python/flask-api/files/flask-api-3.1-flask-3.patch
@@ -0,0 +1,84 @@
+From 9c998897f67d8aa959dc3005d7d22f36568b6938 Mon Sep 17 00:00:00 2001
+From: Arthur Taylor <art...@codders.de>
+Date: Sat, 21 Oct 2023 09:53:02 +0200
+Subject: [PATCH] Add compatibility code to deal with Flask and Werkzeug
+ deprecations
+
+---
+ flask_api/helpers.py   |  5 +++++
+ flask_api/parsers.py   |  2 +-
+ flask_api/renderers.py | 11 +++++++++--
+ flask_api/request.py   |  2 +-
+ 4 files changed, 16 insertions(+), 4 deletions(-)
+ create mode 100644 flask_api/helpers.py
+
+diff --git a/flask_api/helpers.py b/flask_api/helpers.py
+new file mode 100644
+index 0000000..f83dd31
+--- /dev/null
++++ b/flask_api/helpers.py
+@@ -0,0 +1,5 @@
++def url_decode_stream(stream):
++    import urllib
++    body = stream.read()
++    body_str = body.decode()
++    return dict(urllib.parse.parse_qsl(body_str))
+diff --git a/flask_api/parsers.py b/flask_api/parsers.py
+index 56f45f6..d056210 100644
+--- a/flask_api/parsers.py
++++ b/flask_api/parsers.py
+@@ -2,8 +2,8 @@
+ 
+ from werkzeug.formparser import MultiPartParser as WerkzeugMultiPartParser
+ from werkzeug.formparser import default_stream_factory
+-from werkzeug.urls import url_decode_stream
+ 
++from flask_api.helpers import url_decode_stream
+ from flask_api import exceptions
+ 
+ 
+diff --git a/flask_api/renderers.py b/flask_api/renderers.py
+index a9aed23..b5951a2 100644
+--- a/flask_api/renderers.py
++++ b/flask_api/renderers.py
+@@ -1,8 +1,8 @@
+ import pydoc
+ import re
+ 
++import flask
+ from flask import current_app, render_template, request
+-from flask.globals import _request_ctx_stack
+ 
+ from flask_api.compat import apply_markdown
+ from flask_api.mediatypes import MediaType
+@@ -95,7 +95,14 @@ def render(self, data, media_type, **options):
+             mock_content = self._html_escape(text)
+ 
+         # Determine the allowed methods on this view.
+-        adapter = _request_ctx_stack.top.url_adapter
++        if hasattr(flask, 'globals') and \
++            hasattr(flask.globals, 'request_ctx'):
++            # update session for Flask >= 2.2
++            ctx = flask.globals.request_ctx._get_current_object()
++        else:  # pragma: no cover
++            # update session for Flask < 2.2
++            ctx = flask._request_ctx_stack.top
++        adapter = ctx.url_adapter
+         allowed_methods = adapter.allowed_methods()
+ 
+         endpoint = request.url_rule.endpoint
+diff --git a/flask_api/request.py b/flask_api/request.py
+index 33c3eaa..647dfc6 100644
+--- a/flask_api/request.py
++++ b/flask_api/request.py
+@@ -2,9 +2,9 @@
+ 
+ from flask import Request
+ from werkzeug.datastructures import MultiDict
+-from werkzeug.urls import url_decode_stream
+ from werkzeug.wsgi import get_content_length
+ 
++from flask_api.helpers import url_decode_stream
+ from flask_api.negotiation import DefaultNegotiation
+ from flask_api.settings import default_settings
+ 

diff --git a/dev-python/flask-api/flask-api-3.1-r1.ebuild 
b/dev-python/flask-api/flask-api-3.1-r2.ebuild
similarity index 77%
rename from dev-python/flask-api/flask-api-3.1-r1.ebuild
rename to dev-python/flask-api/flask-api-3.1-r2.ebuild
index 10d27309b67b..0f0ad223c49c 100644
--- a/dev-python/flask-api/flask-api-3.1-r1.ebuild
+++ b/dev-python/flask-api/flask-api-3.1-r2.ebuild
@@ -24,13 +24,18 @@ SLOT="0"
 KEYWORDS="~amd64 ~arm64 ~x86"
 
 RDEPEND="
-       <dev-python/flask-3[${PYTHON_USEDEP}]
+       dev-python/flask[${PYTHON_USEDEP}]
        dev-python/markdown[${PYTHON_USEDEP}]
-       <dev-python/werkzeug-3[${PYTHON_USEDEP}]
+       dev-python/werkzeug[${PYTHON_USEDEP}]
 "
 
 distutils_enable_tests pytest
 
+PATCHES=(
+       # 
https://github.com/flask-api/flask-api/commit/9c998897f67d8aa959dc3005d7d22f36568b6938
+       "${FILESDIR}/${P}-flask-3.patch"
+)
+
 python_install_all() {
        local DOCS=( docs/about/release-notes.md docs/api-guide/* docs/index.md 
)
        distutils-r1_python_install_all

Reply via email to