Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZODB
Commits
ecdb05ba
Commit
ecdb05ba
authored
Dec 18, 2008
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
As a small convenience (mainly for tests), you can now specify
initial data as a string argument to the Blob constructor.
parent
42b20433
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
src/ZODB/blob.py
src/ZODB/blob.py
+3
-1
src/ZODB/tests/blob_basic.txt
src/ZODB/tests/blob_basic.txt
+9
-0
No files found.
src/ZODB/blob.py
View file @
ecdb05ba
...
@@ -63,12 +63,14 @@ class Blob(persistent.Persistent):
...
@@ -63,12 +63,14 @@ class Blob(persistent.Persistent):
readers
=
writers
=
None
readers
=
writers
=
None
def
__init__
(
self
):
def
__init__
(
self
,
data
=
None
):
# Raise exception if Blobs are getting subclassed
# Raise exception if Blobs are getting subclassed
# refer to ZODB-Bug No.127182 by Jim Fulton on 2007-07-20
# refer to ZODB-Bug No.127182 by Jim Fulton on 2007-07-20
if
(
self
.
__class__
is
not
Blob
):
if
(
self
.
__class__
is
not
Blob
):
raise
TypeError
(
'Blobs do not support subclassing.'
)
raise
TypeError
(
'Blobs do not support subclassing.'
)
self
.
__setstate__
()
self
.
__setstate__
()
if
data
is
not
None
:
self
.
open
(
'w'
).
write
(
data
)
def
__setstate__
(
self
,
state
=
None
):
def
__setstate__
(
self
,
state
=
None
):
# we use lists here because it will allow us to add and remove
# we use lists here because it will allow us to add and remove
...
...
src/ZODB/tests/blob_basic.txt
View file @
ecdb05ba
...
@@ -173,3 +173,12 @@ Blobs are not subclassable::
...
@@ -173,3 +173,12 @@ Blobs are not subclassable::
...
...
TypeError: Blobs do not support subclassing.
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'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment