From: Shivaram Lingamneni Date: Wed, 2 May 2012 05:25:50 +0000 (-0700) Subject: Cache the value of the `Response.text` property X-Git-Tag: v0.12.0~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d232948188f922c137dd709b53f77c49d1442c84;p=services%2Fpython-requests.git Cache the value of the `Response.text` property --- 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):