Skip to content

Commit 598ff5c

Browse files
Update aiohttp requirement from <3.7 to <3.9 (#632)
1 parent 320f2b5 commit 598ff5c

12 files changed

+49
-65
lines changed

aiohttp_session/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
import json
77
import sys
88
import time
9-
from typing import Any, Callable, Dict, Iterator, Mapping, MutableMapping, Optional, Union, cast
9+
from typing import (Any, Awaitable, Callable, Dict, Iterator, Mapping,
10+
MutableMapping, Optional, Union, cast)
1011

1112
from aiohttp import web
12-
from aiohttp.web_middlewares import _Handler, _Middleware
13+
14+
Handler = Callable[[web.Request], Awaitable[web.StreamResponse]]
15+
Middleware = Callable[[web.Request, Handler], Awaitable[web.StreamResponse]]
1316

1417
if sys.version_info >= (3, 8):
1518
from typing import TypedDict
@@ -162,14 +165,14 @@ async def new_session(request: web.Request) -> Session:
162165
return session
163166

164167

165-
def session_middleware(storage: 'AbstractStorage') -> _Middleware:
168+
def session_middleware(storage: 'AbstractStorage') -> Middleware:
166169
if not isinstance(storage, AbstractStorage):
167170
raise RuntimeError("Expected AbstractStorage got {}".format(storage))
168171

169172
@web.middleware
170173
async def factory(
171174
request: web.Request,
172-
handler: _Handler
175+
handler: Handler
173176
) -> web.StreamResponse:
174177
request[STORAGE_KEY] = storage
175178
raise_response = False
@@ -286,7 +289,7 @@ def save_cookie(
286289
path=params["path"])
287290
else:
288291
# Ignoring type for params until aiohttp#4238 is released
289-
response.set_cookie(self._cookie_name, cookie_data, **params) # type: ignore
292+
response.set_cookie(self._cookie_name, cookie_data, **params)
290293

291294

292295
class SimpleCookieStorage(AbstractStorage):

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pytest-aiohttp==0.3.0
1616
pytest-cov==3.0.0
1717
pytest-mock==3.6.1
1818
pytest-sugar==0.9.4
19-
aiohttp<3.7
19+
aiohttp<3.9
2020
multidict==4.7.6
2121
chardet==3.0.4
2222
yarl==1.7.2

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def read(f):
3838
'Programming Language :: Python :: 3.5',
3939
'Programming Language :: Python :: 3.6',
4040
'Programming Language :: Python :: 3.7',
41+
'Programming Language :: Python :: 3.8',
42+
'Programming Language :: Python :: 3.9',
43+
'Programming Language :: Python :: 3.10',
4144
'Topic :: Internet :: WWW/HTTP',
4245
'Framework :: AsyncIO',
4346
'Framework :: aiohttp',

tests/test_abstract_storage.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from aiohttp import web
77
from aiohttp.test_utils import TestClient
8-
from aiohttp.web_middlewares import _Handler
9-
from aiohttp_session import SimpleCookieStorage, get_session, setup as setup_middleware
8+
from aiohttp_session import (Handler, SimpleCookieStorage,
9+
get_session, setup as setup_middleware)
1010

1111
from .typedefs import AiohttpClient
1212

@@ -18,13 +18,12 @@ def make_cookie(client: TestClient, data: Dict[str, Any]) -> None:
1818
}
1919

2020
value = json.dumps(session_data)
21-
# Ignoring type until aiohttp#4252 is released
2221
client.session.cookie_jar.update_cookies(
23-
{'AIOHTTP_SESSION': value} # type: ignore
22+
{'AIOHTTP_SESSION': value}
2423
)
2524

2625

27-
def create_app(handler: _Handler) -> web.Application:
26+
def create_app(handler: Handler) -> web.Application:
2827
app = web.Application()
2928
setup_middleware(app, SimpleCookieStorage(max_age=10))
3029
app.router.add_route('GET', '/', handler)

tests/test_cookie_storage.py

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

55
from aiohttp import web
66
from aiohttp.test_utils import TestClient
7-
from aiohttp.web_middlewares import _Handler
8-
from aiohttp_session import Session, SimpleCookieStorage, get_session, session_middleware
7+
from aiohttp_session import (Handler, Session, SimpleCookieStorage,
8+
get_session, session_middleware)
99

1010
from .typedefs import AiohttpClient
1111

@@ -17,13 +17,12 @@ def make_cookie(client: TestClient, data: Dict[str, Any]) -> None:
1717
}
1818

1919
value = json.dumps(session_data)
20-
# Ignoring type until aiohttp#4252 is released
2120
client.session.cookie_jar.update_cookies(
22-
{'AIOHTTP_SESSION': value} # type: ignore
21+
{'AIOHTTP_SESSION': value}
2322
)
2423

2524

