comparison src/memory/persistent.py @ 592:e5a875a3311b

Fix pep8 support in src/memory.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:35 +0100
parents beaf6bec2fcd
children 84a6e83157c2
comparison
equal deleted inserted replaced
591:65821b3fa7ab 592:e5a875a3311b
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 from logging import debug, info, warning, error 22 from logging import debug, info, warning, error
23 23
24
24 class MemoryNotInitializedError(Exception): 25 class MemoryNotInitializedError(Exception):
25 pass 26 pass
26 27
28
27 class PersistentDict(object): 29 class PersistentDict(object):
28 """A dictionary which save persistently each value assigned 30 r"""A dictionary which save persistently each value assigned
29 /!\ be careful, each assignment means a database write 31 /!\ be careful, each assignment means a database write
30 /!\ Memory must be initialised before loading/setting value with instances of this class""" 32 /!\ Memory must be initialised before loading/setting value with instances of this class"""
31 storage = None 33 storage = None
32 34
33 def __init__(self, namespace, profile=None): 35 def __init__(self, namespace, profile=None):
78 def __hash__(self): 80 def __hash__(self):
79 return self._cache.__hash__() 81 return self._cache.__hash__()
80 82
81 def __nonzero__(self): 83 def __nonzero__(self):
82 return self._cache.__len__() 84 return self._cache.__len__()
83
84 def __unicode__(self):
85 return self._cache.__unicode__()
86 85
87 def __contains__(self, key): 86 def __contains__(self, key):
88 return self._cache.__contains__(key) 87 return self._cache.__contains__(key)
89 88
90 def __getitem__(self, key): 89 def __getitem__(self, key):
144 """Force saving of an attribute to storage 143 """Force saving of an attribute to storage
145 @return: deferred fired when data is actually saved""" 144 @return: deferred fired when data is actually saved"""
146 if not self.profile: 145 if not self.profile:
147 return self.storage.setGenPrivateBinary(self.namespace, name, self._cache[name]) 146 return self.storage.setGenPrivateBinary(self.namespace, name, self._cache[name])
148 return self.storage.setIndPrivateBinary(self.namespace, name, self._cache[name], self.profile) 147 return self.storage.setIndPrivateBinary(self.namespace, name, self._cache[name], self.profile)
149