From 22178d692a651be21fa9347502babe1bd17aabf2 Mon Sep 17 00:00:00 2001
From: Malcolm Tredinnick <malcolm.tredinnick@gmail.com>
Date: Fri, 9 Mar 2007 05:34:42 +0000
Subject: [PATCH] Fixed #3678 -- Implemented SortedDict.copy().

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4688 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 django/utils/datastructures.py                | 7 +++++++
 tests/regressiontests/datastructures/tests.py | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 94ab76c483..e924e4edbc 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -92,6 +92,13 @@ class SortedDict(dict):
         "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
 
diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py
index 90fb2d56a2..e008c255f1 100644
--- a/tests/regressiontests/datastructures/tests.py
+++ b/tests/regressiontests/datastructures/tests.py
@@ -50,6 +50,8 @@
 >>> d['one'] = 'not one'
 >>> d['one']
 'not one'
+>>> d.keys() == d.copy().keys()
+True
 
 ### DotExpandedDict ############################################################