Author: gwilson
Date: 2007-10-13 23:17:02 -0500 (Sat, 13 Oct 2007)
New Revision: 6506

Modified:
   django/trunk/django/utils/datastructures.py
   django/trunk/tests/regressiontests/datastructures/tests.py
Log:
Fixed #5744 -- Allowed SortedDict contructor to be passed a list of tuples to 
match the interface of dict, thanks Thomas G?\195?\188ttler.


Modified: django/trunk/django/utils/datastructures.py
===================================================================
--- django/trunk/django/utils/datastructures.py 2007-10-14 04:10:02 UTC (rev 
6505)
+++ django/trunk/django/utils/datastructures.py 2007-10-14 04:17:02 UTC (rev 
6506)
@@ -54,7 +54,10 @@
     def __init__(self, data=None):
         if data is None: data = {}
         dict.__init__(self, data)
-        self.keyOrder = data.keys()
+        if isinstance(data, dict):
+            self.keyOrder = data.keys()
+        else:
+            self.keyOrder=[key for key, value in data]
 
     def __setitem__(self, key, value):
         dict.__setitem__(self, key, value)

Modified: django/trunk/tests/regressiontests/datastructures/tests.py
===================================================================
--- django/trunk/tests/regressiontests/datastructures/tests.py  2007-10-14 
04:10:02 UTC (rev 6505)
+++ django/trunk/tests/regressiontests/datastructures/tests.py  2007-10-14 
04:17:02 UTC (rev 6506)
@@ -55,6 +55,14 @@
 >>> print repr(d)
 {'one': 'not one', 'two': 'two', 'three': 'three'}
 
+Init from sequence of tuples
+>>> d = SortedDict((
+... (1, "one"),
+... (0, "zero"),
+... (2, "two")))
+>>> print repr(d)
+{1: 'one', 0: 'zero', 2: 'two'}
+
 ### DotExpandedDict 
############################################################
 
 >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': 
 >>> ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': 
 >>> ['Holovaty']})


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to