Accepting request 1008309 from home:jayvdb:branches:devel:languages:python:flask

- Add upstream patch merged_pr_463.patch to support Werkzeug 2.2.

OBS-URL: https://build.opensuse.org/request/show/1008309
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:flask/python-flask-restx?expand=0&rev=17
This commit is contained in:
Matej Cepl 2022-10-05 22:48:53 +00:00 committed by Git OBS Bridge
parent 79042df58c
commit 70f044130a
3 changed files with 124 additions and 0 deletions

117
merged_pr_463.patch Normal file
View File

@ -0,0 +1,117 @@
From 82f7340ebb51e5c143b804bc0f20f785e96968c0 Mon Sep 17 00:00:00 2001
From: Ben Plowman <ben.plowman@gmail.com>
Date: Thu, 28 Jul 2022 15:01:56 -0700
Subject: [PATCH 1/2] Fix #460 - missing parse_rule method
This method was removed from the public API in werkzeug 2.2.0. Copying it into this project because the method is self-contained.
---
flask_restx/swagger.py | 47 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/flask_restx/swagger.py b/flask_restx/swagger.py
index 478aa86e..932e8d02 100644
--- a/flask_restx/swagger.py
+++ b/flask_restx/swagger.py
@@ -15,7 +15,6 @@
from six import string_types, itervalues, iteritems, iterkeys
from flask import current_app
-from werkzeug.routing import parse_rule
from . import fields
from .model import Model, ModelBase, OrderedModel
@@ -36,7 +35,6 @@
"default": "string",
}
-
#: Maps Python primitives types to Swagger ones
PY_TYPES = {
int: "integer",
@@ -55,6 +53,21 @@
r"^:raises\s+(?P<name>[\w\d_]+)\s*:\s*(?P<description>.*)$", re.MULTILINE
)
+RE_PARSE_RULE = re.compile(
+ r"""
+ (?P<static>[^<]*) # static rule data
+ <
+ (?:
+ (?P<converter>[a-zA-Z_][a-zA-Z0-9_]*) # converter name
+ (?:\((?P<args>.*?)\))? # converter arguments
+ \: # variable delimiter
+ )?
+ (?P<variable>[a-zA-Z_][a-zA-Z0-9_]*) # variable name
+ >
+ """,
+ re.VERBOSE,
+)
+
def ref(model):
"""Return a reference to model in definitions"""
@@ -74,6 +87,36 @@ def extract_path(path):
return RE_URL.sub(r"{\1}", path)
+def parse_rule(rule):
+ """
+ This originally lived in werkzeug.routing.parse_rule until it was removed in werkzeug 2.2.0. Copying it here to
+ avoid depending on the older version of werkzeug.
+ """
+ pos = 0
+ end = len(rule)
+ do_match = RE_PARSE_RULE.match
+ used_names = set()
+ while pos < end:
+ m = do_match(rule, pos)
+ if m is None:
+ break
+ data = m.groupdict()
+ if data["static"]:
+ yield None, None, data["static"]
+ variable = data["variable"]
+ converter = data["converter"] or "default"
+ if variable in used_names:
+ raise ValueError(f"variable name {variable!r} used twice.")
+ used_names.add(variable)
+ yield converter, data["args"] or None, variable
+ pos = m.end()
+ if pos < end:
+ remaining = rule[pos:]
+ if ">" in remaining or "<" in remaining:
+ raise ValueError(f"malformed url rule: {rule!r}")
+ yield None, None, remaining
+
+
def extract_path_params(path):
"""
Extract Flask-style parameters from an URL pattern as Swagger ones.
From 09e57b8af6ca5eddf52377aea32d99c4e03ad585 Mon Sep 17 00:00:00 2001
From: Ben Plowman <ben.plowman@gmail.com>
Date: Tue, 2 Aug 2022 14:45:15 -0700
Subject: [PATCH 2/2] Copy over previous docstring
---
flask_restx/swagger.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/flask_restx/swagger.py b/flask_restx/swagger.py
index 932e8d02..2b67709e 100644
--- a/flask_restx/swagger.py
+++ b/flask_restx/swagger.py
@@ -89,8 +89,11 @@ def extract_path(path):
def parse_rule(rule):
"""
- This originally lived in werkzeug.routing.parse_rule until it was removed in werkzeug 2.2.0. Copying it here to
- avoid depending on the older version of werkzeug.
+ Parse a rule and return it as generator. Each iteration yields tuples in the form
+ ``(converter, arguments, variable)``. If the converter is `None` it's a static url part, otherwise it's a dynamic
+ one.
+
+ Note: This originally lived in werkzeug.routing.parse_rule until it was removed in werkzeug 2.2.0.
"""
pos = 0
end = len(rule)

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Wed Oct 5 22:35:03 UTC 2022 - John Vandenberg <jayvdb@gmail.com>
- Add upstream patch merged_pr_463.patch to support Werkzeug 2.2.
-------------------------------------------------------------------
Fri Jul 15 13:18:17 UTC 2022 - Markéta Machová <mmachova@suse.com>

View File

@ -28,6 +28,8 @@ Group: Development/Languages/Python
Patch0: werkzeug.patch
#PATCH-FIX-UPSTREAM https://github.com/python-restx/flask-restx/pull/427 Handle Werkzeug 2.1.0 change to Response.autocorrect_location_header.
Patch1: redirect.patch
#PATCH-FIX-UPSTREAM https://github.com/python-restx/flask-restx/pull/463 Fix missing parse_rule method
Patch2: merged_pr_463.patch
URL: https://github.com/python-restx/flask-restx
Source: https://github.com/python-restx/flask-restx/archive/%{version}.tar.gz
BuildRequires: %{python_module Faker}