autocommits = True
cleanse_keys = True
+ serialize_eclasses = False
def __init__(self, *args, **config):
super(database,self).__init__(*args, **config)
def iteritems(self):
return self.__db.iteritems()
- def __getitem__(self, cpv):
+ def _getitem(self, cpv):
# we override getitem because it's just a cpickling of the data handed in.
- d = pickle.loads(self.__db[cpv])
- if "_eclasses_" in d:
- d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"])
- return d
-
+ return pickle.loads(self.__db[cpv])
def _setitem(self, cpv, values):
self.__db[cpv] = pickle.dumps(values,pickle.HIGHEST_PROTOCOL)
def _delitem(self, cpv):
del self.__db[cpv]
-
def iterkeys(self):
return iter(self.__db)
-
def has_key(self, cpv):
return cpv in self.__db
-
def __del__(self):
if "__db" in self.__dict__ and self.__db != None:
self.__db.sync()
complete_eclass_entries_ = True
autocommits = False
cleanse_keys = False
+ serialize_eclasses = True
def __init__(self, location, label, auxdbkeys, readonly=False):
""" initialize the derived class; specifically, store label/keys"""
self.readonly = readonly
self.sync_rate = 0
self.updates = 0
-
def __getitem__(self, cpv):
"""set a cpv to values
self.commit()
self.updates = 0
d=self._getitem(cpv)
- if "_eclasses_" in d:
+ if self.serialize_eclasses and "_eclasses_" in d:
d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"])
return d
override this in derived classess"""
raise NotImplementedError
-
def __setitem__(self, cpv, values):
"""set a cpv to values
This shouldn't be overriden in derived classes since it handles the readonly checks"""
for k in d.keys():
if d[k] == '':
del d[k]
- if "_eclasses_" in values:
+ if self.serialize_eclasses and "_eclasses_" in values:
d["_eclasses_"] = serialize_eclasses(d["_eclasses_"])
- elif "_eclasses_" in values:
+ elif self.serialize_eclasses and "_eclasses_" in values:
d = ProtectedDict(values)
d["_eclasses_"] = serialize_eclasses(d["_eclasses_"])
else:
self.commit()
self.updates = 0
-
def _setitem(self, name, values):
"""__setitem__ calls this after readonly checks. override it in derived classes
note _eclassees_ key *must* be handled"""
raise NotImplementedError
-
def __delitem__(self, cpv):
"""delete a key from the cache.
This shouldn't be overriden in derived classes since it handles the readonly checks"""
self.commit()
self.updates = 0
-
def _delitem(self,cpv):
"""__delitem__ calls this after readonly checks. override it in derived classes"""
raise NotImplementedError
-
def has_key(self, cpv):
raise NotImplementedError
-
def keys(self):
return tuple(self.iterkeys())
if not self.autocommits:
raise NotImplementedError
+ def __contains__(self, cpv):
+ return self.has_key(cpv)
+
def get_matches(self, match_dict):
"""generic function for walking the entire cache db, matching restrictions to
filter what cpv's are returned. Derived classes should override this if they
cont = False
break
if cont:
-# yield cpv,vals
yield cpv