diff --git a/CHANGES/2793.doc b/CHANGES/2793.doc new file mode 100644 index 00000000000..3aa6a2f9cb7 --- /dev/null +++ b/CHANGES/2793.doc @@ -0,0 +1 @@ +Drop removed functionality about passing ``StreamReader`` as data at client side. \ No newline at end of file diff --git a/docs/client_quickstart.rst b/docs/client_quickstart.rst index e86532068f4..bd4e1c5967a 100644 --- a/docs/client_quickstart.rst +++ b/docs/client_quickstart.rst @@ -320,11 +320,11 @@ As a simple case, simply provide a file-like object for your body:: Or you can use :class:`aiohttp.streamer` decorator:: @aiohttp.streamer - def file_sender(writer, file_name=None): + async def file_sender(writer, file_name=None): with open(file_name, 'rb') as f: chunk = f.read(2**16) while chunk: - yield from writer.write(chunk) + await writer.write(chunk) chunk = f.read(2**16) # Then you can use file_sender as a data provider: @@ -333,38 +333,6 @@ Or you can use :class:`aiohttp.streamer` decorator:: data=file_sender(file_name='huge_file')) as resp: print(await resp.text()) -Also it is possible to use a :class:`~aiohttp.streams.StreamReader` -object. Lets say we want to upload a file from another request and -calculate the file SHA1 hash:: - - async def feed_stream(resp, stream): - h = hashlib.sha256() - - while True: - chunk = await resp.content.readany() - if not chunk: - break - h.update(chunk) - stream.feed_data(chunk) - - return h.hexdigest() - - resp = session.get('http://httpbin.org/post') - stream = StreamReader() - loop.create_task(session.post('http://httpbin.org/post', - data=stream)) - - file_hash = await feed_stream(resp, stream) - - -Because the response content attribute is a -:class:`~aiohttp.streams.StreamReader`, you can chain get and post -requests together:: - - r = await session.get('http://python.org') - await session.post('http://httpbin.org/post', - data=r.content) - .. _aiohttp-client-websockets: