[Checkins] SVN: ZODB/trunk/src/ZODB/ As a small convenience (mainly for tests), you can now specify

Jim Fulton jim at zope.com
Fri Dec 19 08:24:41 EST 2008


On Dec 19, 2008, at 2:29 AM, Christian Theune wrote:

> On Thu, 2008-12-18 at 14:08 -0500, Jim Fulton wrote:
>> Log message for revision 94174:
>>  As a small convenience (mainly for tests), you can now specify
>>  initial data as a string argument to the Blob constructor.
>>
>>
>> Changed:
>>  U   ZODB/trunk/src/ZODB/blob.py
>>  U   ZODB/trunk/src/ZODB/tests/blob_basic.txt
>>
>> -=-
>> Modified: ZODB/trunk/src/ZODB/blob.py
>> ===================================================================
>> --- ZODB/trunk/src/ZODB/blob.py	2008-12-18 19:08:07 UTC (rev 94173)
>> +++ ZODB/trunk/src/ZODB/blob.py	2008-12-18 19:08:08 UTC (rev 94174)
>> @@ -63,12 +63,14 @@
>>
>>     readers = writers = None
>>
>> -    def __init__(self):
>> +    def __init__(self, data=None):
>>         # Raise exception if Blobs are getting subclassed
>>         # refer to ZODB-Bug No.127182 by Jim Fulton on 2007-07-20
>>         if (self.__class__ is not Blob):
>>             raise TypeError('Blobs do not support subclassing.')
>>         self.__setstate__()
>> +        if data is not None:
>> +            self.open('w').write(data)
>
> Something I'm never sure about: how long will this leave the file  
> handle
> open and let the blob stay in 'already opened' mode?

The file will be garbage collected and closed immediately.  There are  
no circular references to keep it around.  This is perfectly fine.


> I wonder whether closing the file explicitly would be a good idea  
> here.


Some would argue that it would be hygenic, but I think it would just  
clutter the code.

Jim

--
Jim Fulton
Zope Corporation




More information about the Checkins mailing list