Commits

markolopa committed 4a4612c

[persister] two bug fixes

  • Participants
  • Parent commits 77c5443

Comments (0)

Files changed (2)

File persister/container.py

             yield x
             
     def insert(self, i, value):
-        _list = self._persister.load(self._name, [])
+        _list = self._persister.load(self._name, [], pickle=self.pickle)
         _list.insert(i, value)
         self._persister.save(self._name, _list, [], pickle=self.pickle)
 
     def append(self, value):
-        _list = self._persister.load(self._name, [])
+        _list = self._persister.load(self._name, [], pickle=self.pickle)
         _list.append(value)
         self._persister.save(self._name, _list, [], pickle=self.pickle)
 
             if isinstance(obj, PersistentListOrDict):
                 return self._list_or_dict_references[name]
             else:
-                return self._persister.load(name, obj.default_value)
+                return self._persister.load(name, obj.default_value, obj.pickle)
 
         return obj
         

File persister/flexible_persister.py

             if persister.data_dir is not None:
                 fname = '--'.join(path_items)
                 return os.path.join(persister.data_dir, fname)
-            path_items.append(persister.name)
+            path_items.insert(0, persister.name)
+            persister = persister.parent
             count += 1
             if count > 100:
                 raise RuntimeError("infinite loop avoided")
         # special case: pickle file
         if pickle:
             path = self._compute_attribute_path_pickle(name)
-            with open(path, 'r') as fobj:
-                return cPickle.load(fobj)
+            if os.path.exists(path):
+                with open(path, 'r') as fobj:
+                    return cPickle.load(fobj)
+            else:
+                return self._compute_default(default_value)
 
         # is_dir : attributes in files
         if self.is_dir:
         # special case: pickle file
         if pickle:
             path = self._compute_attribute_path_pickle(name)
-            with open(path, 'w') as fobj:
-                cPickle.dump(value, fobj)
-                return
+            if value == default_value and os.path.exists(path):
+                os.remove(path)
+            else:
+                with open(path, 'w') as fobj:
+                    cPickle.dump(value, fobj)
+            return
 
         # normal case: yaml file
         if self.is_dir: