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


Python ChunkObject.read方法代码示例

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


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

示例1: CloudFilesFD

# 需要导入模块: from chunkobject import ChunkObject [as 别名]
# 或者: from chunkobject.ChunkObject import read [as 别名]
class CloudFilesFD(object):
    """Acts like a file() object, but attached to a cloud files object"""

    def __init__(self, cffs, container, obj, mode):
        self.cffs = cffs
        self.container = container
        self.name = obj
        self.mode = mode
        self.closed = False
        self.total_size = 0

        if not all([container, obj]):
            self.closed = True
            raise IOSError(EPERM, "Container and object requred")

        self.container = self.cffs._get_container(self.container)

        if "r" in self.mode:
            self.obj = self.container.get_object(self.name)
            logging.debug("read fd obj.name=%r obj.size=%r" % (self.obj.name, self.obj.size))
        else:  # write
            self.obj = ChunkObject(self.container, obj)
            self.obj.content_type = mimetypes.guess_type(obj)[0]
            self.obj.prepare_chunk()

    def write(self, data):
        """Write data to the object"""
        if "r" in self.mode:
            raise IOSError(EPERM, "Can't write to stream opened for read")
        self.obj.send_chunk(data)

    def close(self):
        """Close the object and finish the data transfer"""
        if "r" in self.mode:
            return
        self.obj.finish_chunk()

    def read(self, size=65536):
        """Read data from the object"""
        logging.debug("read size=%r, total_size=%r, obj.size=%r" % (size, self.total_size, self.obj.size))
        readsize = size
        if (self.total_size + size) > self.obj.size:
            readsize = self.obj.size - self.total_size
        if self.total_size >= self.obj.size:
            return ""
        else:
            offset = self.total_size
            self.total_size += size
            return self.obj.read(size=readsize, offset=offset)

    def seek(self, *kargs, **kwargs):
        """Seek in the object: FIXME doesn't work and raises an error"""
        logging.debug("seek args=%s, kargs=%s" % (str(kargs), str(kwargs)))
        raise IOSError(EPERM, "Seek not implemented")
开发者ID:noodley,项目名称:ftp-cloudfs,代码行数:56,代码来源:fs.py


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