Revision 486f00d3

b/kamaki/utils.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
class OrderedDict(dict):
35
    """An ordered dict implementation for Python versions prior to 2.7"""
34
try:
35
    from collections import OrderDict
36
except ImportError:
37
    class OrderedDict(dict):
38
        """An ordered dict implementation for Python versions prior to 2.7"""
36 39
    
37
    def __init__(self):
38
        dict.__init__(self)
39
        self._keys = []
40
        def __init__(self):
41
            dict.__init__(self)
42
            self._keys = []
40 43
    
41
    def __delitem__(self, key):
42
        dict.__delitem__(self, key)
43
        self._keys.remove(key)
44
        def __delitem__(self, key):
45
            dict.__delitem__(self, key)
46
            self._keys.remove(key)
44 47
    
45
    def __iter__(self):
46
        return iter(self._keys)
48
        def __iter__(self):
49
            return iter(self._keys)
47 50
    
48
    def __repr__(self):
49
        return repr(self.items())
51
        def __repr__(self):
52
            return repr(self.items())
50 53
    
51
    def __setitem__(self, key, value):
52
        if key not in self:
53
            self._keys.append(key)
54
        dict.__setitem__(self, key, value)
54
        def __setitem__(self, key, value):
55
            if key not in self:
56
                self._keys.append(key)
57
            dict.__setitem__(self, key, value)
55 58
    
56
    def keys(self):
57
        return self._keys
59
        def keys(self):
60
            return self._keys
58 61
    
59
    def iteritems(self):
60
        for key in self._keys:
61
            yield key, self[key]
62
        def iteritems(self):
63
            for key in self._keys:
64
                yield key, self[key]
62 65
    
63
    def items(self):
64
        return list(self.iteritems())
66
        def items(self):
67
            return list(self.iteritems())
65 68

  
66 69

  
67 70
def print_addresses(addresses, margin):

Also available in: Unified diff