diff --git a/.azure-pipelines/stage-test.yml b/.azure-pipelines/stage-test.yml index 95ae35c7aa3..cf4e8d390c4 100644 --- a/.azure-pipelines/stage-test.yml +++ b/.azure-pipelines/stage-test.yml @@ -26,14 +26,14 @@ stages: # python.version: 'pypy3' # no_extensions: 'Y' # image: 'ubuntu-latest' - # Py36-Cython-Win: - # python.version: '3.6' - # no_extensions: '' - # image: 'windows-latest' - # Py37-Cython-Win: - # python.version: '3.7' - # no_extensions: '' - # image: 'windows-latest' + Py36-Cython-Win: + python.version: '3.6' + no_extensions: '' + image: 'windows-latest' + Py37-Cython-Win: + python.version: '3.7' + no_extensions: '' + image: 'windows-latest' Py36-Cython-Mac: python.version: '3.6' no_extensions: '' diff --git a/.gitattributes b/.gitattributes index 78fe3eeae3c..054db27e6ee 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ tests/sample.* binary -tests/data.unknown_mime_type -tests/hello.txt.gz \ No newline at end of file +tests/data.unknown_mime_type binary +tests/hello.txt.gz binary diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index 0a6b199b369..1f28040c5ef 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -536,7 +536,7 @@ def url_for(self, *, filename: Union[str, Path], # type: ignore if filepath.is_file(): # TODO cache file content # with file watcher for cache invalidation - with open(str(filepath), mode='rb') as f: + with filepath.open('rb') as f: file_bytes = f.read() h = self._get_file_hash(file_bytes) url = url.with_query({self.VERSION_KEY: h}) diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index 6753a6d45d5..a8372754364 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -1248,7 +1248,7 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: + with fname.open('rb') as f: resp = await client.post( '/', data={'some': f, 'test': b'data'}, chunked=True) assert 200 == resp.status @@ -1270,7 +1270,7 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: + with fname.open('rb') as f: resp = await client.post( '/', data={'some': f}, @@ -1321,8 +1321,8 @@ async def test_POST_FILES_STR(aiohttp_client, fname) -> None: async def handler(request): data = await request.post() - with fname.open() as f: - content1 = f.read() + with fname.open('rb') as f: + content1 = f.read().decode() content2 = data['some'] assert content1 == content2 return web.Response() @@ -1331,8 +1331,8 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: - resp = await client.post('/', data={'some': f.read()}) + with fname.open('rb') as f: + resp = await client.post('/', data={'some': f.read().decode()}) assert 200 == resp.status resp.close() @@ -1350,7 +1350,7 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: + with fname.open('rb') as f: resp = await client.post('/', data=f.read()) assert 200 == resp.status resp.close() @@ -1370,7 +1370,7 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: + with fname.open('rb') as f: resp = await client.post('/', data=[('some', f)]) assert 200 == resp.status resp.close() @@ -1391,7 +1391,7 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: + with fname.open('rb') as f: form = aiohttp.FormData() form.add_field('some', f, content_type='text/plain') resp = await client.post('/', data=form) @@ -1403,14 +1403,14 @@ async def test_POST_FILES_SINGLE(aiohttp_client, fname) -> None: async def handler(request): data = await request.text() - with fname.open('r') as f: - content = f.read() + with fname.open('rb') as f: + content = f.read().decode() assert content == data - # if system cannot determine 'application/pgp-keys' MIME type - # then use 'application/octet-stream' default - assert request.content_type in ['application/pgp-keys', - 'text/plain', - 'application/octet-stream'] + # if system cannot determine 'text/x-python' MIME type + # then use 'application/octet-stream' default + assert request.content_type in ['text/plain', + 'application/octet-stream', + 'text/x-python'] assert 'content-disposition' not in request.headers return web.Response() @@ -1419,7 +1419,7 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: + with fname.open('rb') as f: resp = await client.post('/', data=f) assert 200 == resp.status resp.close() @@ -1430,14 +1430,14 @@ async def test_POST_FILES_SINGLE_content_disposition( async def handler(request): data = await request.text() - with fname.open('r') as f: - content = f.read() + with fname.open('rb') as f: + content = f.read().decode() assert content == data - # if system cannot determine 'application/pgp-keys' MIME type - # then use 'application/octet-stream' default - assert request.content_type in ['application/pgp-keys', - 'text/plain', - 'application/octet-stream'] + # if system cannot determine 'application/pgp-keys' MIME type + # then use 'application/octet-stream' default + assert request.content_type in ['text/plain', + 'application/octet-stream', + 'text/x-python'] assert request.headers['content-disposition'] == ( "inline; filename=\"conftest.py\"; filename*=utf-8''conftest.py") @@ -1447,7 +1447,7 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: + with fname.open('rb') as f: resp = await client.post( '/', data=aiohttp.get_payload(f, disposition='inline')) assert 200 == resp.status @@ -1529,8 +1529,8 @@ async def test_POST_FILES_WITH_DATA(aiohttp_client, fname) -> None: async def handler(request): data = await request.post() assert data['test'] == 'true' - assert data['some'].content_type in ['application/pgp-keys', - 'text/plain; charset=utf-8', + assert data['some'].content_type in ['text/x-python', + 'text/plain', 'application/octet-stream'] assert data['some'].filename == fname.name with fname.open('rb') as f: @@ -1542,7 +1542,7 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with fname.open() as f: + with fname.open('rb') as f: resp = await client.post('/', data={'test': 'true', 'some': f}) assert 200 == resp.status resp.close() diff --git a/tests/test_web_functional.py b/tests/test_web_functional.py index 4857dc4b8aa..b9c1a3f7a34 100644 --- a/tests/test_web_functional.py +++ b/tests/test_web_functional.py @@ -311,8 +311,8 @@ async def test_post_single_file(aiohttp_client) -> None: def check_file(fs): fullname = here / fs.filename - with fullname.open() as f: - test_data = f.read().encode() + with fullname.open('rb') as f: + test_data = f.read() data = fs.file.read() assert test_data == data @@ -331,7 +331,7 @@ async def handler(request): fname = here / 'data.unknown_mime_type' - resp = await client.post('/', data=[fname.open()]) + resp = await client.post('/', data=[fname.open('rb')]) assert 200 == resp.status @@ -374,8 +374,8 @@ async def test_post_files(aiohttp_client) -> None: def check_file(fs): fullname = here / fs.filename - with fullname.open() as f: - test_data = f.read().encode() + with fullname.open('rb') as f: + test_data = f.read() data = fs.file.read() assert test_data == data @@ -392,8 +392,8 @@ async def handler(request): app.router.add_post('/', handler) client = await aiohttp_client(app) - with (here / 'data.unknown_mime_type').open() as f1: - with (here / 'conftest.py').open() as f2: + with (here / 'data.unknown_mime_type').open('rb') as f1: + with (here / 'conftest.py').open('rb') as f2: resp = await client.post('/', data=[f1, f2]) assert 200 == resp.status diff --git a/tests/test_web_sendfile_functional.py b/tests/test_web_sendfile_functional.py index 1e257f5ac72..c2be5dbff0d 100644 --- a/tests/test_web_sendfile_functional.py +++ b/tests/test_web_sendfile_functional.py @@ -322,9 +322,9 @@ async def test_static_file_huge(aiohttp_client, tmp_path) -> None: file_path = tmp_path / 'huge_data.unknown_mime_type' # fill 20MB file - with file_path.open('w') as f: + with file_path.open('wb') as f: for i in range(1024*20): - f.write(chr(i % 64 + 0x20) * 1024) + f.write((chr(i % 64 + 0x20) * 1024).encode()) file_st = file_path.stat() @@ -754,9 +754,9 @@ async def test_static_file_huge_cancel(aiohttp_client, tmp_path) -> None: file_path = tmp_path / 'huge_data.unknown_mime_type' # fill 100MB file - with file_path.open('w') as f: + with file_path.open('wb') as f: for i in range(1024*20): - f.write(chr(i % 64 + 0x20) * 1024) + f.write((chr(i % 64 + 0x20) * 1024).encode()) task = None