forked from playpauseandstop/aiohttp-middlewares
-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotations.py
51 lines (39 loc) · 1.14 KB
/
annotations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
===============================
aiohttp_middlewares.annotations
===============================
Type annotation shortcuts for ``aiohttp_middlewares`` library.
"""
import importlib
from typing import (
Any,
Awaitable,
Callable,
Collection,
Dict,
Pattern,
Type,
Union,
)
from aiohttp import web
from yarl import URL
try:
# (<3.9.0) Try to import Middleware from aiohttp.web_middlewares
Middleware = importlib.import_module('aiohttp.web_middlewares')._Middleware
except AttributeError:
# (>=3.9.0) If that fails, import Middleware from aiohttp.typedefs
Middleware = importlib.import_module('aiohttp.typedefs').Middleware
# Make flake8 happy
(Middleware,)
DictStrAny = Dict[str, Any]
DictStrStr = Dict[str, str]
ExceptionType = Type[Exception]
# FIXME: Drop Handler type definition after `aiohttp-middlewares` will require
# only `aiohttp>=3.8.0`
Handler = Callable[[web.Request], Awaitable[web.StreamResponse]]
IntCollection = Collection[int]
StrCollection = Collection[str]
Url = Union[str, Pattern[str], URL]
UrlCollection = Collection[Url]
UrlDict = Dict[Url, StrCollection]
Urls = Union[UrlCollection, UrlDict]