Merge remote-tracking branch 'origin/develop' into develop
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 62d2ea8, ed15c70 · Browse files · 1 file·+21 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+21 added−31 removed
- other:+21 added−31 removed
Provenance
- Commit
996f99b- Tree
1847358- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
62d2ea8- Parent 2
ed15c70
1 file changed+21 added−31 removed
modified:requests/models.py+21 added-31 removed
108 unmodified lines109 110 # If no proxies are given, allow configuration by environment variables111 # HTTP_PROXY and HTTPS_PROXY.112 if not self.proxies and self.config.get('trust_env'):113- if 'HTTP_PROXY' in os.environ:114- self.proxies['http'] = os.environ['HTTP_PROXY']115- if 'HTTPS_PROXY' in os.environ:116- self.proxies['https'] = os.environ['HTTPS_PROXY']113+ if 'HTTP_PROXY' in os.environ:114+ self.proxies['http'] = os.environ['HTTP_PROXY']115+ if 'HTTPS_PROXY' in os.environ:116+ self.proxies['https'] = os.environ['HTTPS_PROXY']117 118- self.data, self._enc_data = self._encode_params(data)119- self.params, self._enc_params = self._encode_params(params)120- self.files, self._enc_files = self._encode_files(files)118+ self.data = data119+ self.params = params120+ self.files = files121 122 #: :class:`Response <Response>` instance, containing123 #: content and metadata of HTTP Response, once :attr:`sent <send>`.124 self.response = Response()183 unmodified lines308 309 Will successfully encode parameters when passed as a dict or a list of310 2-tuples. Order is retained if data is a list of 2-tuples but abritrary311 if parameters are supplied as a dict.312-313- If the data supplied contains parameters, encodes each parameter in it,314- and returns a list of tuples containing the encoded parameters, and a315- urlencoded version of that.316-317- Otherwise, assumes the data is already encoded appropriately, and318- returns it twice.312 """313 314 if isinstance(data, bytes):322- return data, data315+ return data316 if isinstance(data, str):324- return data, data317+ return data318 elif hasattr(data, '__iter__'):319 try:320 dict(data)321 except ValueError:5 unmodified lines327 for v in isinstance(vs, list) and vs or [vs]:328 result.append(329 (k.encode('utf-8') if isinstance(k, str) else k,330 v.encode('utf-8') if isinstance(v, str) else v))338- return result, urlencode(result, doseq=True)331+ return urlencode(result, doseq=True)332 else:340- return data, data333+ return data334 342- def _encode_files(self,files):335+ def _encode_files(self, files):336 337 if (not files) or isinstance(self.data, str):345- return None, None338+ return None339 340 try:341 fields = self.data.copy()342 except AttributeError:9 unmodified lines352 fields.update({k: (fn, fp.read())})353 354 (body, content_type) = encode_multipart_formdata(fields)355 363- return files, (body, content_type)356+ return (body, content_type)357 358 @property359 def full_url(self):360 """Build the actual URL to use."""16 unmodified lines377 378 if not path:379 path = '/'380 388-381 if is_py2:382 if isinstance(scheme, str):383 scheme = scheme.encode('utf-8')384 if isinstance(netloc, str):8 unmodified lines393 fragment = fragment.encode('utf-8')394 395 url = (urlunparse([scheme, netloc, path, params, query, fragment]))396 397+ enc_params = self._encode_params(self.params)405- if self._enc_params:398+ if enc_params:399 if urlparse(url).query:407- url = '%s&%s' % (url, self._enc_params)400+ url = '%s&%s' % (url, enc_params)401 else:409- url = '%s?%s' % (url, self._enc_params)402+ url = '%s?%s' % (url, enc_params)403 404 if self.config.get('encode_uri', True):405 url = requote_uri(url)406 28 unmodified lines435 """Properly register a hook."""436 437 self.hooks[event].append(hook)438 446- def deregister_hook(self,event,hook):439+ def deregister_hook(self, event, hook):440 """Deregister a previously registered hook.441 Returns True if the hook existed, False if not.442 """443 43 unmodified lines487 self.__dict__.update(r.__dict__)488 489 # Multi-part file uploads.490 if self.files:498- (body, content_type) = self._enc_files491+ (body, content_type) = self._encode_files(self.files)492 else:493 if self.data:494 502- body = self._enc_data495+ body = self._encode_params(self.data)496 if isinstance(self.data, str):497 content_type = None498 else:499 content_type = 'application/x-www-form-urlencoded'1 unmodified line501 # Add content-type if it wasn't explicitly provided.502 if (content_type) and (not 'content-type' in self.headers):503 self.headers['Content-Type'] = content_type504 512-505 _p = urlparse(url)506 proxy = self.proxies.get(_p.scheme)507 508 if proxy:275 unmodified lines784 # Trust that chardet isn't available or something went terribly wrong.785 except Exception:786 pass787 796-788 @property789 def text(self):790 """Content of the response, in unicode.791 38 unmodified lines830 http_error = HTTPError('%s Client Error' % self.status_code)831 http_error.response = self832 raise http_error833 843-834 elif (self.status_code >= 500) and (self.status_code < 600):835 http_error = HTTPError('%s Server Error' % self.status_code)836 http_error.response = self837 raise http_error