26-
def create_app(handler: _Handler) -> web.Application:
25+
def create_app(handler: Handler) -> web.Application:
2726
middleware = session_middleware(SimpleCookieStorage())
2827
app = web.Application(middlewares=[middleware])
2928
app.router.add_route('GET', '/', handler)

tests/test_encrypted_cookie_storage.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import pytest
88
from aiohttp import web
99
from aiohttp.test_utils import TestClient
10-
from aiohttp.web_middlewares import _Handler
11-
from aiohttp_session import Session, get_session, new_session, session_middleware
10+
from aiohttp_session import Handler, Session, get_session, new_session, session_middleware
1211
from aiohttp_session.cookie_storage import EncryptedCookieStorage
1312
from cryptography.fernet import Fernet
1413

@@ -27,14 +26,13 @@ def make_cookie(client: TestClient, fernet: Fernet, data: Dict[str, Any]) -> Non
2726
cookie_data = json.dumps(session_data).encode('utf-8')
2827
encrypted_data = fernet.encrypt(cookie_data).decode('utf-8')
2928

30-
# Ignoring type until aiohttp#4252 is released
3129
client.session.cookie_jar.update_cookies(
32-
{'AIOHTTP_SESSION': encrypted_data} # type: ignore
30+
{'AIOHTTP_SESSION': encrypted_data}
3331
)
3432

3533

3634
def create_app(
37-
handler: _Handler,
35+
handler: Handler,
3836
key: Union[str, bytes, bytearray]
3937
) -> web.Application:
4038
middleware = session_middleware(EncryptedCookieStorage(key))
@@ -188,9 +186,8 @@ async def logout(request: web.Request) -> web.StreamResponse:
188186
evil_cookie = resp.cookies['AIOHTTP_SESSION'].value
189187
resp = await client.delete('/')
190188
assert resp.cookies['AIOHTTP_SESSION'].value == ""
191-
# Ignoring type until aiohttp#4252 is released
192189
client.session.cookie_jar.update_cookies(
193-
{'AIOHTTP_SESSION': evil_cookie} # type: ignore
190+
{'AIOHTTP_SESSION': evil_cookie}
194191
)
195192
resp = await client.get('/')
196193
assert resp.cookies['AIOHTTP_SESSION'].value != evil_cookie
@@ -226,9 +223,8 @@ async def handler(request: web.Request) -> web.StreamResponse:
226223
assert 'AIOHTTP_SESSION' in resp.cookies
227224
cookie = resp.cookies['AIOHTTP_SESSION'].value
228225
await asyncio.sleep(MAX_AGE + 1)
229-
# Ignoring type until aiohttp#4252 is released
230226
client.session.cookie_jar.update_cookies(
231-
{'AIOHTTP_SESSION': cookie} # type: ignore
227+
{'AIOHTTP_SESSION': cookie}
232228
)
233229
resp = await client.get('/')
234230
body = await resp.text()

tests/test_http_exception.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from typing import Tuple
22

33
from aiohttp import web
4-
from aiohttp.web_middlewares import _Handler
5-
from aiohttp_session import SimpleCookieStorage, get_session, session_middleware
4+
from aiohttp_session import Handler, SimpleCookieStorage, get_session, session_middleware
65

76
from .typedefs import AiohttpClient
87

98

10-
def create_app(*handlers: Tuple[str, _Handler]) -> web.Application:
9+
def create_app(*handlers: Tuple[str, Handler]) -> web.Application:
1110
middleware = session_middleware(SimpleCookieStorage())
1211
app = web.Application(middlewares=[middleware])
1312
for url, handler in handlers:

tests/test_memcached_storage.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
import aiomcache
88
from aiohttp import web
99
from aiohttp.test_utils import TestClient
10-
from aiohttp.web_middlewares import _Handler
11-
from aiohttp_session import Session, get_session, session_middleware
10+
from aiohttp_session import Handler, Session, get_session, session_middleware
1211
from aiohttp_session.memcached_storage import MemcachedStorage
1312

1413
from .typedefs import AiohttpClient
1514

1615

