Author: lukeplant
Date: 2011-07-08 05:07:54 -0700 (Fri, 08 Jul 2011)
New Revision: 16526

Modified:
   django/trunk/django/http/__init__.py
   django/trunk/tests/regressiontests/httpwrappers/tests.py
Log:
Fixed bug with our SimpleCookie regarding load/custom Morsel, and simplified 
implementation

Modified: django/trunk/django/http/__init__.py
===================================================================
--- django/trunk/django/http/__init__.py        2011-07-08 09:39:56 UTC (rev 
16525)
+++ django/trunk/django/http/__init__.py        2011-07-08 12:07:54 UTC (rev 
16526)
@@ -54,18 +54,10 @@
                 if "httponly" in self:
                     output += "; httponly"
                 return output
+    else:
+        Morsel = Cookie.Morsel
 
     class SimpleCookie(Cookie.SimpleCookie):
-        if not _morsel_supports_httponly:
-            def __set(self, key, real_value, coded_value):
-                M = self.get(key, Morsel())
-                M.set(key, real_value, coded_value)
-                dict.__setitem__(self, key, M)
-
-            def __setitem__(self, key, value):
-                rval, cval = self.value_encode(value)
-                self.__set(key, rval, cval)
-
         if not _cookie_encodes_correctly:
             def value_encode(self, val):
                 # Some browsers do not support quoted-string from RFC 2109,
@@ -91,19 +83,20 @@
 
                 return val, encoded
 
-        if not _cookie_allows_colon_in_names:
+        if not _cookie_allows_colon_in_names or not _morsel_supports_httponly:
             def load(self, rawdata):
                 self.bad_cookies = set()
                 super(SimpleCookie, self).load(rawdata)
                 for key in self.bad_cookies:
                     del self[key]
 
-            _strict_set = Cookie.BaseCookie._BaseCookie__set
-
             # override private __set() method:
+            # (needed for using our Morsel, and for laxness with CookieError
             def _BaseCookie__set(self, key, real_value, coded_value):
                 try:
-                    self._strict_set(key, real_value, coded_value)
+                    M = self.get(key, Morsel())
+                    M.set(key, real_value, coded_value)
+                    dict.__setitem__(self, key, M)
                 except Cookie.CookieError:
                     self.bad_cookies.add(key)
                     dict.__setitem__(self, key, Cookie.Morsel())

Modified: django/trunk/tests/regressiontests/httpwrappers/tests.py
===================================================================
--- django/trunk/tests/regressiontests/httpwrappers/tests.py    2011-07-08 
09:39:56 UTC (rev 16525)
+++ django/trunk/tests/regressiontests/httpwrappers/tests.py    2011-07-08 
12:07:54 UTC (rev 16526)
@@ -291,3 +291,13 @@
         Test that a repeated non-standard name doesn't affect all cookies. 
Ticket #15852
         """
         self.assertTrue('good_cookie' in parse_cookie('a,=b; a,=c; 
good_cookie=yes').keys())
+
+    def test_httponly_after_load(self):
+        """
+        Test that we can use httponly attribute on cookies that we load
+        """
+        c = SimpleCookie()
+        c.load("name=val")
+        c['name']['httponly'] = True
+        self.assertTrue(c['name']['httponly'])
+

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to