diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2011-06-29 15:12:48 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2011-06-29 15:12:48 +0000 |
| commit | 89e0e8b6bc861bb95e55bd5e255e756fe3be1cf2 (patch) | |
| tree | b746bf6b79ef9fb8b8e1c853996282e19c91af43 /django/http | |
| parent | b8f0346c11c9e02b1ec13db2d470f8e063a8de70 (diff) | |
Fixed our SimpleCookie overriding and use to be compatible with a (potential) stdlib SimpleCookie that fixes http://bugs.python.org/issue2193
The previous code tested the stdlib in a way that would always fail. It then
used an overridden SimpleCookie.load method that wouldn't work for the
stdlib. And it did some completely unnecessary monkey patching.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16485 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/__init__.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py index e667f6a9fc..9704eafb19 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -28,8 +28,11 @@ _morsel_supports_httponly = Cookie.Morsel._reserved.has_key('httponly') _cookie_encodes_correctly = Cookie.SimpleCookie().value_encode(';') == (';', '"\\073"') # See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256 _tc = Cookie.SimpleCookie() -_tc.load('f:oo') -_cookie_allows_colon_in_names = 'Set-Cookie: f:oo=' in _tc.output() +try: + _tc.load('foo:bar=1') + _cookie_allows_colon_in_names = True +except Cookie.CookieError: + _cookie_allows_colon_in_names = False if _morsel_supports_httponly and _cookie_encodes_correctly and _cookie_allows_colon_in_names: SimpleCookie = Cookie.SimpleCookie @@ -89,19 +92,16 @@ else: return val, encoded if not _cookie_allows_colon_in_names: - def load(self, rawdata, ignore_parse_errors=False): - if ignore_parse_errors: - self.bad_cookies = set() - self._BaseCookie__set = self._loose_set + def load(self, rawdata): + self.bad_cookies = set() super(SimpleCookie, self).load(rawdata) - if ignore_parse_errors: - self._BaseCookie__set = self._strict_set - for key in self.bad_cookies: - del self[key] + for key in self.bad_cookies: + del self[key] _strict_set = Cookie.BaseCookie._BaseCookie__set - def _loose_set(self, key, real_value, coded_value): + # override private __set() method: + def _BaseCookie__set(self, key, real_value, coded_value): try: self._strict_set(key, real_value, coded_value) except Cookie.CookieError: @@ -519,7 +519,7 @@ def parse_cookie(cookie): if not isinstance(cookie, Cookie.BaseCookie): try: c = SimpleCookie() - c.load(cookie, ignore_parse_errors=True) + c.load(cookie) except Cookie.CookieError: # Invalid cookie return {} |
