

from Ft.Ods import Constants


class DictionaryLiteralKeyMixin:

    def _4ods_setByKey(self,key,value):

        Constants.g_typeCheck[self._keyType](key,self._keyRepoId)

        key = key._4ods_getData()

        if self._values.has_key(key):
            self._dbChanges.append((Constants.DictionaryChanges.CHANGE,key,value))
        else:
            self._dbChanges.append((Constants.DictionaryChanges.ADD,key,value))
        self._values[key] = value

    def _4ods_getByKey(self,key):
        return self._values[key._4ods_getData()]

    def _4ods_deleteByKey(self,key):
        key = key._4ods_getData()
        self._dbChanges.append((Constants.DictionaryChanges.REMOVE,key,None))
        del self._values[key]

    def _4ods_initValueKeys(self):
        pass

    def _4ods_prepareKeyChanges(self):
        pass



    def has_key(self,key):
        return self._values.has_key(key._4ods_getData())

    def keys(self):
        keys = []
        for value in self._values.keys():
            keys.append(self._db.current()._4ods_createLiteralInstance(self._keyType,self._keyRepoId,value))
        return keys
