durusmail: durus-users: StringIO Hack
StringIO Hack
2005-09-29
2005-09-29
2005-09-29
StringIO Hack
David Binger
2005-09-29
An early concrete Storage was something like the (untested) one below,
which might satisfy your need for a faster testing-only storage.  This
seems a little better than adding another option to the FileStorage
constructor.

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