Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Fixed #1539: Fixed multithreading problem in QueryDict…

…. Thanks, Eugene and Alex Brown

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2577 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 15b5f4ded23217983d937442ebe0ec197d09846f 1 parent ff3810c
Adrian Holovaty authored March 28, 2006
29  django/http/__init__.py
@@ -69,21 +69,34 @@ def parse_file_upload(header_dict, post_data):
69 69
 class QueryDict(MultiValueDict):
70 70
     """A specialized MultiValueDict that takes a query string when initialized.
71 71
     This is immutable unless you create a copy of it."""
72  
-    def __init__(self, query_string):
  72
+    def __init__(self, query_string, mutable=False):
73 73
         MultiValueDict.__init__(self)
74 74
         self._mutable = True
75 75
         for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True
76 76
             self.appendlist(key, value)
77  
-        self._mutable = False
  77
+        self._mutable = mutable
78 78
 
79 79
     def _assert_mutable(self):
80 80
         if not self._mutable:
81 81
             raise AttributeError, "This QueryDict instance is immutable"
82 82
 
83  
-    def _setitem_if_mutable(self, key, value):
  83
+    def __setitem__(self, key, value):
84 84
         self._assert_mutable()
85 85
         MultiValueDict.__setitem__(self, key, value)
86  
-    __setitem__ = _setitem_if_mutable
  86
+
  87
+    def __copy__(self):
  88
+        result = self.__class__('', mutable=True)
  89
+        for key, value in dict.items(self):
  90
+            dict.__setitem__(result, key, value)
  91
+        return result
  92
+
  93
+    def __deepcopy__(self, memo={}):
  94
+        import copy
  95
+        result = self.__class__('', mutable=True)
  96
+        memo[id(self)] = result
  97
+        for key, value in dict.items(self):
  98
+            dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
  99
+        return result
87 100
 
88 101
     def setlist(self, key, list_):
89 102
         self._assert_mutable()
@@ -115,13 +128,7 @@ def setdefault(self, *args):
115 128
 
116 129
     def copy(self):
117 130
         "Returns a mutable copy of this object."
118  
-        import copy
119  
-        # Our custom __setitem__ must be disabled for copying machinery.
120  
-        QueryDict.__setitem__ = dict.__setitem__
121  
-        cp = copy.deepcopy(self)
122  
-        QueryDict.__setitem__ = QueryDict._setitem_if_mutable
123  
-        cp._mutable = True
124  
-        return cp
  131
+        return self.__deepcopy__()
125 132
 
126 133
     def urlencode(self):
127 134
         output = []
21  django/utils/datastructures.py
@@ -117,9 +117,19 @@ def __getitem__(self, key):
117 117
         except IndexError:
118 118
             return []
119 119
 
120  
-    def _setitem_list(self, key, value):
  120
+    def __setitem__(self, key, value):
121 121
         dict.__setitem__(self, key, [value])
122  
-    __setitem__ = _setitem_list
  122
+
  123
+    def __copy__(self):
  124
+        return self.__class__(dict.items(self))
  125
+
  126
+    def __deepcopy__(self, memo={}):
  127
+        import copy
  128
+        result = self.__class__()
  129
+        memo[id(self)] = result
  130
+        for key, value in dict.items(self):
  131
+            dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
  132
+        return result
123 133
 
124 134
     def get(self, key, default=None):
125 135
         "Returns the default value if the requested data doesn't exist"
@@ -173,12 +183,7 @@ def values(self):
173 183
 
174 184
     def copy(self):
175 185
         "Returns a copy of this object."
176  
-        import copy
177  
-        # Our custom __setitem__ must be disabled for copying machinery.
178  
-        MultiValueDict.__setitem__ = dict.__setitem__
179  
-        cp = copy.deepcopy(self)
180  
-        MultiValueDict.__setitem__ = MultiValueDict._setitem_list
181  
-        return cp
  186
+        return self.__deepcopy__()
182 187
 
183 188
     def update(self, other_dict):
184 189
         "update() extends rather than replaces existing key lists."

0 notes on commit 15b5f4d

Please sign in to comment.
Something went wrong with that request. Please try again.