Skip to content

Commit

Permalink
support aiohttp-3.8.0
Browse files Browse the repository at this point in the history
This fixes the rename of aiohttp.web_routedef._SimpleHandler to aiohttp.typedefs.Handler while remaining backwards incompatible.   This also fixes the upcoming rename of aiohttp.web_app._Middleware to aiohttp.typedefs.Middleware.
  • Loading branch information
cmalek committed Nov 3, 2021
1 parent 9b6dc41 commit eb2a04e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions aiodogstatsd/contrib/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
from typing import AsyncIterator, Callable, Optional, cast

from aiohttp import web
from aiohttp.web_app import _Middleware
from aiohttp.web_routedef import _SimpleHandler
try:
from aiohttp.typedefs import Middleware
except ImportError:
# aiohttp < 3.8.0
from aiohttp.web_app import _Middleware as Middleware
try:
from aiohttp.typedefs import Handler
except ImportError:
# aiohttp < 3.8.0
from aiohttp.web_routedef import _SimpleHandler as Handler
from aiohttp.web_urldispatcher import DynamicResource, MatchInfoError

from aiodogstatsd import Client, typedefs
Expand Down Expand Up @@ -55,10 +63,10 @@ def middleware_factory(
request_duration_metric_name: str = DEAFULT_REQUEST_DURATION_METRIC_NAME,
collect_not_allowed: bool = False,
collect_not_found: bool = False,
) -> _Middleware:
) -> Middleware:
@web.middleware
async def middleware(
request: web.Request, handler: _SimpleHandler
request: web.Request, handler: Handler
) -> web.StreamResponse:
loop = get_event_loop()
request_started_at = loop.time()
Expand Down

0 comments on commit eb2a04e

Please sign in to comment.