From d232948188f922c137dd709b53f77c49d1442c84 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Tue, 1 May 2012 22:25:50 -0700 Subject: [PATCH] Cache the value of the `Response.text` property --- requests/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index ac2811e..ebf8256 100644 --- a/requests/models.py +++ b/requests/models.py @@ -653,8 +653,11 @@ class Response(object): def __init__(self): + # bytes of the page: self._content = False self._content_consumed = False + # unicode of the page: + self._text = None #: Integer Code of responded HTTP Status. self.status_code = None @@ -793,7 +796,6 @@ class Response(object): except Exception: return 'utf-8' - @property def text(self): """Content of the response, in unicode. @@ -802,6 +804,9 @@ class Response(object): will be guessed. """ + if self._text is not None: + return self._text + # Try charset from content-type content = None encoding = self.encoding @@ -822,6 +827,7 @@ class Response(object): except (UnicodeError, TypeError): pass + self._text = content return content def raise_for_status(self, allow_redirects=True): -- 2.7.4