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

Add json parameter #2258

Merged
merged 5 commits into from
Oct 5, 2014
Merged

Add json parameter #2258

merged 5 commits into from
Oct 5, 2014

Conversation

sigmavirus24
Copy link
Contributor

Closes #2025

@sigmavirus24 sigmavirus24 self-assigned this Sep 30, 2014
"""Sends a POST request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
Copy link
Contributor

Choose a reason for hiding this comment

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

This would get passed through with the kwargs, right, so I guess this is just so people know about the parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sigmavirus24 sigmavirus24 changed the title Add json Add json parameter Sep 30, 2014
@@ -397,7 +402,7 @@ def prepare_headers(self, headers):
else:
self.headers = CaseInsensitiveDict()

def prepare_body(self, data, files):
def prepare_body(self, data, files, _json=None):
Copy link
Member

Choose a reason for hiding this comment

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

Why the underscore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working on changing that already. The problem is that the module json is imported at the top and needs to be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by aliasing json_dumps = json.dumps at the top of the module. Not sure I like it, but apparently import semantics are such that requests.compat.json can't be imported from (e.g., you can't do from .compat.json import dumps). Can you think of a better solution to avoid the local variable/parameter from shadowing the top-level module name beyond doing from . import compat and then doing compat.json.dumps?

- Don't _ prefix json in prepare_body
- Don't initialize json to []
- Don't initialize json to {}
- Reorder parameters to PreparedRequest.prepare
- Remove extra parentheses
- Update docstring
@sigmavirus24
Copy link
Contributor Author

@Lukasa @kevinburke care to take another look at this?

@Lukasa
Copy link
Member

Lukasa commented Oct 5, 2014

LGTM

@kennethreitz
Copy link
Contributor

omg I'm so excited

❤️ ✨ 🍰 🌹 🍰 ✨ ❤️

kennethreitz added a commit that referenced this pull request Oct 5, 2014
@kennethreitz kennethreitz merged commit 1e79cf6 into psf:master Oct 5, 2014
@sigmavirus24
Copy link
Contributor Author

@willingc thank you so much for your hard work on this. 🍰 (Those emoji from @kennethreitz are for you ;))

@willingc
Copy link
Contributor

willingc commented Oct 5, 2014

Thank you @sigmavirus24 for your support and mentoring 🎸 🌅 🌲 , @Lukasa for the review 🐱 🐈 😸 , and @kennethreitz for the community atmosphere 📷 ✌️ 🎸

@kennethreitz
Copy link
Contributor

@willingc thank YOU, and you're welcome :)

@@ -209,6 +212,7 @@ def __init__(self,
headers=None,
files=None,
data=None,
json=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I'm late to the party, was out - wouldn't this also change the meaning for anyone who creates a Request by hand, eg

params = {'date_created': '1-1-14'}
req = Request('GET', 'http://jsonip.com', {'User-Agent': 'foobar'}, None, {}, params)

where now suddenly params is JSON data?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON Upload
5 participants