From 78d557bf024db83f41c9650c58700efd24172821 Mon Sep 17 00:00:00 2001
From: Gary Wilson Jr <gary.wilson@gmail.com>
Date: Sun, 14 Oct 2007 04:17:02 +0000
Subject: [PATCH] =?UTF-8?q?Fixed=20#5744=20--=20Allowed=20SortedDict=20con?=
 =?UTF-8?q?tructor=20to=20be=20passed=20a=20list=20of=20tuples=20to=20matc?=
 =?UTF-8?q?h=20the=20interface=20of=20dict,=20thanks=20Thomas=20G=C3=BCttl?=
 =?UTF-8?q?er.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6506 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 django/utils/datastructures.py                | 5 ++++-
 tests/regressiontests/datastructures/tests.py | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 2f3c9bb568..d750f098f0 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -54,7 +54,10 @@ class SortedDict(dict):
     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)
diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py
index 3920e1ca40..b58ee79693 100644
--- a/tests/regressiontests/datastructures/tests.py
+++ b/tests/regressiontests/datastructures/tests.py
@@ -55,6 +55,14 @@ True
 >>> 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']})