1716
def create_app(
18-
handler: _Handler,
17+
handler: Handler,
1918
memcached: aiomcache.Client,
2019
max_age: Optional[int] = None,
2120
key_factory: Callable[[], str] = lambda: uuid.uuid4().hex
@@ -40,9 +39,8 @@ async def make_cookie(
4039
key = uuid.uuid4().hex
4140
storage_key = ('AIOHTTP_SESSION_' + key).encode('utf-8')
4241
await memcached.set(storage_key, bytes(value, 'utf-8'))
43-
# Ignoring type until aiohttp#4252 is released
4442
client.session.cookie_jar.update_cookies(
45-
{'AIOHTTP_SESSION': key} # type: ignore
43+
{'AIOHTTP_SESSION': key}
4644
)
4745

4846

@@ -53,9 +51,8 @@ async def make_cookie_with_bad_value(
5351
key = uuid.uuid4().hex
5452
storage_key = ('AIOHTTP_SESSION_' + key).encode('utf-8')
5553
await memcached.set(storage_key, b'')
56-
# Ignoring type until aiohttp#4252 is released
5754
client.session.cookie_jar.update_cookies(
58-
{'AIOHTTP_SESSION': key} # type: ignore
55+
{'AIOHTTP_SESSION': key}
5956
)
6057

6158

@@ -217,9 +214,8 @@ async def handler(request: web.Request) -> web.StreamResponse:
217214
return web.Response(body=b'OK')
218215

219216
client = await aiohttp_client(create_app(handler, memcached))
220-
# Ignoring type until aiohttp#4252 is released
221217
client.session.cookie_jar.update_cookies(
222-
{'AIOHTTP_SESSION': 'invalid_key'} # type: ignore
218+
{'AIOHTTP_SESSION': 'invalid_key'}
223219
)
224220
resp = await client.get('/')
225221
assert resp.status == 200
@@ -273,9 +269,8 @@ async def logout(request: web.Request) -> web.StreamResponse:
273269
evil_cookie = resp.cookies['AIOHTTP_SESSION'].value
274270
resp = await client.delete('/')
275271
assert resp.cookies['AIOHTTP_SESSION'].value == ""
276-
# Ignoring type until aiohttp#4252 is released
277272
client.session.cookie_jar.update_cookies(
278-
{'AIOHTTP_SESSION': evil_cookie} # type: ignore
273+
{'AIOHTTP_SESSION': evil_cookie}
279274
)
280275
resp = await client.get('/')
281276
assert resp.cookies['AIOHTTP_SESSION'].value != evil_cookie

tests/test_nacl_storage.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import pytest
99
from aiohttp import web
1010
from aiohttp.test_utils import TestClient
11-
from aiohttp.web_middlewares import _Handler
12-
from aiohttp_session import Session, get_session, new_session, session_middleware
11+
from aiohttp_session import Handler, Session, get_session, new_session, session_middleware
1312
from aiohttp_session.nacl_storage import NaClCookieStorage
1413
from nacl.encoding import Base64Encoder
1514

@@ -43,7 +42,7 @@ def make_cookie(
4342

4443

4544
def create_app(
46-
handler: _Handler,
45+
handler: Handler,
4746
key: bytes,
4847
max_age: Optional[int] = None
4948
) -> web.Application:
@@ -186,9 +185,8 @@ async def logout(request: web.Request) -> web.StreamResponse:
186185
evil_cookie = resp.cookies['AIOHTTP_SESSION'].value
187186
resp = await client.delete('/')
188187
assert resp.cookies['AIOHTTP_SESSION'].value == ""
189-
# Ignoring type until aiohttp#4252 is released
190188
client.session.cookie_jar.update_cookies(
191-
{'AIOHTTP_SESSION': evil_cookie} # type: ignore
189+
{'AIOHTTP_SESSION': evil_cookie}
192190
)
193191
resp = await client.get('/')
194192
assert resp.cookies['AIOHTTP_SESSION'].value != evil_cookie
@@ -235,9 +233,8 @@ async def handler(request: web.Request) -> web.StreamResponse:
235233
return web.Response(body=b'OK')
236234

237235
client = await aiohttp_client(create_app(handler, key))
238-
# Ignoring type until aiohttp#4252 is released
239236
client.session.cookie_jar.update_cookies(
240-
{'AIOHTTP_SESSION': 'bad key'} # type: ignore
237+
{'AIOHTTP_SESSION': 'bad key'}
241238
)
242239
resp = await client.get('/')
243240
assert resp.status == 200
@@ -291,9 +288,8 @@ async def handler(request: web.Request) -> web.StreamResponse:
291288
assert 'AIOHTTP_SESSION' in resp.cookies
292289
cookie = resp.cookies['AIOHTTP_SESSION'].value
293290
await asyncio.sleep(MAX_AGE + 1)
294-
# Ignoring type until aiohttp#4252 is released
295291
client.session.cookie_jar.update_cookies(
296-
{'AIOHTTP_SESSION': cookie} # type: ignore
292+
{'AIOHTTP_SESSION': cookie}
297293
)
298294
resp = await client.get('/')
299295
body = await resp.text()

tests/test_path_domain.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
from aiohttp import web
77
from aiohttp.test_utils import TestClient
8-
from aiohttp.web_middlewares import _Handler
9-
from aiohttp_session import SimpleCookieStorage, get_session, session_middleware
8+
from aiohttp_session import Handler, SimpleCookieStorage, get_session, session_middleware
109

1110
from .typedefs import AiohttpClient
1211

@@ -30,7 +29,7 @@ def make_cookie(
3029

3130

3231
def create_app(
33-
handler: _Handler,
32+
handler: Handler,
3433
path: Optional[str] = None,
3534
domain: Optional[str] = None
3635
) -> web.Application:

0 commit comments

Comments
 (0)