Skip to content

Commit ba9d7eb

Browse files
Bump aiohttp from 3.8.6 to 3.10.10 (#1220)
* Bump aiohttp from 3.8.6 to 3.10.10 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.8.6 to 3.10.10. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](aio-libs/aiohttp@v3.8.6...v3.10.10) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Update keys * Fix * Upgrade aiohttp-jnja2 * Fix * Upgrade aiohttp-security * fix * Chat * imagetagger * get_config * moderator * polls * missing file --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sam Bull <[email protected]>
1 parent 17f708f commit ba9d7eb

File tree

26 files changed

+84
-64
lines changed

26 files changed

+84
-64
lines changed

demos/blog/aiohttpdemo_blog/db.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
)
1212
from sqlalchemy.sql import select
1313

14+
from aiohttpdemo_blog.typedefs import config_key, db_key
15+
1416

1517
class Base(DeclarativeBase):
1618
pass
@@ -41,9 +43,9 @@ class Posts(Base):
4143

4244

4345
async def init_db(app):
44-
dsn = construct_db_url(app["config"]["database"])
46+
dsn = construct_db_url(app[config_key]["database"])
4547
engine = create_async_engine(dsn)
46-
app["db_pool"] = async_sessionmaker(engine)
48+
app[db_key] = async_sessionmaker(engine)
4749

4850
yield
4951

demos/blog/aiohttpdemo_blog/db_auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from aiohttp_security.abc import AbstractAuthorizationPolicy
22

33
from aiohttpdemo_blog import db
4+
from aiohttpdemo_blog.typedefs import db_key
45

56

67
class DBAuthorizationPolicy(AbstractAuthorizationPolicy):
78
def __init__(self, app):
89
self.app = app
910

1011
async def authorized_userid(self, identity):
11-
async with self.app["db_pool"]() as sess:
12+
async with self.app[db_key]() as sess:
1213
user = await db.get_user_by_name(sess, identity)
1314
if user:
1415
return identity

demos/blog/aiohttpdemo_blog/main.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@
99
from aiohttp_session import setup as setup_session
1010
from aiohttp_session.redis_storage import RedisStorage
1111
from redis import asyncio as aioredis
12+
1213
from aiohttpdemo_blog.db_auth import DBAuthorizationPolicy
1314
from aiohttpdemo_blog.db import init_db
1415
from aiohttpdemo_blog.routes import setup_routes
1516
from aiohttpdemo_blog.settings import load_config, PACKAGE_NAME
17+
from aiohttpdemo_blog.typedefs import config_key
1618

1719

1820
log = logging.getLogger(__name__)
1921

2022

21-
async def setup_redis(app):
22-
23-
redis_host = app["config"]["redis"]["REDIS_HOST"]
24-
redis_port = app["config"]["redis"]["REDIS_PORT"]
23+
async def setup_redis(app: web.Application):
24+
redis_host = app[config_key]["redis"]["REDIS_HOST"]
25+
redis_port = app[config_key]["redis"]["REDIS_PORT"]
2526

26-
redis = await aioredis.from_url(f"redis://{redis_host}:{redis_port}")
27-
app["redis"] = redis
28-
return redis
27+
return await aioredis.from_url(f"redis://{redis_host}:{redis_port}")
2928

3029

3130
async def current_user_ctx_processor(request):
@@ -38,7 +37,7 @@ async def init_app(config):
3837

3938
app = web.Application()
4039

41-
app['config'] = config
40+
app[config_key] = config
4241

4342
setup_routes(app)
4443

@@ -61,7 +60,7 @@ async def init_app(config):
6160
DBAuthorizationPolicy(app)
6261
)
6362

64-
log.debug(app['config'])
63+
log.debug(app[config_key])
6564

6665
return app
6766

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import Any
2+
3+
from aiohttp import web
4+
from sqlalchemy.ext.asyncio import async_sessionmaker
5+
6+
config_key = web.AppKey("config_key", dict[str, Any])
7+
db_key = web.AppKey("db_key", async_sessionmaker)

demos/blog/aiohttpdemo_blog/views.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from aiohttpdemo_blog import db
66
from aiohttpdemo_blog.forms import validate_login_form
7+
from aiohttpdemo_blog.typedefs import db_key
78

89

910
def redirect(router, route_name):
@@ -17,7 +18,7 @@ async def index(request):
1718
if not username:
1819
raise redirect(request.app.router, 'login')
1920

