summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDieter Verfaillie <dieterv@optionexplicit.be>2012-07-05 21:30:01 +0200
committerDieter Verfaillie <dieterv@optionexplicit.be>2012-11-28 21:31:22 +0100
commitb0a78b8734aee54b0f976fc4f1194bb73f7e52f4 (patch)
tree9edba5895d881a739d71d34c124b98007289ac86
parent93abf1c2f65a2378971a056d6f5e7df68e9e72c4 (diff)
downloadgobject-introspection-b0a78b8734aee54b0f976fc4f1194bb73f7e52f4.tar.gz
giscanner: use collections.OrderedDict when available
Starting with Python 2.7 we can use the batteries included collections.OrderedDict class. However, configure.ac claims we still support Python 2.5 and 2.6, so don't remove our custom odict implementation just yet... https://bugzilla.gnome.org/show_bug.cgi?id=688897
-rw-r--r--giscanner/odict.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/giscanner/odict.py b/giscanner/odict.py
index df703cbb..fa164c31 100644
--- a/giscanner/odict.py
+++ b/giscanner/odict.py
@@ -20,26 +20,31 @@
"""odict - an ordered dictionary"""
-from UserDict import DictMixin
+try:
+ # Starting with Python 2.7 we can use collections.OrderedDict
+ from collections import OrderedDict as odict
+except ImportError:
+ # But we still support Python 2.5 and 2.6
+ from UserDict import DictMixin
-class odict(DictMixin):
+ class odict(DictMixin):
- def __init__(self):
- self._items = {}
- self._keys = []
+ def __init__(self):
+ self._items = {}
+ self._keys = []
- def __setitem__(self, key, value):
- if key not in self._items:
- self._keys.append(key)
- self._items[key] = value
+ def __setitem__(self, key, value):
+ if key not in self._items:
+ self._keys.append(key)
+ self._items[key] = value
- def __getitem__(self, key):
- return self._items[key]
+ def __getitem__(self, key):
+ return self._items[key]
- def __delitem__(self, key):
- del self._items[key]
- self._keys.remove(key)
+ def __delitem__(self, key):
+ del self._items[key]
+ self._keys.remove(key)
- def keys(self):
- return self._keys[:]
+ def keys(self):
+ return self._keys[:]