Merge pull request #2105 from funkybob/cleanup_get_post
Used @cached_property for request.GET and COOKIES
This commit is contained in:
commit
08bb238eae
|
@ -14,6 +14,7 @@ from django.core.handlers import base
|
||||||
from django.core.urlresolvers import set_script_prefix
|
from django.core.urlresolvers import set_script_prefix
|
||||||
from django.utils import datastructures
|
from django.utils import datastructures
|
||||||
from django.utils.encoding import force_str, force_text
|
from django.utils.encoding import force_str, force_text
|
||||||
|
from django.utils.functional import cached_property
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
# For backwards compatibility -- lots of code uses this in the wild!
|
# 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)
|
self._request = datastructures.MergeDict(self.POST, self.GET)
|
||||||
return self._request
|
return self._request
|
||||||
|
|
||||||
def _get_get(self):
|
@cached_property
|
||||||
if not hasattr(self, '_get'):
|
def GET(self):
|
||||||
# The WSGI spec says 'QUERY_STRING' may be absent.
|
# The WSGI spec says 'QUERY_STRING' may be absent.
|
||||||
raw_query_string = get_bytes_from_wsgi(self.environ, 'QUERY_STRING', '')
|
raw_query_string = get_bytes_from_wsgi(self.environ, 'QUERY_STRING', '')
|
||||||
self._get = http.QueryDict(raw_query_string, encoding=self._encoding)
|
return http.QueryDict(raw_query_string, encoding=self._encoding)
|
||||||
return self._get
|
|
||||||
|
|
||||||
def _set_get(self, get):
|
|
||||||
self._get = get
|
|
||||||
|
|
||||||
def _get_post(self):
|
def _get_post(self):
|
||||||
if not hasattr(self, '_post'):
|
if not hasattr(self, '_post'):
|
||||||
|
@ -154,23 +151,17 @@ class WSGIRequest(http.HttpRequest):
|
||||||
def _set_post(self, post):
|
def _set_post(self, post):
|
||||||
self._post = post
|
self._post = post
|
||||||
|
|
||||||
def _get_cookies(self):
|
@cached_property
|
||||||
if not hasattr(self, '_cookies'):
|
def COOKIES(self):
|
||||||
raw_cookie = get_str_from_wsgi(self.environ, 'HTTP_COOKIE', '')
|
raw_cookie = get_str_from_wsgi(self.environ, 'HTTP_COOKIE', '')
|
||||||
self._cookies = http.parse_cookie(raw_cookie)
|
return http.parse_cookie(raw_cookie)
|
||||||
return self._cookies
|
|
||||||
|
|
||||||
def _set_cookies(self, cookies):
|
|
||||||
self._cookies = cookies
|
|
||||||
|
|
||||||
def _get_files(self):
|
def _get_files(self):
|
||||||
if not hasattr(self, '_files'):
|
if not hasattr(self, '_files'):
|
||||||
self._load_post_and_files()
|
self._load_post_and_files()
|
||||||
return self._files
|
return self._files
|
||||||
|
|
||||||
GET = property(_get_get, _set_get)
|
|
||||||
POST = property(_get_post, _set_post)
|
POST = property(_get_post, _set_post)
|
||||||
COOKIES = property(_get_cookies, _set_cookies)
|
|
||||||
FILES = property(_get_files)
|
FILES = property(_get_files)
|
||||||
REQUEST = property(_get_request)
|
REQUEST = property(_get_request)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue