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

Jim Fulton jim at zope.com
Thu Dec 18 14:08:08 EST 2008


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)
 
     def __setstate__(self, state=None):
         # we use lists here because it will allow us to add and remove

Modified: ZODB/trunk/src/ZODB/tests/blob_basic.txt
===================================================================
--- ZODB/trunk/src/ZODB/tests/blob_basic.txt	2008-12-18 19:08:07 UTC (rev 94173)
+++ ZODB/trunk/src/ZODB/tests/blob_basic.txt	2008-12-18 19:08:08 UTC (rev 94174)
@@ -173,3 +173,12 @@
         ...
     TypeError: Blobs do not support subclassing.
 
+Passing data to the blob constructor
+------------------------------------
+
+If you have a small amount of data, you can pass it to the blob
+constructor.  (This is a convenience, mostly for writing tests.)
+
+    >>> myblob = Blob('some data')
+    >>> myblob.open().read()
+    'some data'



More information about the Zodb-checkins mailing list