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

+4-2
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

+2-1
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

+8-9
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

+7
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

+4-3
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

+3-3
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

+2-1
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

+4-4
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

+7-5
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

+2-2
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

demos/graphql-demo/requirements-dev.txt

+3-3
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_graphql==1.1.0
1+
aiohttp==3.10.10
2+
aiohttp-jinja2==1.6
3+
aiohttp-graphql==1.1.0
44
aiodataloader==0.4.0
55
faker==26.0.0
66
trafaret_config==2.0.2

demos/imagetagger/imagetagger/app.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from aiohttp import web
88

99
from .routes import init_routes
10-
from .utils import init_config, Config, get_config, init_workers
10+
from .utils import Config, get_config, init_workers
1111
from .views import SiteHandler
1212

1313

@@ -24,7 +24,6 @@ def init_jinja2(app: web.Application) -> None:
2424
async def init_app(conf: Config) -> web.Application:
2525
app = web.Application()
2626
executor = await init_workers(app, conf.workers)
27-
init_config(app, conf)
2827
init_jinja2(app)
2928
handler = SiteHandler(conf, executor)
3029
init_routes(app, handler)

demos/imagetagger/imagetagger/utils.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from trafaret_config import commandline
1313
from .worker import warm, clean
1414

15+
executor_key = web.AppKey("executor_key", ProcessPoolExecutor)
1516

1617
PATH = pathlib.Path(__file__).parent.parent
1718
settings_file = os.environ.get('SETTINGS_FILE', 'api.dev.yml')
@@ -69,10 +70,6 @@ def get_config(argv: Any = None) -> Config:
6970
return config_from_dict(d)
7071

7172

72-
def init_config(app: web.Application, config: Config) -> None:
73-
app['config'] = config
74-
75-
7673
async def init_workers(
7774
app: web.Application, conf: WorkersConfig
7875
) -> ProcessPoolExecutor:
@@ -90,5 +87,5 @@ async def close_executor(app: web.Application) -> None:
9087
executor.shutdown(wait=True)
9188

9289
app.on_cleanup.append(close_executor)
93-
app['executor'] = executor
90+
app[executor_key] = executor
9491
return executor

demos/imagetagger/imagetagger/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aiohttp import web
77

88
from .worker import predict
9-
from .utils import Config
9+
from .utils import Config, executor_key
1010

1111

1212
class SiteHandler:
@@ -23,7 +23,7 @@ async def predict(self, request: web.Request) -> web.Response:
2323
form = await request.post()
2424
raw_data = form['file'].file.read()
2525
form["file"].file.close() # Not needed in aiohttp 4+.
26-
executor = request.app['executor']
26+
executor = request.app[executor_key]
2727
r = self._loop.run_in_executor
2828
raw_data = await r(executor, predict, raw_data)
2929
# raw_data = predict(raw_data)

demos/imagetagger/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
aiohttp==3.8.5
2-
aiohttp-jinja2==1.5.1
1+
aiohttp==3.10.10
2+
aiohttp-jinja2==1.6
33
keras==3.6.0
44
Pillow==11.0.0
55
tensorflow==2.16.1

demos/moderator/moderator/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ async def close_executor(app):
6363
executor.shutdown(wait=True)
6464

6565
app.on_cleanup.append(close_executor)
66-
app['executor'] = executor
6766
return executor

demos/moderator/requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
aiohttp==3.8.5
1+
aiohttp==3.10.10
22
trafaret==2.1.1
33
pyyaml==6.0.2
44
numpy==1.26.4

demos/moderator_bot/requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-i https://pypi.org/simple/
2-
aiohttp==3.8.5
2+
aiohttp==3.10.10
33
aioslacker==0.0.11
44
async-timeout==4.0.3
55
atomicwrites==1.4.1

demos/motortwit/requirements.txt

+3-3
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==0.4.0
1+
aiohttp==3.10.10
2+
aiohttp-jinja2==1.6
3+
aiohttp-security==0.5.0
44
bcrypt==4.1.3
55
faker==26.0.0
66
motor==3.6.0

demos/polls/aiohttpdemo_polls/db.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
55
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
66

7+
from aiohttpdemo_polls.typedefs import config_key, db_key
8+
79

810
class Base(DeclarativeBase):
911
pass
@@ -37,8 +39,8 @@ class RecordNotFound(Exception):
3739

3840

3941
async def pg_context(app):
40-
engine = create_async_engine(DSN.format(**app["config"]["postgres"]))
41-
app["db"] = async_sessionmaker(engine)
42+
engine = create_async_engine(DSN.format(**app[config_key]["postgres"]))
43+
app[db_key] = async_sessionmaker(engine)
4244

4345
yield
4446

@@ -59,7 +61,7 @@ async def get_question(sess, question_id):
5961

6062

6163
async def vote(app, question_id, choice_id):
62-
async with app["db"].begin() as sess:
64+
async with app[db_key].begin() as sess:
6365
result = await sess.get(Choice, choice_id)
6466
result.votes += 1
6567
if not result:

demos/polls/aiohttpdemo_polls/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
from aiohttpdemo_polls.middlewares import setup_middlewares
1010
from aiohttpdemo_polls.routes import setup_routes, setup_static_routes
1111
from aiohttpdemo_polls.settings import get_config
12+
from aiohttpdemo_polls.typedefs import config_key
1213

1314

1415
async def init_app(argv=None):
1516

1617
app = web.Application()
1718

18-
app['config'] = get_config(argv)
19+
app[config_key] = get_config(argv)
1920

2021
# setup Jinja2 template renderer
2122
aiohttp_jinja2.setup(
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)

0 commit comments

Comments
 (0)