Skip to content
Myr

Cache the value of the `Response.text` property

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Shivaram Lingamneni · committed by Shivaram Lingamneni · parent 35d5ac6 · Browse files · 1 file+7 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−1 removed

  • other:+7 added−1 removed

1 file+7 added−1 removed

modified:requests/models.py+7 added-1 removed
651 unmodified lines
652 """653654 def __init__(self):655656 # bytes of the page:657 self._content = False658 self._content_consumed = False659 # unicode of the page:660 self._text = None661662 #: Integer Code of responded HTTP Status.663 self.status_code = None664
130 unmodified lines
795 # Trust that chardet isn't available or something went terribly wrong.796 except Exception:797 return 'utf-8'798796799 @property800 def text(self):801 """Content of the response, in unicode.802803 if Response.encoding is None and chardet module is available, encoding804 will be guessed.805 """806807 if self._text is not None:808 return self._text809810 # Try charset from content-type811 content = None812 encoding = self.encoding813
12 unmodified lines
826 content = str(self.content, errors='replace')827 except (UnicodeError, TypeError):828 pass829830 self._text = content831 return content832833 def raise_for_status(self, allow_redirects=True):834 """Raises stored :class:`HTTPError` or :class:`URLError`, if one occurred."""
19 unmodified lines