comparison 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
comparison
equal deleted inserted replaced
1339:18cd46a264e9 1340:91e72da1d093
116 return self._cache.__delitem__(key) 116 return self._cache.__delitem__(key)
117 117
118 def get(self, key, default=None): 118 def get(self, key, default=None):
119 return self._cache.get(key, default) 119 return self._cache.get(key, default)
120 120
121 def setdefault(self, key, default):
122 try:
123 return self._cache[key]
124 except:
125 self.__setitem__(key, default)
126 return default
127
121 def force(self, name): 128 def force(self, name):
122 """Force saving of an attribute to storage 129 """Force saving of an attribute to storage
123 @return: deferred fired when data is actually saved""" 130 @return: deferred fired when data is actually saved"""
124 if not self.profile: 131 if not self.profile:
125 return self.storage.setGenPrivate(self.namespace, name, self._cache[name]) 132 return self.storage.setGenPrivate(self.namespace, name, self._cache[name])