Skip to content

Commit

Permalink
Fix #2793: Drop removed functionality from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Mar 6, 2018
1 parent 4b7260d commit 20928e1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGES/2793.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop removed functionality about passing ``StreamReader`` as data at client side.
36 changes: 2 additions & 34 deletions docs/client_quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:

Expand Down

0 comments on commit 20928e1

Please sign in to comment.