From 253cba373bc393526a15da38aa364ac10631e53c Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 9 Mar 2012 08:35:51 -0800 Subject: [PATCH] _detected_encoding --- requests/models.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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: -- 2.7.4