'''
Dictionary store
=================

Use a Python dictionary as a store.
'''

__all__ = ('DictStore', )

try:
    import cPickle as pickle
except ImportError:
    import pickle

from os.path import exists
from kivy.compat import iteritems
from kivy.storage import AbstractStore


class DictStore(AbstractStore):
    '''Store implementation using a pickled `dict`.
    See the :mod:`kivy.storage` module documentation for more information.
    '''
    def __init__(self, filename, data=None, **kwargs):
        self.filename = filename
        self._data = data or {}
        self._is_changed = True
        super(DictStore, self).__init__(**kwargs)

    def store_load(self):
        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 not self._is_changed:
            return

        with open(self.filename, 'w') as fd:
            pickle.dump(self._data, fd)

        self._is_changed = False

    def store_exists(self, key):
        return key in self._data

    def store_get(self, key):
        return self._data[key]

    def store_put(self, key, value):
        self._data[key] = value
        return True

    def store_delete(self, key):
        del self._data[key]
        return True

    def store_find(self, filters):
        for key, values in iteritems(self._data):
            found = True
            for fkey, fvalue in iteritems(filters):
                if fkey not in values:
                    found = False
                    break
                if values[fkey] != fvalue:
                    found = False
                    break
            if found:
                yield key, values

    def store_count(self):
        return len(self._data)

    def store_keys(self):
        return self._data.keys()

@@ -494,24 +494,213 @@
  **kwargs):%0A
+        if isinstance(filename, dict):%0A            # backward compatibility, first argument was a dict.%0A            self.filename = None%0A            self._data = filename%0A        else:%0A    
         self
@@ -712,32 +712,36 @@
 name = filename%0A
+    
         self._da
@@ -857,32 +857,85 @@
 ore_load(self):%0A
+        if self.filename is None:%0A            return%0A
         if not e
@@ -967,33 +967,32 @@
          return%0A
-%0A
         with ope
@@ -1115,24 +1115,24 @@
 oads(data)%0A%0A
-
     def stor
@@ -1137,32 +1137,85 @@
 ore_sync(self):%0A
+        if self.filename is None:%0A            return%0A
         if not s

add backward compatibility for the first argument.