Code

Ticket #3508: doc_MergeDict_py23.diff

File doc_MergeDict_py23.diff, 1008 bytes (added by thebanana, 7 years ago)

MergeDict patch that works with Python 2.3

Line 
1=== datastructures.py
2==================================================================
3--- datastructures.py   (revision 2131)
4+++ datastructures.py   (revision 2132)
5@@ -43,6 +43,27 @@
6                 return True
7         return False
8 
9+    def __str__(self):
10+        '''
11+        Returns something like
12+
13+            "{'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}"
14+
15+        instead of the generic "<object meta-data>" inherited from object.
16+        '''
17+        return str(dict(self.items()))
18+
19+    def __repr__(self):
20+        '''
21+        Returns something like
22+
23+            MergeDict({'key1': 'val1', 'key2': 'val2'}, {'key3': 'val3'})
24+
25+        instead of generic "<object meta-data>" inherited from object.
26+        '''
27+        dictreprs = ', '.join([repr(d) for d in self.dicts])
28+        return '%s(%s)' % (self.__class__.__name__, dictreprs)
29+
30 class SortedDict(dict):
31     "A dictionary that keeps its keys in the order in which they're inserted."
32     def __init__(self, data=None):