Hey, guys. Just thought I'd pass along this ugly little hack I made to the Durus 3.0 we're using in Schevo. The motivation for it was this. We've got a lot of Schevo unit tests that create and destroy Durus databases and it was starting to take a while to run all of them. I figured it would be faster if they used StringIO instead of an actual file on disk. For me, the time dropped from 60 seconds to 40 seconds, so it was worthwhile. To use it, I create a StringIO object that I pass as the fp argument. If I'm testing actual persistence, I save the StringIO object's value and feed it back in upon "reopening" that database file. I tried creating a StringIO subclass that had a fileno() method, but that didn't satisfy the requirements of the unlock_file() method, so I opted for the simpler solution you see below. The hack is a bit ugly, but I figured I'd sent it to possibly lead to a cleaner solution. If nobody else has a need for this, or if you don't think it is appropriate for Durus, then I can just continue to patch Schevo. In any case, here it is: Modified: trunk/schevo/store/file_storage.py ============================================================================== --- trunk/schevo/store/file_storage.py (original) +++ trunk/schevo/store/file_storage.py Fri Sep 23 20:21:42 2005 @@ -59,13 +59,15 @@ _PACK_INCREMENT = 20 # number of records to pack before yielding - def __init__(self, filename=None, readonly=False, repair=False): + def __init__(self, filename=None, readonly=False, repair=False, fp=None): """(filename:str=None, readonly:bool=False, repair:bool=False) If filename is empty (or None), a temporary file will be used. """ self.oid = 0 self.filename = filename - if readonly: + if fp is not None: + self.fp = fp + elif readonly: if not filename: raise ValueError( "A filename is required for a readonly storage.") @@ -162,7 +164,8 @@ self.fp, self._generate_pending_records(), index): pass self.fp.flush() - fsync(self.fp) + if hasattr(self.fp, 'fileno'): + fsync(self.fp) self.index.update(index) if self.pack_extra is not None: self.pack_extra.extend(index) @@ -280,7 +283,8 @@ def close(self): if self.fp is not None: - unlock_file(self.fp) + if hasattr(self.fp, 'fileno'): + unlock_file(self.fp) self.fp.close() self.fp = None -- Patrick K. O'Brien Orbtech http://www.orbtech.com Schevo http://www.schevo.org Pypersyst http://www.pypersyst.org