Merge branch 'redsea' 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 9ba93b8, 6c359b2 · Browse files · 3 files·+21 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+21 added−28 removed
- other:+21 added−28 removed
Provenance
- Commit
8e6f98f- Tree
26296a3- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
9ba93b8- Parent 2
6c359b2
3 files changed+21 added−28 removed
modified:requests/defaults.py+1 added-5 removed
8 unmodified lines9 Configurations:10 11 :base_headers: Default HTTP headers.12 :verbose: Stream to write request logging to.13-:timeout: Seconds until request timeout.14-:max_redirects: Maximum number of redirects allowed within a request.13+:max_redirects: Maximum number of redirects allowed within a request.s15-:decode_unicode: Decode unicode responses automatically?14 :keep_alive: Reuse HTTP Connections?15 :max_retries: The number of times a request should be retried in the event of a connection failure.16 :danger_mode: If true, Requests will raise errors immediately.17 :safe_mode: If true, Requests will catch all errors.18 :pool_maxsize: The maximium size of an HTTP connection pool.19 :pool_connections: The number of active HTTP connection pools to use.22-20 """21 22 from . import __version__23 7 unmodified lines31 }32 33 defaults['verbose'] = None34 defaults['max_redirects'] = 3038-defaults['decode_unicode'] = True35 defaults['pool_connections'] = 1036 defaults['pool_maxsize'] = 1037 defaults['max_retries'] = 038 defaults['danger_mode'] = False2 unmodified linesmodified:requests/models.py+17 added-23 removed
150 unmodified lines151 def __repr__(self):152 return '<Request [%s]>' % (self.method)153 154 155- def _build_response(self, resp, is_error=False):155+ def _build_response(self, resp):156 """Build internal :class:`Response <Response>` object157 from given response.158 """159 30 unmodified lines190 response.error = getattr(resp, 'error', None)191 192 # Save original response for later.193 response.raw = resp194-195- if is_error:196- response.error = resp197-194 response.url = self.full_url.decode('utf-8')195 196 return response197 408 unmodified lines606 return False607 return True608 609 614- def iter_content(self, chunk_size=10 * 1024, decode_unicode=None):610+ def iter_content(self, chunk_size=10 * 1024, decode_unicode=False):611 """Iterates over the response data. This avoids reading the content612 at once into memory for large responses. The chunk size is the number613 of bytes it should read into memory. This is not necessarily the614 length of each item returned as decoding can take place.45 unmodified lines660 gen = stream_decompress(gen, mode='gzip')661 elif 'deflate' in self.headers.get('content-encoding', ''):662 gen = stream_decompress(gen, mode='deflate')663 668- if decode_unicode is None:669- decode_unicode = self.config.get('decode_unicode')670-664 if decode_unicode:665 gen = stream_decode_response_unicode(gen, self)666 667 return gen29 unmodified lines697 698 699 @property700 def content(self):708- """Content of the response, in bytes or unicode709- (if available).710- """701+ """Content of the response, in bytes."""702 703 if self._content is None:704 # Read the contents.705 try:4 unmodified lines710 self._content = self.raw.read()711 except AttributeError:712 self._content = None713 714+ self._content_consumed = True723- content = self._content715+ return self._content716 725- # Decode unicode content.726- if self.config.get('decode_unicode'):717 728- # Try charset from content-type718+ @property719+ def text(self):720+ """Content of the response, in unicode."""721 730- if self.encoding:731- try:732- content = unicode(content, self.encoding)733- except UnicodeError:734- pass722+ # Try charset from content-type723+ content = u''724 736- # Fall back:725+ if self.encoding:726 try:727+ content = unicode(self.content, self.encoding)728+ except UnicodeError:729+ pass730+731+ # Try to fall back:732+ try:733 content = unicode(content, self.encoding, errors='replace')734 except TypeError:735 pass736 742- self._content_consumed = True737 return content738 739 740 def raise_for_status(self):15 unmodified linesmodified:requests/utils.py+3 added
274 unmodified lines275 276 if 'charset' in params:277 return params['charset'].strip("'\"")278 279+ if 'text' in content_type:280+ return 'ISO-8859-1'281 282+283 def unicode_from_html(content):284 """Attempts to decode an HTML string into unicode.285 If unsuccessful, the original content is returned.286 """115 unmodified lines