durusmail: durus-users: StringIO Hack
StringIO Hack
2005-09-29
2005-09-29
2005-09-29
StringIO Hack
David Binger
2005-09-29
On Sep 29, 2005, at 8:53 AM, David Binger wrote:

> An early concrete Storage was something like the (untested) one below,

Here is a lightly tested version:

class MemoryStorage (Storage):

     def __init__(self):
         self.records = {}
         self.transaction = None

     def load(self, oid):
         return records[oid]

     def begin(self):
         self.transaction = {}

     def store(self, oid, record):
         self.transaction[oid] = record

     def end(self):
         self.records.update(self.transaction)
         self.transaction = None

     def sync(self):
         return []

     def gen_oid_record(self):
         for oid, record in self.records.iteritems():
             yield oid, record

reply