Skip to content

Commit

Permalink
Fixed #3678 -- Implemented SortedDict.copy().
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4688 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Mar 9, 2007
1 parent fcd119b commit 22178d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions django/utils/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/regressiontests/datastructures/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
>>> d['one'] = 'not one'
>>> d['one']
'not one'
>>> d.keys() == d.copy().keys()
True
### DotExpandedDict ############################################################
Expand Down

0 comments on commit 22178d6

Please sign in to comment.