Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed our SimpleCookie overriding and use to be compatible with a (po…

…tential) 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
  • Loading branch information...
commit 89e0e8b6bc861bb95e55bd5e255e756fe3be1cf2 1 parent b8f0346
@spookylukey spookylukey authored
Showing with 12 additions and 12 deletions.
  1. +12 −12 django/http/__init__.py
View
24 django/http/__init__.py
@@ -28,8 +28,11 @@
_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 @@ def value_encode(self, val):
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 {}
Please sign in to comment.
Something went wrong with that request. Please try again.