dictstore: add backward compatibility for the first argument.

This commit is contained in:
Mathieu Virbel 2014-04-06 17:39:59 +02:00
parent 9e408b2877
commit e6c2c6d25c
1 changed files with 11 additions and 3 deletions

View File

@ -22,21 +22,29 @@ class DictStore(AbstractStore):
See the :mod:`kivy.storage` module documentation for more information.
'''
def __init__(self, filename, data=None, **kwargs):
self.filename = filename
self._data = data or {}
if isinstance(filename, dict):
# backward compatibility, first argument was a dict.
self.filename = None
self._data = filename
else:
self.filename = filename
self._data = data or {}
self._is_changed = True
super(DictStore, self).__init__(**kwargs)
def store_load(self):
if self.filename is None:
return
if not exists(self.filename):
return
with open(self.filename, 'r') as fd:
data = fd.read()
if data:
self._data = pickle.loads(data)
def store_sync(self):
if self.filename is None:
return
if not self._is_changed:
return