1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2007-2008 www.stani.be
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program. If not, see http://www.gnu.org/licenses/
19
"""This one uses generators in places where it can, and plays nicely
22
def __init__(self, d={}):
24
dict.__init__(self, d)
26
def __delitem__(self, key):
27
dict.__delitem__(self, key)
28
self._keys.remove(key)
30
def __setitem__(self, key, item):
31
dict.__setitem__(self, key, item)
32
# a peculiar sharp edge from copy.deepcopy
33
# we'll have our set item called without __init__
34
if not hasattr(self, '_keys'):
36
if key not in self._keys:
37
self._keys.append(key)
51
if len(self._keys) == 0:
52
raise KeyError('dictionary is empty')
59
def setdefault(self, key, failobj = None):
60
dict.setdefault(self, key, failobj)
61
if key not in self._keys:
62
self._keys.append(key)
66
if not self.has_key(key):
67
self._keys.append(key)
74
def move(self, key, index):
76
""" Move the specified to key to *before* the specified index. """
79
cur = self._keys.index(key)
82
self._keys.insert(index, key)
83
# this may have shifted the position of cur, if it is after index
84
if cur >= index: cur = cur + 1
88
if not self.has_key(key):
90
return self._keys.index(key)
92
if __name__ == '__main__':
b'\\ No newline at end of file'