Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mutipart .serialize() docs #2970

Merged
merged 1 commit into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/2965.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace multipart writer `.serialize()` method with `.write()` in documentation.
16 changes: 12 additions & 4 deletions docs/multipart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ instance as :meth:`aiohttp.ClientSession.request` ``data`` argument::

await session.post('http://example.com', data=mpwriter)

Behind the scenes :meth:`MultipartWriter.serialize` will yield chunks of every
Behind the scenes :meth:`MultipartWriter.write` will yield chunks of every
part and if body part has `Content-Encoding` or `Content-Transfer-Encoding`
they will be applied on streaming content.

Please note, that on :meth:`MultipartWriter.serialize` all the file objects
Please note, that on :meth:`MultipartWriter.write` all the file objects
will be read until the end and there is no way to repeat a request without
rewinding their pointers to the start.

Expand All @@ -206,9 +206,17 @@ using chunked transfer encoding by default. To overcome this issue, you have
to serialize a :class:`MultipartWriter` by our own in the way to calculate its
size::

body = b''.join(mpwriter.serialize())
class Writer:
def __init__(self):
self.buffer = bytearray()

async def write(self, data):
self.buffer.extend(data)

writer = Writer()
mpwriter.writer(writer)
await aiohttp.post('http://example.com',
data=body, headers=mpwriter.headers)
data=writer.buffer, headers=mpwriter.headers)

Sometimes the server response may not be well formed: it may or may not
contains nested parts. For instance, we request a resource which returns
Expand Down