diff src/memory/persistent.py @ 1340:91e72da1d093 frontends_multi_profiles

core (persistent dict): added setdefault method
author Goffi <goffi@goffi.org>
date Tue, 24 Feb 2015 16:54:28 +0100
parents b29a065a66f0
children 069ad98b360d
line wrap: on
line diff
--- a/src/memory/persistent.py	Tue Feb 24 16:52:44 2015 +0100
+++ b/src/memory/persistent.py	Tue Feb 24 16:54:28 2015 +0100
@@ -118,6 +118,13 @@
     def get(self, key, default=None):
         return self._cache.get(key, default)
 
+    def setdefault(self, key, default):
+        try:
+            return self._cache[key]
+        except:
+            self.__setitem__(key, default)
+            return default
+
     def force(self, name):
         """Force saving of an attribute to storage
         @return: deferred fired when data is actually saved"""