Skip to content
Myr

Fix a couple of issues I noticed

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- 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

authored by Ian Cordasco · committed by Ian Cordasco · parent 0713e09 · Browse files · 2 files+12 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−10 removed

  • other:+12 added−10 removed

2 files+12 added−10 removed

modified:requests/models.py+11 added-9 removed
44 unmodified lines
45DEFAULT_REDIRECT_LIMIT = 3046CONTENT_CHUNK_SIZE = 10 * 102447ITER_CHUNK_SIZE = 5124849json_dumps = json.dumps505152class RequestEncodingMixin(object):53 @property54 def path_url(self):55 """Build the path URL to use."""
134 unmodified lines
190 :param method: HTTP method to use.191 :param url: URL to send.192 :param headers: dictionary of headers to send.193 :param files: dictionary of {filename: fileobject} files to multipart upload.192 :param data: the body to attach the request. If a dictionary is provided, form-encoding will take place.193 :param json: json for the body to attach the request.194 :param data: the body to attach to the request. If a dictionary is provided, form-encoding will take place.195 :param json: json for the body to attach to the request (if data is not specified).196 :param params: dictionary of URL parameters to append to the URL.197 :param auth: Auth handler or (user, pass) tuple.198 :param cookies: dictionary or CookieJar of cookies to attach to this request.199 :param hooks: dictionary of callback hooks, for internal usage.
19 unmodified lines
219 hooks=None):220221 # Default empty dicts for dict params.222 data = [] if data is None else data221 json = [] if json is None else json223 files = [] if files is None else files224 headers = {} if headers is None else headers225 params = {} if params is None else params226 hooks = {} if hooks is None else hooks
67 unmodified lines
294 #: dictionary of callback hooks, for internal usage.295 self.hooks = default_hooks()296297 def prepare(self, method=None, url=None, headers=None, files=None,297 data=None, json=None, params=None, auth=None, cookies=None, hooks=None):298 data=None, params=None, auth=None, cookies=None, hooks=None,299 json=None):300 """Prepares the entire request with the given parameters."""301302 self.prepare_method(method)303 self.prepare_url(url, params)
99 unmodified lines
403 self.headers = CaseInsensitiveDict((to_native_string(name), value) for name, value in headers.items())404 else:405 self.headers = CaseInsensitiveDict()406405 def prepare_body(self, data, files, _json=None):407 def prepare_body(self, data, files, json=None):408 """Prepares the given HTTP body data."""409410 # Check if file, fo, generator, iterator.411 # If not, run through normal process.
2 unmodified lines
414 body = None415 content_type = None416 length = None417416 if _json is not None:418 if json is not None:419 content_type = 'application/json'418 data = json.dumps(_json)420 body = json_dumps(json)421422 is_stream = all([423 hasattr(data, '__iter__'),424 not isinstance(data, (basestring, list, tuple, dict))
18 unmodified lines
443 # Multi-part file uploads.444 if files:445 (body, content_type) = self._encode_files(files, data)446 else:445 if data and _json is None:447 if data and json is None:448 body = self._encode_params(data)449 if isinstance(data, basestring) or hasattr(data, 'read'):450 content_type = None451 else:
1 unmodified line
453454 self.prepare_content_length(body)455456 # Add content-type if it wasn't explicitly provided.455 if (content_type) and (not 'content-type' in self.headers):457 if content_type and ('content-type' not in self.headers):458 self.headers['Content-Type'] = content_type459460 self.body = body461
366 unmodified lines
modified:requests/sessions.py+1 added-1 removed
428 unmodified lines
429 url = url,430 headers = headers,431 files = files,432 data = data or {},433 json = json or {},433 json = json,434 params = params or {},435 auth = auth,436 cookies = cookies,437 hooks = hooks,
225 unmodified lines