Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #5744 -- Allowed SortedDict contructor to be passed a list of t…

…uples to match the interface of dict, thanks Thomas Güttler.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6506 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 78d557bf024db83f41c9650c58700efd24172821 1 parent a3d015f
@gdub gdub authored
View
5 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)
View
8 tests/regressiontests/datastructures/tests.py
@@ -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']})
Please sign in to comment.
Something went wrong with that request. Please try again.