[gobject-introspection] giscanner: use collections.OrderedDict when available
- From: Dieter Verfaillie <dieterv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] giscanner: use collections.OrderedDict when available
- Date: Wed, 28 Nov 2012 20:57:00 +0000 (UTC)
commit b0a78b8734aee54b0f976fc4f1194bb73f7e52f4
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date: Thu Jul 5 21:30:01 2012 +0200
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
giscanner/odict.py | 37 +++++++++++++++++++++----------------
1 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/giscanner/odict.py b/giscanner/odict.py
index df703cb..fa164c3 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[:]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]