Commit 95563b19 authored by Jim Fulton's avatar Jim Fulton

As a small convenience (mainly for tests), you can now specify

initial data as a string argument to the Blob constructor.
parent f313dd97
......@@ -63,12 +63,14 @@ class Blob(persistent.Persistent):
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
......
......@@ -173,3 +173,12 @@ Blobs are not subclassable::
...
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'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment