summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-01-03 06:56:10 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-01-03 06:56:10 +0000
commite8b001f46f7d5dff9268cf5a800a35bb505112bf (patch)
treee5ef8cdecfeb2cf0f3dd4149702e8d23c9d9865d /django/utils
parent618e1b1587c8447b26df0c66a53b80ca1c67aa9e (diff)
[1.1.X] Fixed #12476 -- Forced the rollout of generators passed to SortedDict so that the data source can be read twice. Thanks to gsf for the report, and Alex for the patch.
Backport of r12064 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12065 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/datastructures.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 06cf6c6b75..adcc3546d0 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -1,3 +1,5 @@
+from types import GeneratorType
+
from django.utils.copycompat import deepcopy
@@ -65,6 +67,11 @@ class SortedDict(dict):
def __init__(self, data=None):
if data is None:
data = {}
+ elif isinstance(data, GeneratorType):
+ # Unfortunately we need to be able to read a generator twice. Once
+ # to get the data into self with our super().__init__ call and a
+ # second time to setup keyOrder correctly
+ data = list(data)
super(SortedDict, self).__init__(data)
if isinstance(data, dict):
self.keyOrder = data.keys()