Skip to content

Commit

Permalink
Drop streamer (#3538)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Jan 14, 2019
1 parent 2bec332 commit 0e60406
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 302 deletions.
1 change: 1 addition & 0 deletions CHANGES/3538.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop ``@aiohttp.streamer`` decorator, use async generators instead.
4 changes: 0 additions & 4 deletions aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
payload_type
)

from .payload_streamer import streamer

from .resolver import AsyncResolver, DefaultResolver, ThreadedResolver

from .signals import Signal
Expand Down Expand Up @@ -177,8 +175,6 @@
'TextIOPayload',
'get_payload',
'payload_type',
# payload_streamer
'streamer',
# resolver
'AsyncResolver',
'DefaultResolver',
Expand Down
74 changes: 0 additions & 74 deletions aiohttp/payload_streamer.py

This file was deleted.

47 changes: 6 additions & 41 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,51 +1519,16 @@ async def handler(request):
with fname.open('rb') as f:
data_size = len(f.read())

with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def stream(writer, fname):
with fname.open('rb') as f:
data = f.read(100)
while data:
await writer.write(data)
data = f.read(100)

resp = await client.post(
'/', data=stream(fname), headers={'Content-Length': str(data_size)})
assert 200 == resp.status
resp.close()


async def test_POST_STREAM_DATA_no_params(aiohttp_client, fname) -> None:

async def handler(request):
assert request.content_type == 'application/octet-stream'
content = await request.read()
@async_generator
async def gen(fname):
with fname.open('rb') as f:
expected = f.read()
assert request.content_length == len(expected)
assert content == expected

return web.Response()

app = web.Application()
app.router.add_post('/', handler)
client = await aiohttp_client(app)

with fname.open('rb') as f:
data_size = len(f.read())

with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def stream(writer):
with fname.open('rb') as f:
data = f.read(100)
while data:
await yield_(data)
data = f.read(100)
while data:
await writer.write(data)
data = f.read(100)

resp = await client.post(
'/', data=stream, headers={'Content-Length': str(data_size)})
'/', data=gen(fname), headers={'Content-Length': str(data_size)})
assert 200 == resp.status
resp.close()

Expand Down
121 changes: 0 additions & 121 deletions tests/test_client_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,27 +894,6 @@ async def gen():
await req.close()


async def test_data_stream_deprecated(loop, buf, conn) -> None:
with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def gen(writer):
await writer.write(b'binary data')
await writer.write(b' result')

req = ClientRequest(
'POST', URL('http://python.org/'), data=gen(), loop=loop)
assert req.chunked
assert req.headers['TRANSFER-ENCODING'] == 'chunked'

resp = await req.send(conn)
assert asyncio.isfuture(req._writer)
await resp.wait_for_close()
assert req._writer is None
assert buf.split(b'\r\n\r\n', 1)[1] == \
b'b\r\nbinary data\r\n7\r\n result\r\n0\r\n\r\n'
await req.close()


