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

Payload refactoring #1664

Closed
wants to merge 5 commits into from
Closed

Payload refactoring #1664

wants to merge 5 commits into from

Conversation

fafhrd91
Copy link
Member

Payload refactoring

@fafhrd91
Copy link
Member Author

fafhrd91 commented Feb 20, 2017

some goals

  1. unify how we handle various types of payloads
  2. unify client/server implementation
  3. it needs to be backward compatible with existing clients

note: this is only about how we send payload

@fafhrd91
Copy link
Member Author

added streamer decorator for coroutine support as data provider

for usage check test_client_functional.py::test_POST_STREAM_DATA

@fafhrd91
Copy link
Member Author

@kxepal is this content-disposition right? inline; filename="test.txt"; filename*=utf-8''test.txt

@codecov-io
Copy link

codecov-io commented Feb 20, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@57cb76c). Click here to learn what that means.
The diff coverage is 100%.

@@            Coverage Diff            @@
##             master    #1664   +/-   ##
=========================================
  Coverage          ?   95.19%           
=========================================
  Files             ?       34           
  Lines             ?     7237           
  Branches          ?     1262           
=========================================
  Hits              ?     6889           
  Misses            ?      227           
  Partials          ?      121
Impacted Files Coverage Δ
aiohttp/client.py 90.81% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57cb76c...0e765a1. Read the comment docs.

@fafhrd91 fafhrd91 force-pushed the payload-refactoring branch from 94a233d to c2df3cc Compare February 20, 2017 23:35
@fafhrd91
Copy link
Member Author

@kxepal I need you to review MultipartWriter related changes specifically

@fafhrd91 fafhrd91 force-pushed the payload-refactoring branch from 2c01b0e to 0e765a1 Compare February 21, 2017 06:46
Copy link
Member

@kxepal kxepal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fafhrd91 Wonderful work!

"""Write last chunk"""

@asyncio.coroutine # pragma: no branch
@asyncio.coroutine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Twice coroutite?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"""Write chunk into stream"""

@asyncio.coroutine # pragma: no branch
@abstractmethod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can exclude abstract methods from coverage:

[report]
exclude_lines =
    @abc.abstractmethod
    @abstractmethod

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

self.chunked = True
# FormData
if isinstance(body, FormData):
body = body(self.encoding)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to handle there any callable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? I dont understand

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that what if body could be an arbitrary callable object? FormData uses that interface to be processed. We can reuse that way for everything else. Though not sure if this would be helpful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add this later, right now I do not see value in this. Developer should be able to prepare spendable data before calling client. Case with custom data generation from coroutine already covered with streamer decorator

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Thanks!

try:
body = payload.PAYLOAD_REGISTRY.get(body)
except payload.LookupError:
body = FormData(body)(self.encoding)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to send data as is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body could be dict or list or whatever. I am fine with changing FormData api

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was though to just throw an "encode me" error in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first i try to convert body into Payload, then if it fails I try to use FormData
when you do FormData(body)(self.encoding) it returns bytes for url encoded or
MultipartWriter (which is Payload) or fails

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should be more clear. I mean that just try to send data as is without implicit transformations and fail if that's not possible (dict, list, custom object that didn't implement required interface). Implicit transformation may play a bad joke.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to be explicit, it may be not clear if it fails on actual write

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

return self.append(obj, headers)

*_, params = parse_mimetype(headers.get(CONTENT_TYPE))
charset = params.get('charset', 'utf-8')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit redundant and may confuse. Because you can throw here any content-type, but in the end it will be application/json without any charset and else params.

Better have explicit charset function argument or drop this idea. We're in 2017 anyway and Python`s json escapes all non ascii chars, so it doesn't really matter which encoding will be applied.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care much about this, we can remove it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

self._encoding = encoding
self._filename = filename
if headers is not None:
self._headers = CIMultiDict(headers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't here be a multidict proxy? Because, technically, I can update Payload.headers content type and it will cause a conflict with the content type property.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, maybe. this api is not settled yet.

@kxepal
Copy link
Member

kxepal commented Feb 21, 2017

I'll take a second look at the evening if it wouldn't be too late (:
Massive changes, but I like the way it goes.

@fafhrd91 fafhrd91 closed this Feb 21, 2017
@fafhrd91 fafhrd91 deleted the payload-refactoring branch February 21, 2017 08:13
@fafhrd91
Copy link
Member Author

accidentally removed branch, now GitHub does not allow reopen PR.

@kxepal let's continue here, in any case I am mostly done with refactoring.

@fafhrd91
Copy link
Member Author

fafhrd91 commented Feb 21, 2017

@asvetlov comments?

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants