diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-22 00:52:54 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-22 00:52:54 +0000 |
| commit | dbd1cb9083db8a0206a4b951813f4c8291afa824 (patch) | |
| tree | e5d430cd8ff4721810824f2bd7c161c46a2643eb /django/utils/datastructures.py | |
| parent | 375a6d78cb476f865fe5cccbf3277af7afb4d719 (diff) | |
Fixed #5183 -- Added __deepcopy__, pop() and popitem() to SortedDict. Based on
a patch from David Blewett.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6593 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/datastructures.py')
| -rw-r--r-- | django/utils/datastructures.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index dfd3fc69e7..e0835b2cfc 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -62,6 +62,13 @@ class SortedDict(dict): else: self.keyOrder = [key for key, value in data] + def __deepcopy__(self,memo): + from copy import deepcopy + obj = self.__class__() + for k, v in self.items(): + obj[k] = deepcopy(v, memo) + return obj + def __setitem__(self, key, value): dict.__setitem__(self, key, value) if key not in self.keyOrder: @@ -75,6 +82,20 @@ class SortedDict(dict): for k in self.keyOrder: yield k + def pop(self, k, *args): + result = dict.pop(self, k, *args) + try: + self.keyOrder.remove(k) + except ValueError: + # Key wasn't in the dictionary in the first place. No problem. + pass + return result + + def popitem(self): + result = dict.popitem(self) + self.keyOrder.remove(result[0]) + return result + def items(self): return zip(self.keyOrder, self.values()) |
