本文整理汇总了Python中ZODB.blob.Blob类的典型用法代码示例。如果您正苦于以下问题:Python Blob类的具体用法?Python Blob怎么用?Python Blob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Blob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _deserialize
def _deserialize(kls, data):
blob = Blob()
bfile = blob.open('w')
data = base64.b64decode(data['data'])
bfile.write(data)
bfile.close()
return blob
示例2: __call__
def __call__(self):
from ZODB.blob import Blob
from plone.app.blob.iterators import BlobStreamIterator
myblob = Blob()
with myblob.open('w') as fd:
fd.write('Hi, Blob!')
return BlobStreamIterator(myblob)
示例3: crop_factory
def crop_factory(fieldname, direction='keep', **parameters):
blob = Blob()
result = blob.open('w')
_, image_format, dimensions = scaleImage(
data['data'], result=result, **parameters)
result.close()
return blob, image_format, dimensions
示例4: _store_resized_image
def _store_resized_image(self, key, data):
""" store a blob image as attribute """
blob = Blob()
f = blob.open('w')
f.write(data['data'])
f.close()
setattr(self, key, blob)
self._p_changed = 1
示例5: __call__
def __call__(self):
from ZODB.blob import Blob
from plone.app.blob.iterators import BlobStreamIterator
myblob = Blob()
f = myblob.open("w")
f.write("Hi, Blob!")
f.close()
return BlobStreamIterator(myblob)
示例6: saveFileToBlob
def saveFileToBlob(filepath):
blob = Blob()
fi = open(filepath)
bfile = blob.open('w')
bfile.write(fi.read())
bfile.close()
fi.close()
return blob
示例7: addfile
def addfile(fname):
myblob = Blob()
b=myblob.open('w')
o=open(fname)
data = o.read()
b.write(data)
print b.name
b.close()
return myblob
示例8: testBlobbableOFSFileWithoutFileName
def testBlobbableOFSFileWithoutFileName(self):
obj = File('foo', 'Foo', getFile('plone.pdf'), 'application/pdf')
blobbable = IBlobbable(obj)
target = Blob()
blobbable.feed(target)
self.assertEqual(target.open('r').read(),
getFile('plone.pdf').read())
self.assertEqual(blobbable.filename(), '')
self.assertEqual(blobbable.mimetype(), 'application/pdf')
示例9: __init__
def __init__(self, mimetype, fd):
self.mimetype = mimetype
blob = Blob()
blobfd = blob.open('w')
copyfileobj(fd, blobfd)
blobfd.close()
self.data = blob
示例10: NamedBlobFile
class NamedBlobFile(Persistent):
"""A file stored in a ZODB BLOB, with a filename"""
implements(INamedBlobFile)
filename = FieldProperty(INamedFile["filename"])
def __init__(self, data="", contentType="", filename=None):
if filename is not None and contentType in ("", "application/octet-stream"):
contentType = get_contenttype(filename=filename)
self.contentType = contentType
self._blob = Blob()
f = self._blob.open("w")
f.write("")
f.close()
self._setData(data)
self.filename = filename
def open(self, mode="r"):
if mode != "r" and "size" in self.__dict__:
del self.__dict__["size"]
return self._blob.open(mode)
def openDetached(self):
return open(self._blob.committed(), "rb")
def _setData(self, data):
if "size" in self.__dict__:
del self.__dict__["size"]
# Search for a storable that is able to store the data
dottedName = ".".join((data.__class__.__module__, data.__class__.__name__))
storable = getUtility(IStorage, name=dottedName)
storable.store(data, self._blob)
def _getData(self):
fp = self._blob.open("r")
data = fp.read()
fp.close()
return data
_data = property(_getData, _setData)
data = property(_getData, _setData)
@property
def size(self):
if "size" in self.__dict__:
return self.__dict__["size"]
reader = self._blob.open()
reader.seek(0, 2)
size = int(reader.tell())
reader.close()
self.__dict__["size"] = size
return size
def getSize(self):
return self.size
示例11: testBlobbableOFSImage
def testBlobbableOFSImage(self):
gif = getImage()
obj = Image('foo', 'Foo', StringIO(gif))
obj.filename = 'foo.gif'
blobbable = IBlobbable(obj)
target = Blob()
blobbable.feed(target)
self.assertEqual(target.open('r').read(), gif)
self.assertEqual(blobbable.filename(), 'foo.gif')
self.assertEqual(blobbable.mimetype(), 'image/gif')
示例12: put
def put(self, key, src, cache_tag, headers=()):
blobfile = Blob()
self.persistent_map[key] = (headers, cache_tag, blobfile)
f = blobfile.open('w')
size = 0
while 1:
data = src.read(1 << 21)
if not data:
break
size += len(data)
f.write(data)
f.close()
示例13: testBlobbableBinaryFile
def testBlobbableBinaryFile(self):
_file = os.path.join(os.path.dirname(__file__), 'data', 'image.gif')
with open(_file, 'rb') as f:
obj = Binary(f)
obj.filename = 'image.gif'
blobbable = IBlobbable(obj)
target = Blob()
blobbable.feed(target)
self.assertEqual(target.open('r').read(),
getFile('image.gif').read())
self.assertEquals(blobbable.filename(), 'image.gif')
self.assertEquals(blobbable.mimetype(), 'image/gif')
示例14: Tutorial
class Tutorial(Persistent):
implements(ITutorial)
attachment_name = None
attachment_data = None
attachment_mimetype = None
def __init__(self, title, author_name, text, url=None, code=None,
language=None, stream=None, file_name=None, mime_type=None):
self.title = title
self.author_name = author_name
self.url = url
self.text = text
self.code = code
self.language = language
self.date = datetime.now()
self.attachment_data = Blob()
self.attachment_name = file_name
self.attachment_mimetype = mime_type
self.upload(stream)
def upload(self, stream):
if stream is not None:
f = self.attachment_data.open('w')
size = save_data(stream, f)
f.close()
self.attachment_size = size
示例15: __init__
def __init__(self, stream=None, mimetype=None, title=u''):
""" The constructor of a File object.
``stream`` should be a filelike object (an object with a ``read``
method that takes a size argument) or ``None``. If stream is
``None``, the blob attached to this file object is created empty.
``title`` must be a string or Unicode object.
``mimetype`` may be any of the following:
- ``None``, meaning set this file object's mimetype to
``application/octet-stream`` (the default).
- A mimetype string (e.g. ``image/gif``)
- The constant :attr:`substanced.file.USE_MAGIC`, which will
derive the mimetype from the stream content (if ``stream`` is also
supplied) using the ``python-magic`` library.
.. warning::
On non-Linux systems, successful use of
:attr:`substanced.file.USE_MAGIC` requires the installation
of additional dependencies. See :ref:`optional_dependencies`.
"""
self.blob = Blob()
self.mimetype = mimetype or 'application/octet-stream'
self.title = title or u''
if stream is not None:
if mimetype is USE_MAGIC:
hint = USE_MAGIC
else:
hint = None
self.upload(stream, mimetype_hint=hint)