Browse files

Fixed #3678 -- Implemented SortedDict.copy().

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4688 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent fcd119b commit 22178d692a651be21fa9347502babe1bd17aabf2 @malcolmt malcolmt committed Mar 9, 2007
Showing with 9 additions and 0 deletions.
  1. +7 −0 django/utils/datastructures.py
  2. +2 −0 tests/regressiontests/datastructures/tests.py
View
7 django/utils/datastructures.py
@@ -92,6 +92,13 @@ def value_for_index(self, index):
"Returns the value of the item at the given zero-based index."
return self[self.keyOrder[index]]
+ def copy(self):
+ "Returns a copy of this object."
+ # This way of initialising the copy means it works for subclasses, too.
+ obj = self.__class__(self)
+ obj.keyOrder = self.keyOrder
+ return obj
+
class MultiValueDictKeyError(KeyError):
pass
View
2 tests/regressiontests/datastructures/tests.py
@@ -50,6 +50,8 @@
>>> d['one'] = 'not one'
>>> d['one']
'not one'
+>>> d.keys() == d.copy().keys()
+True
### DotExpandedDict ############################################################

0 comments on commit 22178d6

Please sign in to comment.