summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2014-09-30 16:03:31 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2014-09-30 16:03:31 -0500
commit8ed941fa6991355753e698f6b253096d57f6c7e4 (patch)
treebcc22df1e2fffd419d83e4caf22f42f5c7855ea2
parent0713e09526d3ed2d2fe2516fa6d35727c557024f (diff)
downloadpython-requests-8ed941fa6991355753e698f6b253096d57f6c7e4.tar.gz
Fix a couple of issues I noticed
- 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
-rw-r--r--requests/models.py20
-rw-r--r--requests/sessions.py2
2 files changed, 12 insertions, 10 deletions
diff --git a/requests/models.py b/requests/models.py
index a96fc4e6..c1f7f561 100644
--- a/requests/models.py
+++ b/requests/models.py
@@ -46,6 +46,8 @@ DEFAULT_REDIRECT_LIMIT = 30
CONTENT_CHUNK_SIZE = 10 * 1024
ITER_CHUNK_SIZE = 512
+json_dumps = json.dumps
+
class RequestEncodingMixin(object):
@property
@@ -189,8 +191,8 @@ class Request(RequestHooksMixin):
:param url: URL to send.
:param headers: dictionary of headers to send.
:param files: dictionary of {filename: fileobject} files to multipart upload.
- :param data: the body to attach the request. If a dictionary is provided, form-encoding will take place.
- :param json: json for the body to attach the request.
+ :param data: the body to attach to the request. If a dictionary is provided, form-encoding will take place.
+ :param json: json for the body to attach to the request (if data is not specified).
:param params: dictionary of URL parameters to append to the URL.
:param auth: Auth handler or (user, pass) tuple.
:param cookies: dictionary or CookieJar of cookies to attach to this request.
@@ -218,7 +220,6 @@ class Request(RequestHooksMixin):
# Default empty dicts for dict params.
data = [] if data is None else data
- json = [] if json is None else json
files = [] if files is None else files
headers = {} if headers is None else headers
params = {} if params is None else params
@@ -294,7 +295,8 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
self.hooks = default_hooks()
def prepare(self, method=None, url=None, headers=None, files=None,
- data=None, json=None, params=None, auth=None, cookies=None, hooks=None):
+ data=None, params=None, auth=None, cookies=None, hooks=None,
+ json=None):
"""Prepares the entire request with the given parameters."""
self.prepare_method(method)
@@ -402,7 +404,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
else:
self.headers = CaseInsensitiveDict()
- def prepare_body(self, data, files, _json=None):
+ def prepare_body(self, data, files, json=None):
"""Prepares the given HTTP body data."""
# Check if file, fo, generator, iterator.
@@ -413,9 +415,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
content_type = None
length = None
- if _json is not None:
+ if json is not None:
content_type = 'application/json'
- data = json.dumps(_json)
+ body = json_dumps(json)
is_stream = all([
hasattr(data, '__iter__'),
@@ -442,7 +444,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
if files:
(body, content_type) = self._encode_files(files, data)
else:
- if data and _json is None:
+ if data and json is None:
body = self._encode_params(data)
if isinstance(data, basestring) or hasattr(data, 'read'):
content_type = None
@@ -452,7 +454,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
self.prepare_content_length(body)
# Add content-type if it wasn't explicitly provided.
- if (content_type) and (not 'content-type' in self.headers):
+ if content_type and ('content-type' not in self.headers):
self.headers['Content-Type'] = content_type
self.body = body
diff --git a/requests/sessions.py b/requests/sessions.py
index 7942447f..c5ad0060 100644
--- a/requests/sessions.py
+++ b/requests/sessions.py
@@ -430,7 +430,7 @@ class Session(SessionRedirectMixin):
headers = headers,
files = files,
data = data or {},
- json = json or {},
+ json = json,
params = params or {},
auth = auth,
cookies = cookies,