Ticket #12476: diff2.diff

File diff2.diff, 1.3 KB (added by Gabriel Farrell, 15 years ago)

Slimmed down comment, made test more clear

  • django/utils/datastructures.py

    diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
    index 06cf6c6..898d168 100644
    a b  
     1from types import GeneratorType
     2
    13from django.utils.copycompat import deepcopy
    24
    35
    class SortedDict(dict):  
    6567    def __init__(self, data=None):
    6668        if data is None:
    6769            data = {}
     70        elif isinstance(data, GeneratorType):
     71            data = list(data)  # Convert to list to read data twice. 
    6872        super(SortedDict, self).__init__(data)
    6973        if isinstance(data, dict):
    7074            self.keyOrder = data.keys()
  • tests/regressiontests/datastructures/tests.py

    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  
    119119>>> d.keyOrder
    120120[]
    121121
     122Init from generator
     123>>> d = SortedDict((i, i) for i in xrange(3))
     124>>> print repr(d)
     125{0: 0, 1: 1, 2: 2}
     126
    122127### DotExpandedDict ##########################################################
    123128
    124129>>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': ['Holovaty']})
Back to Top