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
Provenance
- Commit
8ed941f- Tree
bcc22df- Author
Ian Cordasco <graffatcolmingov@gmail.com>- Committer
Ian Cordasco <graffatcolmingov@gmail.com>- Parent
0713e09
2 files changed+12 added−10 removed
modified:requests/models.py+11 added-9 removed
44 unmodified lines45 DEFAULT_REDIRECT_LIMIT = 3046 CONTENT_CHUNK_SIZE = 10 * 102447 ITER_CHUNK_SIZE = 51248 49+json_dumps = json.dumps50 51+52 class RequestEncodingMixin(object):53 @property54 def path_url(self):55 """Build the path URL to use."""134 unmodified lines190 :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 lines219 hooks=None):220 221 # 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 hooks67 unmodified lines294 #: dictionary of callback hooks, for internal usage.295 self.hooks = default_hooks()296 297 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."""301 302 self.prepare_method(method)303 self.prepare_url(url, params)99 unmodified lines403 self.headers = CaseInsensitiveDict((to_native_string(name), value) for name, value in headers.items())404 else:405 self.headers = CaseInsensitiveDict()406 405- def prepare_body(self, data, files, _json=None):407+ def prepare_body(self, data, files, json=None):408 """Prepares the given HTTP body data."""409 410 # Check if file, fo, generator, iterator.411 # If not, run through normal process.2 unmodified lines414 body = None415 content_type = None416 length = None417 416- 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)421 422 is_stream = all([423 hasattr(data, '__iter__'),424 not isinstance(data, (basestring, list, tuple, dict))18 unmodified lines443 # 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 line453 454 self.prepare_content_length(body)455 456 # 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_type459 460 self.body = body461 366 unmodified linesmodified:requests/sessions.py+1 added-1 removed
428 unmodified lines429 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