Merge remote branch 'origin'
[gnome.gobject-introspection] / giscanner / odict.py
1 # -*- Mode: Python -*-
2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008  Johan Dahlin
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
9 #
10 # This library 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 GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
19 #
20
21 """odict - an ordered dictionary"""
22
23 from UserDict import DictMixin
24
25
26 class odict(DictMixin):
27
28     def __init__(self):
29         self._items = {}
30         self._keys = []
31
32     def __setitem__(self, key, value):
33         if key not in self._items:
34             self._keys.append(key)
35         self._items[key] = value
36
37     def __getitem__(self, key):
38         return self._items[key]
39
40     def __delitem__(self, key):
41         del self._items[key]
42         self._keys.remove(key)
43
44     def keys(self):
45         return self._keys[:]