Use cached_property for request.GET and request.COOKIES

This commit is contained in:
Curtis 2013-12-24 21:57:57 +11:00
parent e9e522a8e7
commit d7a4b156d9
1 changed files with 10 additions and 19 deletions

View File

@ -14,6 +14,7 @@ from django.core.handlers import base
from django.core.urlresolvers import set_script_prefix
from django.utils import datastructures
from django.utils.encoding import force_str, force_text
from django.utils.functional import cached_property
from django.utils import six
# For backwards compatibility -- lots of code uses this in the wild!
@ -136,15 +137,11 @@ class WSGIRequest(http.HttpRequest):
self._request = datastructures.MergeDict(self.POST, self.GET)
return self._request
def _get_get(self):
if not hasattr(self, '_get'):
@cached_property
def GET(self):
# The WSGI spec says 'QUERY_STRING' may be absent.
raw_query_string = get_bytes_from_wsgi(self.environ, 'QUERY_STRING', '')
self._get = http.QueryDict(raw_query_string, encoding=self._encoding)
return self._get
def _set_get(self, get):
self._get = get
return http.QueryDict(raw_query_string, encoding=self._encoding)
def _get_post(self):
if not hasattr(self, '_post'):
@ -154,23 +151,17 @@ class WSGIRequest(http.HttpRequest):
def _set_post(self, post):
self._post = post
def _get_cookies(self):
if not hasattr(self, '_cookies'):
@cached_property
def COOKIES(self):
raw_cookie = get_str_from_wsgi(self.environ, 'HTTP_COOKIE', '')
self._cookies = http.parse_cookie(raw_cookie)
return self._cookies
def _set_cookies(self, cookies):
self._cookies = cookies
return http.parse_cookie(raw_cookie)
def _get_files(self):
if not hasattr(self, '_files'):
self._load_post_and_files()
return self._files
GET = property(_get_get, _set_get)
POST = property(_get_post, _set_post)
COOKIES = property(_get_cookies, _set_cookies)
FILES = property(_get_files)
REQUEST = property(_get_request)