diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 06cf6c6..adcc354 100644
a
|
b
|
|
| 1 | from types import GeneratorType |
| 2 | |
1 | 3 | from django.utils.copycompat import deepcopy |
2 | 4 | |
3 | 5 | |
… |
… |
class SortedDict(dict):
|
65 | 67 | def __init__(self, data=None): |
66 | 68 | if data is None: |
67 | 69 | data = {} |
| 70 | elif isinstance(data, GeneratorType): |
| 71 | # Unfortunately we need to be able to read a generator twice. Once |
| 72 | # to get the data into self with our super().__init__ call and a |
| 73 | # second time to setup keyOrder correctly |
| 74 | data = list(data) |
68 | 75 | super(SortedDict, self).__init__(data) |
69 | 76 | if isinstance(data, dict): |
70 | 77 | self.keyOrder = data.keys() |
diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py
index e658f33..148c7e4 100644
a
|
b
|
True
|
95 | 95 | >>> d.pop('one', 'missing') |
96 | 96 | 'missing' |
97 | 97 | |
| 98 | >>> SortedDict((i, i) for i in xrange(3)) |
| 99 | {0: 0, 1: 1, 2: 2} |
| 100 | |
98 | 101 | We don't know which item will be popped in popitem(), so we'll just check that |
99 | 102 | the number of keys has decreased. |
100 | 103 | >>> l = len(d) |