Accepting request 917994 from devel:languages:python

- Restore python39-failures.patch, which is actually still needed.
- Remove python39-failures.patch and replace it with actual fix
  of the issue in remove_deprecated_loop_argument.patch.
- Add backport_fix_for_setting_cookies.patch for backport of
  fixes from 3.8 branch.
- Add python39-failures.patch to fix test problems with Python 3.9.7+
  (gh#aio-libs/aiohttp#5991).

OBS-URL: https://build.opensuse.org/request/show/917994
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-aiohttp?expand=0&rev=24
This commit is contained in:
Dominique Leuenberger 2021-09-11 20:24:15 +00:00 committed by Git OBS Bridge
commit 3abed77515
5 changed files with 257 additions and 0 deletions

View File

@ -0,0 +1,93 @@
From d0453ed56820e32802be743bf7a7b7027f9c9589 Mon Sep 17 00:00:00 2001
From: Sam Bull <aa6bs0@sambull.org>
Date: Sat, 14 Nov 2020 15:24:43 +0000
Subject: [PATCH 1/7] Backport fix for setting cookies
---
CHANGES/5233.bugfix | 1 +
aiohttp/web_protocol.py | 21 ++++++++++-----------
tests/test_web_exceptions.py | 28 ++++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 11 deletions(-)
--- /dev/null
+++ b/CHANGES/5233.bugfix
@@ -0,0 +1 @@
+Fix cookies disappearing from HTTPExceptions.
--- a/aiohttp/web_protocol.py
+++ b/aiohttp/web_protocol.py
@@ -423,9 +423,7 @@ class RequestHandler(BaseProtocol):
finally:
self._current_request = None
except HTTPException as exc:
- resp = Response(
- status=exc.status, reason=exc.reason, text=exc.text, headers=exc.headers
- )
+ resp = exc
reset = await self.finish_response(request, resp, start_time)
except asyncio.CancelledError:
raise
@@ -437,6 +435,15 @@ class RequestHandler(BaseProtocol):
resp = self.handle_error(request, 500, exc)
reset = await self.finish_response(request, resp, start_time)
else:
+ # Deprecation warning (See #2415)
+ if getattr(resp, "__http_exception__", False):
+ warnings.warn(
+ "returning HTTPException object is deprecated "
+ "(#2415) and will be removed, "
+ "please raise the exception instead",
+ DeprecationWarning,
+ )
+
reset = await self.finish_response(request, resp, start_time)
return resp, reset
@@ -486,14 +493,6 @@ class RequestHandler(BaseProtocol):
except (asyncio.CancelledError, ConnectionError):
self.log_debug("Ignored premature client disconnection")
break
- # Deprecation warning (See #2415)
- if getattr(resp, "__http_exception__", False):
- warnings.warn(
- "returning HTTPException object is deprecated "
- "(#2415) and will be removed, "
- "please raise the exception instead",
- DeprecationWarning,
- )
# Drop the processed task from asyncio.Task.all_tasks() early
del task
--- a/tests/test_web_exceptions.py
+++ b/tests/test_web_exceptions.py
@@ -203,3 +203,31 @@ def test_HTTPException_retains_cause() -
tb = "".join(format_exception(ei.type, ei.value, ei.tb))
assert "CustomException" in tb
assert "direct cause" in tb
+
+
+async def test_HTTPException_retains_cookie(aiohttp_client):
+ @web.middleware
+ async def middleware(request, handler):
+ try:
+ return await handler(request)
+ except web.HTTPException as exc:
+ exc.set_cookie("foo", request["foo"])
+ raise exc
+
+ async def save(request):
+ request["foo"] = "works"
+ raise web.HTTPFound("/show")
+
+ async def show(request):
+ return web.Response(text=request.cookies["foo"])
+
+ app = web.Application(middlewares=[middleware])
+ app.router.add_route("GET", "/save", save)
+ app.router.add_route("GET", "/show", show)
+ client = await aiohttp_client(app)
+
+ resp = await client.get("/save")
+ assert resp.status == 200
+ assert str(resp.url)[-5:] == "/show"
+ text = await resp.text()
+ assert text == "works"

View File

@ -1,3 +1,22 @@
-------------------------------------------------------------------
Fri Sep 10 14:22:31 UTC 2021 - Matej Cepl <mcepl@suse.com>
- Restore python39-failures.patch, which is actually still needed.
-------------------------------------------------------------------
Thu Sep 9 20:05:44 UTC 2021 - Matej Cepl <mcepl@suse.com>
- Remove python39-failures.patch and replace it with actual fix
of the issue in remove_deprecated_loop_argument.patch.
- Add backport_fix_for_setting_cookies.patch for backport of
fixes from 3.8 branch.
-------------------------------------------------------------------
Wed Sep 8 21:10:23 UTC 2021 - Matej Cepl <mcepl@suse.com>
- Add python39-failures.patch to fix test problems with Python 3.9.7+
(gh#aio-libs/aiohttp#5991).
------------------------------------------------------------------- -------------------------------------------------------------------
Tue Jun 8 19:15:11 UTC 2021 - Matej Cepl <mcepl@suse.com> Tue Jun 8 19:15:11 UTC 2021 - Matej Cepl <mcepl@suse.com>

View File

@ -29,6 +29,15 @@ Patch0: unbundle-http-parser.patch
# PATCH-FIX-UPSTREAM stdlib-typing_extensions.patch gh#aio-libs/aiohttp#5374 mcepl@suse.com # PATCH-FIX-UPSTREAM stdlib-typing_extensions.patch gh#aio-libs/aiohttp#5374 mcepl@suse.com
# Fix typing_extensions imports. # Fix typing_extensions imports.
Patch1: stdlib-typing_extensions.patch Patch1: stdlib-typing_extensions.patch
# PATCH-FIX-UPSTREAM python39-failures.patch gh#aio-libs/aiohttp#5991 mcepl@suse.com
# Bridge over Python 3.9.6 v 3.9.7 incompatibilities
Patch2: python39-failures.patch
# PATCH-FIX-UPSTREAM remove_deprecated_loop_argument.patch gh#aio-libs/aiohttp#5991 mcepl@suse.com
# remove deprecated loop argument
Patch3: remove_deprecated_loop_argument.patch
# PATCH-FIX-UPSTREAM backport_fix_for_setting_cookies.patch gh#aio-libs/aiohttp#5233 mcepl@suse.com
# backport of fixes from 3.8 branch
Patch4: backport_fix_for_setting_cookies.patch
BuildRequires: %{python_module Cython} BuildRequires: %{python_module Cython}
BuildRequires: %{python_module async_timeout >= 3.0} BuildRequires: %{python_module async_timeout >= 3.0}
BuildRequires: %{python_module attrs >= 17.3.0} BuildRequires: %{python_module attrs >= 17.3.0}

77
python39-failures.patch Normal file
View File

@ -0,0 +1,77 @@
---
tests/test_web_middleware.py | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
--- a/tests/test_web_middleware.py
+++ b/tests/test_web_middleware.py
@@ -1,4 +1,5 @@
import re
+import sys
from typing import Any
import pytest
@@ -6,6 +7,7 @@ from yarl import URL
from aiohttp import web
+py39 = sys.version_info[:3] >= (3, 9, 7)
async def test_middleware_modifies_response(loop, aiohttp_client) -> None:
async def handler(request):
@@ -410,7 +412,10 @@ async def test_old_style_middleware(loop
txt = await resp.text()
assert "OK[old style middleware]" == txt
- assert len(warning_checker) == 1
+ if py39:
+ assert len(warning_checker) == 2
+ else:
+ assert len(warning_checker) == 1
msg = str(warning_checker.list[0].message)
assert re.match(
"^old-style middleware "
@@ -464,7 +469,10 @@ async def test_mixed_middleware(loop, ai
txt = await resp.text()
assert "OK[new style 2][old style 2][new style 1][old style 1]" == txt
- assert len(w) == 2
+ if py39:
+ assert len(w) == 3
+ else:
+ assert len(w) == 2
tmpl = (
"^old-style middleware "
'"<function test_mixed_middleware.<locals>.'
@@ -503,7 +511,10 @@ async def test_old_style_middleware_clas
txt = await resp.text()
assert "OK[old style middleware]" == txt
- assert len(warning_checker) == 1
+ if py39:
+ assert len(warning_checker) == 2
+ else:
+ assert len(warning_checker) == 1
msg = str(warning_checker.list[0].message)
assert re.match(
"^old-style middleware "
@@ -537,7 +548,10 @@ async def test_new_style_middleware_clas
txt = await resp.text()
assert "OK[new style middleware]" == txt
- assert len(warning_checker) == 0
+ if py39:
+ assert len(warning_checker) == 1
+ else:
+ assert len(warning_checker) == 0
async def test_new_style_middleware_method(loop, aiohttp_client) -> None:
@@ -563,4 +577,7 @@ async def test_new_style_middleware_meth
txt = await resp.text()
assert "OK[new style middleware]" == txt
- assert len(warning_checker) == 0
+ if py39:
+ assert len(warning_checker) == 1
+ else:
+ assert len(warning_checker) == 0

View File

@ -0,0 +1,59 @@
From dd3a89130b5769218550159ebbab9e28d8b974a3 Mon Sep 17 00:00:00 2001
From: Hanaasagi <ambiguous404@gmail.com>
Date: Tue, 3 Aug 2021 11:53:45 +0000
Subject: [PATCH] fix: remove deprecated loop argument for asnycio.sleep/gather
calls
---
CHANGES/5905.bugfix | 1 +
aiohttp/web.py | 4 +---
tests/test_locks.py | 6 +++---
3 files changed, 5 insertions(+), 6 deletions(-)
create mode 100644 CHANGES/5905.bugfix
--- /dev/null
+++ b/CHANGES/5905.bugfix
@@ -0,0 +1 @@
+remove deprecated loop argument for asnycio.sleep/gather calls
--- a/aiohttp/web.py
+++ b/aiohttp/web.py
@@ -440,9 +440,7 @@ def _cancel_tasks(
for task in to_cancel:
task.cancel()
- loop.run_until_complete(
- asyncio.gather(*to_cancel, loop=loop, return_exceptions=True)
- )
+ loop.run_until_complete(asyncio.gather(*to_cancel, return_exceptions=True))
for task in to_cancel:
if task.cancelled():
--- a/tests/test_locks.py
+++ b/tests/test_locks.py
@@ -18,7 +18,7 @@ class TestEventResultOrError:
return 1
t = loop.create_task(c())
- await asyncio.sleep(0, loop=loop)
+ await asyncio.sleep(0)
e = Exception()
ev.set(exc=e)
assert (await t) == e
@@ -31,7 +31,7 @@ class TestEventResultOrError:
return 1
t = loop.create_task(c())
- await asyncio.sleep(0, loop=loop)
+ await asyncio.sleep(0)
ev.set()
assert (await t) == 1
@@ -43,7 +43,7 @@ class TestEventResultOrError:
t1 = loop.create_task(c())
t2 = loop.create_task(c())
- await asyncio.sleep(0, loop=loop)
+ await asyncio.sleep(0)
ev.cancel()
ev.set()