From: Kenneth Reitz Date: Fri, 9 Mar 2012 16:35:51 +0000 (-0800) Subject: _detected_encoding X-Git-Tag: v0.10.8~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=253cba373bc393526a15da38aa364ac10631e53c;p=services%2Fpython-requests.git _detected_encoding --- diff --git a/requests/models.py b/requests/models.py index 44038d3..4f05601 100644 --- a/requests/models.py +++ b/requests/models.py @@ -707,7 +707,7 @@ class Response(object): return gen - def iter_lines(self, chunk_size=10 * 1024, decode_unicode=True): + def iter_lines(self, chunk_size=10 * 1024, decode_unicode=None): """Iterates over the response data, one line at a time. This avoids reading the content at once into memory for large responses. @@ -756,6 +756,16 @@ class Response(object): self._content_consumed = True return self._content + def _detected_encoding(self): + try: + detected = chardet.detect(self.content) or {} + return detected.get('encoding') + + # Trust that chardet isn't available or something went terribly wrong. + except Exception: + pass + + @property def text(self): """Content of the response, in unicode. @@ -770,13 +780,7 @@ class Response(object): # Fallback to auto-detected encoding if chardet is available. if self.encoding is None: - try: - detected = chardet.detect(self.content) or {} - encoding = detected.get('encoding') - - # Trust that chardet isn't available or something went terribly wrong. - except Exception: - pass + encoding = self._detected_encoding() # Decode unicode from given encoding. try: