Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #3964 -- Added a custom SortedDict.__repr__ so that the keys ar…

…e printed

in sorted order. Based on a patch from Forest Bond.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5069 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit aca569804e661725ed38d2bc0a2ccfd165e4bad0 1 parent 535535a
@malcolmt malcolmt authored
View
7 django/utils/datastructures.py
@@ -99,6 +99,13 @@ def copy(self):
obj.keyOrder = self.keyOrder
return obj
+ def __repr__(self):
+ """
+ Replaces the normal dict.__repr__ with a version that returns the keys
+ in their sorted order.
+ """
+ return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()])
+
class MultiValueDictKeyError(KeyError):
pass
View
2  tests/regressiontests/datastructures/tests.py
@@ -52,6 +52,8 @@
'not one'
>>> d.keys() == d.copy().keys()
True
+>>> print repr(d)
+{'one': 'not one', 'two': 'two', 'three': 'three'}
### DotExpandedDict ############################################################

0 comments on commit aca5698

Please sign in to comment.
Something went wrong with that request. Please try again.