当前位置: 首页>>代码示例>>Python>>正文


Python blob.Blob类代码示例

本文整理汇总了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
开发者ID:collective,项目名称:wildcard.migrator,代码行数:7,代码来源:mjson.py

示例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)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:7,代码来源:testing.py

示例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
开发者ID:hersonrodrigues,项目名称:plone.app.imagecropping,代码行数:7,代码来源:utils.py

示例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
开发者ID:wyldebeast-wunderliebe,项目名称:w20e.pycms,代码行数:8,代码来源:image.py

示例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)
开发者ID:pigaov10,项目名称:plone4.3,代码行数:8,代码来源:testing.py

示例6: saveFileToBlob

def saveFileToBlob(filepath):
    blob = Blob()
    fi = open(filepath)
    bfile = blob.open('w')
    bfile.write(fi.read())
    bfile.close()
    fi.close()
    return blob
开发者ID:collective,项目名称:collective.documentviewer,代码行数:8,代码来源:convert.py

示例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
开发者ID:shambo001,项目名称:peat,代码行数:9,代码来源:zodbtest.py

示例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')
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:9,代码来源:test_adapters.py

示例9: __init__

    def __init__(self, mimetype, fd):
        self.mimetype = mimetype

        blob = Blob()
        blobfd = blob.open('w')
        copyfileobj(fd, blobfd)
        blobfd.close()

        self.data = blob
开发者ID:chrisrossi,项目名称:surebro,代码行数:9,代码来源:content.py

示例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
开发者ID:pigaov10,项目名称:plone4.3,代码行数:56,代码来源:file.py

示例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')
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:10,代码来源:test_adapters.py

示例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()
开发者ID:lslaz1,项目名称:karl,代码行数:12,代码来源:filestore.py

示例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')
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:12,代码来源:test_adapters.py

示例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        
开发者ID:mcdonc,项目名称:marlton,代码行数:27,代码来源:models.py

示例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)
开发者ID:tseaver,项目名称:substanced,代码行数:35,代码来源:__init__.py


注:本文中的ZODB.blob.Blob类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。