20-
async with request.app['db_pool']() as sess:
21+
async with request.app[db_key]() as sess:
2122
current_user = await db.get_user_by_name(sess, username)
2223
posts = await db.get_posts_with_joined_users(sess)
2324

@@ -33,7 +34,7 @@ async def login(request):
3334
if request.method == 'POST':
3435
form = await request.post()
3536

36-
async with request.app['db_pool']() as sess:
37+
async with request.app[db_key]() as sess:
3738
error = await validate_login_form(sess, form)
3839

3940
if error:
@@ -64,7 +65,7 @@ async def create_post(request):
6465
if request.method == 'POST':
6566
form = await request.post()
6667

67-
async with request.app['db_pool'].begin() as sess:
68+
async with request.app[db_key].begin() as sess:
6869
current_user = await db.get_user_by_name(sess, username)
6970
sess.add(db.Posts(body=form["body"], user_id=current_user.id))
7071
raise redirect(request.app.router, 'index')

demos/blog/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
aiohttp==3.8.5
2-
aiohttp-jinja2==1.5.1
3-
aiohttp_security[session]==0.4.0
1+
aiohttp==3.10.10
2+
aiohttp-jinja2==1.6
3+
aiohttp-security[session]==0.5.0
44
asyncpg==0.30.0
55
bcrypt==4.1.3
66
pytoml==0.1.21

demos/blog/tests/test_stuff.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
generate_password_hash,
44
check_password_hash
55
)
6+
from aiohttpdemo_blog.typedefs import db_key
67

78

89
def test_security():
@@ -25,7 +26,7 @@ async def test_login_form(tables_and_data, client):
2526
'username': 'Adam',
2627
'password': 'adam'
2728
}
28-
async with client.server.app["db_pool"]() as sess:
29+
async with client.server.app[db_key]() as sess:
2930
error = await validate_login_form(sess, invalid_form)
3031
assert error
3132

demos/chat/aiohttpdemo_chat/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import aiohttp_jinja2
66
from aiohttp import web
7-
from aiohttpdemo_chat.views import index
7+
from aiohttpdemo_chat.views import index, ws_key
88

99

1010
async def init_app():
1111

1212
app = web.Application()
1313

14-
app['websockets'] = {}
14+
app[ws_key] = {}
1515

1616
app.on_shutdown.append(shutdown)
1717

@@ -24,9 +24,9 @@ async def init_app():
2424

2525

2626
async def shutdown(app):
27-
for ws in app['websockets'].values():
27+
for ws in app[ws_key].values():
2828
await ws.close()
29-
app['websockets'].clear()
29+
app[ws_key].clear()
3030

3131

3232
async def get_app():

demos/chat/aiohttpdemo_chat/views.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
log = logging.getLogger(__name__)
99

10+
ws_key = web.AppKey("ws_key", dict[str, web.WebSocketResponse])
11+
1012

1113
def get_random_name():
1214
fake = Faker()
@@ -26,24 +28,24 @@ async def index(request):
2628

2729
await ws_current.send_json({'action': 'connect', 'name': name})
2830

29-
for ws in request.app['websockets'].values():
31+
for ws in request.app[ws_key].values():
3032
await ws.send_json({'action': 'join', 'name': name})
31-
request.app['websockets'][name] = ws_current
33+
request.app[ws_key][name] = ws_current
3234

3335
while True:
3436
msg = await ws_current.receive()
3537

3638
if msg.type == aiohttp.WSMsgType.text:
37-
for ws in request.app['websockets'].values():
39+
for ws in request.app[ws_key].values():
3840
if ws is not ws_current:
3941
await ws.send_json(
4042
{'action': 'sent', 'name': name, 'text': msg.data})
4143
else:
4244
break
4345

44-
del request.app['websockets'][name]
46+
del request.app[ws_key][name]
4547
log.info('%s disconnected.', name)
46-
for ws in request.app['websockets'].values():
48+
for ws in request.app[ws_key].values():
4749
await ws.send_json({'action': 'disconnect', 'name': name})
4850

4951
return ws_current

demos/chat/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
aiohttp==3.8.5
2-
aiohttp-jinja2==1.5.1
1+
aiohttp==3.10.10
2+
aiohttp-jinja2==1.6
33
faker==26.0.0

0 commit comments

Comments
 (0)