gimarshallingtests: Add string_ to boxed structure
[platform/upstream/gobject-introspection.git] / 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 try:
24     # Starting with Python 2.7 we can use collections.OrderedDict
25     from collections import OrderedDict as odict
26 except ImportError:
27     # But we still support Python 2.5 and 2.6
28     from UserDict import DictMixin
29
30
31     class odict(DictMixin):
32
33         def __init__(self):
34             self._items = {}
35             self._keys = []
36
37         def __setitem__(self, key, value):
38             if key not in self._items:
39                 self._keys.append(key)
40             self._items[key] = value
41
42         def __getitem__(self, key):
43             return self._items[key]
44
45         def __delitem__(self, key):
46             del self._items[key]
47             self._keys.remove(key)
48
49         def keys(self):
50             return self._keys[:]