Added more readable __str__ and __repr__ methods to MergeDict.
Thanks, john@calixto.net. Fixed #3508. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13721 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
dee7ef802d
commit
255147c97e
1
AUTHORS
1
AUTHORS
|
@ -238,6 +238,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
jcrasta@gmail.com
|
jcrasta@gmail.com
|
||||||
jdetaeye
|
jdetaeye
|
||||||
jhenry <jhenry@theonion.com>
|
jhenry <jhenry@theonion.com>
|
||||||
|
john@calixto.net
|
||||||
Zak Johnson <zakj@nox.cx>
|
Zak Johnson <zakj@nox.cx>
|
||||||
Nis Jørgensen <nis@superlativ.dk>
|
Nis Jørgensen <nis@superlativ.dk>
|
||||||
Michael Josephson <http://www.sdjournal.com/>
|
Michael Josephson <http://www.sdjournal.com/>
|
||||||
|
|
|
@ -77,6 +77,27 @@ class MergeDict(object):
|
||||||
"""Returns a copy of this object."""
|
"""Returns a copy of this object."""
|
||||||
return self.__copy__()
|
return self.__copy__()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
'''
|
||||||
|
Returns something like
|
||||||
|
|
||||||
|
"{'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}"
|
||||||
|
|
||||||
|
instead of the generic "<object meta-data>" inherited from object.
|
||||||
|
'''
|
||||||
|
return str(dict(self.items()))
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
'''
|
||||||
|
Returns something like
|
||||||
|
|
||||||
|
MergeDict({'key1': 'val1', 'key2': 'val2'}, {'key3': 'val3'})
|
||||||
|
|
||||||
|
instead of generic "<object meta-data>" inherited from object.
|
||||||
|
'''
|
||||||
|
dictreprs = ', '.join(repr(d) for d in self.dicts)
|
||||||
|
return '%s(%s)' % (self.__class__.__name__, dictreprs)
|
||||||
|
|
||||||
class SortedDict(dict):
|
class SortedDict(dict):
|
||||||
"""
|
"""
|
||||||
A dictionary that keeps its keys in the order in which they're inserted.
|
A dictionary that keeps its keys in the order in which they're inserted.
|
||||||
|
|
Loading…
Reference in New Issue