Author: Alex
Date: 2010-10-27 15:39:20 -0500 (Wed, 27 Oct 2010)
New Revision: 14366

Modified:
   django/trunk/django/utils/datastructures.py
   django/trunk/tests/regressiontests/utils/datastructures.py
Log:
Fixed MultiValueDict's copy implementation to be consistant with all other 
copies.

Modified: django/trunk/django/utils/datastructures.py
===================================================================
--- django/trunk/django/utils/datastructures.py 2010-10-27 20:08:54 UTC (rev 
14365)
+++ django/trunk/django/utils/datastructures.py 2010-10-27 20:39:20 UTC (rev 
14366)
@@ -1,6 +1,6 @@
 from types import GeneratorType
 
-from django.utils.copycompat import deepcopy
+from django.utils.copycompat import copy, deepcopy
 
 
 class MergeDict(object):
@@ -263,7 +263,10 @@
         super(MultiValueDict, self).__setitem__(key, [value])
 
     def __copy__(self):
-        return self.__class__(super(MultiValueDict, self).items())
+        return self.__class__([
+            (k, v[:])
+            for k, v in self.lists()
+        ])
 
     def __deepcopy__(self, memo=None):
         import django.utils.copycompat as copy
@@ -361,8 +364,8 @@
             yield self[key]
 
     def copy(self):
-        """Returns a copy of this object."""
-        return self.__deepcopy__()
+        """Returns a shallow copy of this object."""
+        return copy(self)
 
     def update(self, *args, **kwargs):
         """
@@ -491,4 +494,3 @@
         if use_func:
             return self.func(value)
         return value
-

Modified: django/trunk/tests/regressiontests/utils/datastructures.py
===================================================================
--- django/trunk/tests/regressiontests/utils/datastructures.py  2010-10-27 
20:08:54 UTC (rev 14365)
+++ django/trunk/tests/regressiontests/utils/datastructures.py  2010-10-27 
20:39:20 UTC (rev 14366)
@@ -4,6 +4,7 @@
 import pickle
 import unittest
 
+from django.utils.copycompat import copy
 from django.utils.datastructures import *
 
 
@@ -211,7 +212,27 @@
         self.assertEquals(list(d.itervalues()),
                           ['Developer', 'Simon', 'Willison'])
 
+    def test_copy(self):
+        for copy_func in [copy, lambda d: d.copy()]:
+            d1 = MultiValueDict({
+                "developers": ["Carl", "Fred"]
+            })
+            self.assertEqual(d1["developers"], "Fred")
+            d2 = copy_func(d1)
+            d2.update({"developers": "Groucho"})
+            self.assertEqual(d2["developers"], "Groucho")
+            self.assertEqual(d1["developers"], "Fred")
 
+            d1 = MultiValueDict({
+                "key": [[]]
+            })
+            self.assertEqual(d1["key"], [])
+            d2 = copy_func(d1)
+            d2["key"].append("Penguin")
+            self.assertEqual(d1["key"], ["Penguin"])
+            self.assertEqual(d2["key"], ["Penguin"])
+
+
 class DotExpandedDictTests(DatastructuresTestCase):
 
     def test_dotexpandeddict(self):

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

Reply via email to