async def test_data_file(loop, buf, conn) -> None:
req = ClientRequest(
'POST', URL('http://python.org/'),
Expand Down Expand Up @@ -959,33 +938,6 @@ async def throw_exc():
await req.close()


async def test_data_stream_exc_deprecated(loop, conn) -> None:
fut = loop.create_future()

with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def gen(writer):
await writer.write(b'binary data')
await fut

req = ClientRequest(
'POST', URL('http://python.org/'), data=gen(), loop=loop)
assert req.chunked
assert req.headers['TRANSFER-ENCODING'] == 'chunked'

async def throw_exc():
await asyncio.sleep(0.01, loop=loop)
fut.set_exception(ValueError)

loop.create_task(throw_exc())

await req.send(conn)
await req._writer
# assert conn.close.called
assert conn.protocol.set_exception.called
await req.close()


async def test_data_stream_exc_chain(loop, conn) -> None:
fut = loop.create_future()

Expand Down Expand Up @@ -1015,36 +967,6 @@ async def throw_exc():
await req.close()


async def test_data_stream_exc_chain_deprecated(loop, conn) -> None:
fut = loop.create_future()

with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def gen(writer):
await fut

req = ClientRequest('POST', URL('http://python.org/'),
data=gen(), loop=loop)

inner_exc = ValueError()

async def throw_exc():
await asyncio.sleep(0.01, loop=loop)
fut.set_exception(inner_exc)

loop.create_task(throw_exc())

await req.send(conn)
await req._writer
# assert connection.close.called
assert conn.protocol.set_exception.called
outer_exc = conn.protocol.set_exception.call_args[0][0]
assert isinstance(outer_exc, ValueError)
assert inner_exc is outer_exc
assert inner_exc is outer_exc
await req.close()


async def test_data_stream_continue(loop, buf, conn) -> None:
@async_generator
async def gen():
Expand All @@ -1070,33 +992,6 @@ async def coro():
resp.close()


async def test_data_stream_continue_deprecated(loop, buf, conn) -> None:
with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def gen(writer):
await writer.write(b'binary data')
await writer.write(b' result')
await writer.write_eof()

req = ClientRequest(
'POST', URL('http://python.org/'), data=gen(),
expect100=True, loop=loop)
assert req.chunked

async def coro():
await asyncio.sleep(0.0001, loop=loop)
req._continue.set_result(1)

loop.create_task(coro())

resp = await req.send(conn)
await req._writer
assert buf.split(b'\r\n\r\n', 1)[1] == \
b'b\r\nbinary data\r\n7\r\n result\r\n0\r\n\r\n'
await req.close()
resp.close()


async def test_data_continue(loop, buf, conn) -> None:
req = ClientRequest(
'POST', URL('http://python.org/'), data=b'data',
Expand Down Expand Up @@ -1131,22 +1026,6 @@ async def gen():
resp.close()


async def test_close_deprecated(loop, buf, conn) -> None:
with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def gen(writer):
await asyncio.sleep(0.00001, loop=loop)
await writer.write(b'result')

req = ClientRequest(
'POST', URL('http://python.org/'), data=gen(), loop=loop)
resp = await req.send(conn)
await req.close()
assert buf.split(b'\r\n\r\n', 1)[1] == b'6\r\nresult\r\n0\r\n\r\n'
await req.close()
resp.close()


async def test_custom_response_class(loop, conn) -> None:
class CustomResponse(ClientResponse):
def read(self, decode=False):
Expand Down
62 changes: 0 additions & 62 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,37 +791,6 @@ async def handler(request):
assert resp.headers.get('Content-Length') == str(len(resp_data))


async def test_response_with_streamer(aiohttp_client, fname) -> None:

with fname.open('rb') as f:
data = f.read()

data_size = len(data)

with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def stream(writer, f_name):
with f_name.open('rb') as f:
data = f.read(100)
while data:
await writer.write(data)
data = f.read(100)

async def handler(request):
headers = {'Content-Length': str(data_size)}
return web.Response(body=stream(fname), headers=headers)

app = web.Application()
app.router.add_get('/', handler)
client = await aiohttp_client(app)

resp = await client.get('/')
assert 200 == resp.status
resp_data = await resp.read()
assert resp_data == data
assert resp.headers.get('Content-Length') == str(len(resp_data))


async def test_response_with_async_gen_no_params(aiohttp_client,
fname) -> None:

Expand Down Expand Up @@ -853,37 +822,6 @@ async def handler(request):
assert resp.headers.get('Content-Length') == str(len(resp_data))


async def test_response_with_streamer_no_params(aiohttp_client, fname) -> None:

with fname.open('rb') as f:
data = f.read()

data_size = len(data)

with pytest.warns(DeprecationWarning):
@aiohttp.streamer
async def stream(writer):
with fname.open('rb') as f:
data = f.read(100)
while data:
await writer.write(data)
data = f.read(100)

async def handler(request):
headers = {'Content-Length': str(data_size)}
return web.Response(body=stream, headers=headers)

app = web.Application()
app.router.add_get('/', handler)
client = await aiohttp_client(app)

resp = await client.get('/')
assert 200 == resp.status
resp_data = await resp.read()
assert resp_data == data
assert resp.headers.get('Content-Length') == str(len(resp_data))


async def test_response_with_file(aiohttp_client, fname) -> None:

with fname.open('rb') as f:
Expand Down

0 comments on commit 0e60406

Please sign in to comment.