[gobject-introspection] scanner: sync with upstream OrderedDict



commit db7ab0e797f755fb7ff273a2071d27fd62a2b7c7
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date:   Sun Mar 15 20:35:29 2015 +0100

    scanner: sync with upstream OrderedDict
    
    Synced with https://github.com/zzzeek/sqlalchemy/commit/a4a826021fb6d77fadbdac0071616d7e5486e4d1

 giscanner/collections/ordereddict.py |   39 ++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 13 deletions(-)
---
diff --git a/giscanner/collections/ordereddict.py b/giscanner/collections/ordereddict.py
index 0cb4b95..e1f1afc 100644
--- a/giscanner/collections/ordereddict.py
+++ b/giscanner/collections/ordereddict.py
@@ -30,9 +30,20 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 
+import sys
+
+
+py2k = sys.version_info < (3, 0)
+
+
 class OrderedDict(dict):
     """A dict that returns keys/values/items in the order they were added."""
 
+    __slots__ = '_list',
+
+    def __reduce__(self):
+        return OrderedDict, (self.items(),)
+
     def __init__(self, ____sequence=None, **kwargs):
         self._list = []
         if ____sequence is None:
@@ -61,6 +72,7 @@ class OrderedDict(dict):
                     self.__setitem__(key, ____sequence[key])
             else:
                 for key, value in ____sequence:
+                    print key, value
                     self[key] = value
         if kwargs:
             self.update(kwargs)
@@ -75,25 +87,26 @@ class OrderedDict(dict):
     def __iter__(self):
         return iter(self._list)
 
+    def keys(self):
+        return list(self)
+
     def values(self):
         return [self[key] for key in self._list]
 
-    def itervalues(self):
-        return iter([self[key] for key in self._list])
-
-    def keys(self):
-        return list(self._list)
+    def items(self):
+        return [(key, self[key]) for key in self._list]
 
-    def iterkeys(self):
-        return iter(self.keys())
+    if py2k:
+        def itervalues(self):
+            return iter(self.values())
 
-    def items(self):
-        return [(key, self[key]) for key in self.keys()]
+        def iterkeys(self):
+            return iter(self)
 
-    def iteritems(self):
-        return iter(self.items())
+        def iteritems(self):
+            return iter(self.items())
 
-    def __setitem__(self, key, obj):
+    def __setitem__(self, key, object):
         if key not in self:
             try:
                 self._list.append(key)
@@ -101,7 +114,7 @@ class OrderedDict(dict):
                 # work around Python pickle loads() with
                 # dict subclass (seems to ignore __setstate__?)
                 self._list = [key]
-        dict.__setitem__(self, key, obj)
+        dict.__setitem__(self, key, object)
 
     def __delitem__(self, key):
         dict.__delitem__(self, key)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]