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 9:09 AM, David Binger wrote:

>
> 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:

Doh!  I pasted the wrong version.  This time I mean it.


class MemoryStorage (Storage):
     """
     A concrete Storage that keeps everything in memory.
     This may be useful for testing purposes.
     """
     def __init__(self):
         self.records = {}
         self.transaction = None
         self.oid = 0

     def new_oid(self):
         self.oid += 1
         return p64(self.oid)

     def load(self, oid):
         return self.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