Skip to content

Commit

Permalink
Use AppKey in aiohttp 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
JCHacking authored Nov 12, 2023
1 parent b008016 commit d17a09e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions demo/login_required_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
]
_Handler = Callable[[web.Request], Awaitable[web.StreamResponse]]

user_key = web.AppKey("user", str)

def login_required(fn: _Handler) -> _Handler:
async def wrapped(
Expand All @@ -29,15 +30,15 @@ async def wrapped(
user_id = session["user_id"]
# actually load user from your database (e.g. with aiopg)
user = DATABASE[user_id]
app["user"] = user
app[user_key] = user
return await fn(request, *args, **kwargs)

return wrapped


@login_required
async def handler(request: web.Request) -> web.Response:
user = request.app["user"]
user = request.app[user_key]
return web.Response(text=f"User {user} authorized")


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-e .
aiohttp==3.8.5
aiohttp==3.9.0b1
aiomcache==0.8.1
cryptography==41.0.5
docker==6.1.3
Expand Down

0 comments on commit d17a09e

Please sign in to comment.