Ticket #3508: doc_MergeDict.diff

File doc_MergeDict.diff, 1.0 KB (added by thebanana, 18 years ago)

patch to add str and repr to MergeDict

  • django/utils/datastructures.py

    === django/utils/datastructures.py
    ==================================================================
     
    4343                return True
    4444        return False
    4545
     46    def __str__(self):
     47        '''
     48        Returns something like
     49
     50            "{'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}"
     51
     52        instead of the generic "<object meta-data>" inherited from object.
     53        '''
     54        return str(dict(self.items()))
     55
     56    def __repr__(self):
     57        '''
     58        Returns something like
     59
     60            MergeDict({'key1': 'val1', 'key2': 'val2'}, {'key3': 'val3'})
     61
     62        instead of generic "<object meta-data>" inherited from object.
     63        '''
     64        dictreprs = ', '.join(repr(d) for d in self.dicts)
     65        return '%s(%s)' % (self.__class__.__name__, dictreprs)
     66
    4667class SortedDict(dict):
    4768    "A dictionary that keeps its keys in the order in which they're inserted."
    4869    def __init__(self, data=None):
Back to Top