diff sat/memory/persistent.py @ 3253:1af840e84af7

core (memory/persistent): fixed "items", added "all" + "adel" to LazyPersistentBinaryDict: - `items` was returning the dict with all values, it now returns a Deferred with actual dict items() - `all` new method does return the dict with all values (in a Deferred) - `adel` has been added to LazyPersistentBinaryDict
author Goffi <goffi@goffi.org>
date Tue, 14 Apr 2020 20:36:24 +0200
parents 78fea49735c5
children be6d91572633
line wrap: on
line diff
--- a/sat/memory/persistent.py	Tue Apr 14 20:29:37 2020 +0200
+++ b/sat/memory/persistent.py	Tue Apr 14 20:36:24 2020 +0200
@@ -66,7 +66,7 @@
         return iter(self._cache.items())
 
     def items(self):
-        return list(self._cache.items())
+        return self._cache.items()
 
     def __repr__(self):
         return self._cache.__repr__()
@@ -178,6 +178,11 @@
         raise NotImplementedError
 
     def items(self):
+        d = self.storage.getPrivates(self.namespace, binary=self.binary, profile=self.profile)
+        d.addCallback(lambda data_dict: data_dict.items())
+        return d
+
+    def all(self):
         return self.storage.getPrivates(self.namespace, binary=self.binary, profile=self.profile)
 
     def __repr__(self):
@@ -257,6 +262,12 @@
         return self.storage.setPrivateValue(self.namespace, key, value,
                                             self.binary, self.profile)
 
+    def adel(self, key):
+        """Async del, return a Deferred fired when value is actually deleted"""
+        # XXX: similar as PersistentDict.adel, but doesn't use cache
+        return self.storage.delPrivateValue(
+            self.namespace, key, self.binary, self.profile)
+
     def setdefault(self, key, default):
         raise NotImplementedError