Commits

Chris Mutel committed 00eb45e

Added more methods to serialized dicts and moved _data to data

  • Participants
  • Parent commits bb32871

Comments (0)

Files changed (2)

File brightway2/meta.py

     _filename = "mapping.pickle"
 
     def add(self, keys):
-        index = max(self._data.values())
+        index = max(self.data.values())
         for i, key in enumerate(keys):
-            if key not in self._data:
-                self._data[key] = index + i + 1
+            if key not in self.data:
+                self.data[key] = index + i + 1
         self.flush()
 
     def delete(self, keys):
         for key in keys:
-            del self._data[key]
+            del self.data[key]
         self.flush()
 
     def __setitem__(self, key, value):
     _filename = "databases.json"
 
     def increment_version(self, database):
-        self._data[database]["version"] += 1
+        self.data[database]["version"] += 1
         self.flush()
-        return self._data[database]["version"]
+        return self.data[database]["version"]
 
     def version(self, database):
-        return self._data[database]["version"]
+        return self.data[database]["version"]
 
     def __unicode__(self):
         return u"Brightway2 databases metadata with %i objects" % len(
-            self._data)
+            self.data)
 
 
 class Methods(SerializedDict):
 
     def __unicode__(self):
         return u"Brightway2 methods metadata with %i objects" % len(
-            self._data)
+            self.data)
 
 
 mapping = Mapping()

File brightway2/serialization.py

 
     def load(self):
         try:
-            self._data = self.deserialize()
+            self.data = self.deserialize()
         except IOError:
             # Create if not present
-            self._data = {}
+            self.data = {}
             self.flush()
 
     def flush(self):
         self.serialize()
 
     @property
-    def data(self):
-        return self._data
-
-    @property
     def list(self):
-        return self._data.keys()
+        return sorted(self.data.keys())
 
     def __getitem__(self, key):
-        return self._data[key]
+        return self.data[key]
 
     def __setitem__(self, key, value):
-        self._data[key] = value
+        self.data[key] = value
         self.flush()
 
     def __contains__(self, key):
-        return key in self._data
+        return key in self.data
 
     def __str__(self):
         return self.__unicode__()
 
     def __delitem__(self, name):
-        del self._data[name]
+        del self.data[name]
         self.flush()
 
+    def iteritems(self):
+        return self.data.iteritems()
+
+    def keys(self):
+        return self.data.keys()
+
+    def values(self):
+        return self.data.values()
+
     def serialize(self, filepath=None):
         with open(filepath or self._filepath, "w") as f:
-            json.dump(self.pack(self._data), f, indent=2)
+            json.dump(self.pack(self.data), f, indent=2)
 
     def deserialize(self):
         return self.unpack(json.load(open(self._filepath, "r")))
 class PickledDict(SerializedDict):
     def serialize(self):
         with open(self._filepath, "wb") as f:
-            pickle.dump(self.pack(self._data), f,
+            pickle.dump(self.pack(self.data), f,
                 protocol=pickle.HIGHEST_PROTOCOL)
 
     def deserialize(self):