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


Python Blob.open方法代码示例

本文整理汇总了Python中ZODB.blob.Blob.open方法的典型用法代码示例。如果您正苦于以下问题:Python Blob.open方法的具体用法?Python Blob.open怎么用?Python Blob.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZODB.blob.Blob的用法示例。


在下文中一共展示了Blob.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: NamedBlobFile

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
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,代码行数:58,代码来源:file.py

示例2: crop_factory

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
 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,代码行数:9,代码来源:utils.py

示例3: _deserialize

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
 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,代码行数:9,代码来源:mjson.py

示例4: Tutorial

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
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,代码行数:29,代码来源:models.py

示例5: __call__

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
 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,代码行数:9,代码来源:testing.py

示例6: File

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
class File(BaseContent):

    meta_type = 'File'
    label = 'File'
    admin_view_path = '@@info'
    file = '' # FIXME: temporary while we fix the edit form

    add_form = FileAddForm
    edit_form = FileEditForm

    def __init__(self):
        BaseContent.__init__(self)
        self.blob = Blob()

    def upload(self, mimetype, filename, stream):
        self.mimetype = mimetype
        self.filename = filename
        f = self.blob.open('w')
        size = upload_stream(stream, f)
        f.close()
        self.size = size

    def get_icon(self, request):
        """Return icon and alernate text that correspond to the MIME
        type of the file.
        """
        label, icon = ICONS.get(self.mimetype, ('Unknown', 'mime_unknown.png'))
        icon = request.static_url('petrel:static/img/%s' % icon)
        return icon, label
开发者ID:dbaty,项目名称:Petrel,代码行数:31,代码来源:file.py

示例7: saveFileToBlob

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
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,代码行数:10,代码来源:convert.py

示例8: _store_resized_image

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
 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,代码行数:10,代码来源:image.py

示例9: CommunityFile

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
class CommunityFile(Persistent):
    implements(ICommunityFile)
    modified_by = None  # Sorry, persistence
    is_image = False    # Sorry, persistence

    def __init__(self, title, stream, mimetype, filename, creator=u''):
        self.title = unicode(title)
        self.mimetype = mimetype
        self.filename = filename
        self.creator = unicode(creator)
        self.modified_by = self.creator
        self.blobfile = Blob()
        self.upload(stream)
        self._init_image()

    def _init_image(self):
        if not self.mimetype.startswith('image'):
            return

        try:
            image = PIL.Image.open(self.blobfile.open())
        except IOError:
            return

        self._thumbs = OOBTree()
        self.image_size = image.size
        self.is_image = True
        alsoProvides(self, IImage)

    def image(self):
        assert self.is_image, "Not an image."
        return PIL.Image.open(self.blobfile.open())

    def thumbnail(self, size):
        assert self.is_image, "Not an image."
        key = '%dx%d' % size
        thumbnail = self._thumbs.get(key, None)
        if thumbnail is None:
            self._thumbs[key] = thumbnail = Thumbnail(self.image(), size)
        return thumbnail

    def upload(self, stream):
        f = self.blobfile.open('w')
        size = upload_stream(stream, f)
        f.close()
        self.size = size
开发者ID:boothead,项目名称:karl,代码行数:48,代码来源:files.py

示例10: __call__

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
 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,代码行数:10,代码来源:testing.py

示例11: __init__

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
    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,代码行数:11,代码来源:content.py

示例12: addfile

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
 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,代码行数:11,代码来源:zodbtest.py

示例13: testBlobbableOFSFileWithoutFileName

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
 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,代码行数:11,代码来源:test_adapters.py

示例14: testBlobbableOFSImage

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
 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,代码行数:12,代码来源:test_adapters.py

示例15: File

# 需要导入模块: from ZODB.blob import Blob [as 别名]
# 或者: from ZODB.blob.Blob import open [as 别名]
class File(Persistent):

    # prevent view tab from sorting first (it would display the file when
    # manage_main clicked)
    __tab_order__ = ('properties', 'acl_edit', 'view')

    __propschema__ = fileschema

    def __init__(self, stream, mimetype='application/octet-stream'):
        self.mimetype = mimetype
        self.blob = Blob()
        self.upload(stream)
           
    def get_properties(self):
        filedata = dict(
            fp=None,
            uid=str(self.__objectid__),
            filename=self.__name__,
            )
        return dict(
            name=self.__name__,
            file=filedata,
            mimetype=self.mimetype
            )

    def set_properties(self, struct):
        newname = struct['name']
        file = struct['file']
        mimetype = struct['mimetype']
        if file and file.get('fp'):
            fp = file['fp']
            fp.seek(0)
            self.upload(fp)
            filename = file['filename']
            mimetype = mimetypes.guess_type(filename, strict=False)[0]
            if not newname:
                newname = filename
        if not mimetype:
            mimetype = 'application/octet-stream'
        self.mimetype = mimetype
        oldname = self.__name__
        if newname and newname != oldname:
            self.__parent__.rename(oldname, newname)
        
    def upload(self, stream):
        if not stream:
            stream = StringIO.StringIO()
        fp = self.blob.open('w')
        size = 0
        for chunk in chunks(stream):
            size += len(chunk)        
            fp.write(chunk)
        fp.close()
        self.size = size
开发者ID:ericrasmussen,项目名称:substanced,代码行数:56,代码来源:resources.py


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