diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 06cf6c6..898d168 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 | data = list(data) # Convert to list to read data twice. |
68 | 72 | super(SortedDict, self).__init__(data) |
69 | 73 | if isinstance(data, dict): |
70 | 74 | self.keyOrder = data.keys() |
diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py
index e658f33..98063d5 100644
a
|
b
|
Init from sequence of tuples
|
119 | 119 | >>> d.keyOrder |
120 | 120 | [] |
121 | 121 | |
| 122 | Init from generator |
| 123 | >>> d = SortedDict((i, i) for i in xrange(3)) |
| 124 | >>> print repr(d) |
| 125 | {0: 0, 1: 1, 2: 2} |
| 126 | |
122 | 127 | ### DotExpandedDict ########################################################## |
123 | 128 | |
124 | 129 | >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': ['Holovaty']}) |