-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Payload refactoring #1664
Conversation
some goals
note: this is only about how we send payload |
added for usage check |
@kxepal is this |
Codecov Report
@@ Coverage Diff @@
## master #1664 +/- ##
=========================================
Coverage ? 95.19%
=========================================
Files ? 34
Lines ? 7237
Branches ? 1262
=========================================
Hits ? 6889
Misses ? 227
Partials ? 121
Continue to review full report at Codecov.
|
94a233d
to
c2df3cc
Compare
@kxepal I need you to review MultipartWriter related changes specifically |
812ec16
to
2c01b0e
Compare
2c01b0e
to
0e765a1
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Twice coroutite?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? I dont understand
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I'll take a second look at the evening if it wouldn't be too late (: |
accidentally removed branch, now GitHub does not allow reopen PR. @kxepal let's continue here, in any case I am mostly done with refactoring. |
@asvetlov comments? |
Payload refactoring