From: khamidou Date: Mon, 15 Mar 2010 13:53:09 +0000 (+0100) Subject: added the possibility to use an output encoder X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ad171a8feb1434ce6093a12b755656c74bf0e83a;p=cabinet.git added the possibility to use an output encoder --- diff --git a/cabinet.py b/cabinet.py index 5a1c593..138f527 100644 --- a/cabinet.py +++ b/cabinet.py @@ -8,9 +8,10 @@ except ImportError: class Cabinet(object): - def __init__(self, filename, *args): + def __init__(self, filename, Encoder=json.JSONEncoder, *args): self.db = bsddb.hashopen(filename) self.cache = {} + self.encoder = Encoder def __getitem__(self, key): if self.cache.has_key(key): @@ -35,6 +36,6 @@ class Cabinet(object): def sync(self): for key in self.cache: - self.db[key] = json.dumps(self.cache[key]) + self.db[key] = json.dumps(self.cache[key], cls=self.encoder) self.db.sync()