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


Python io.SEEK_SET属性代码示例

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


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

示例1: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset: int, whence: int = io.SEEK_SET) -> int:
        self._check_open()
        self._check_random()
        if whence == io.SEEK_SET:
            ok = self.dev.seek(offset)
        elif whence == io.SEEK_CUR:
            ok = self.dev.seek(self.tell() + offset)
        elif whence == io.SEEK_END:
            ok = self.dev.seek(len(self) + offset)
        else:
            raise io.UnsupportedOperation("whence = {} is not "
                                          "supported!".format(whence))
        if not ok:
            raise QtOSError(self.dev, msg="seek failed!")

        return self.dev.pos() 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:18,代码来源:qtutils.py

示例2: annotation_stream

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def annotation_stream(self, with_checksum=False):
        # create a large temporary file
        f = tempfile.TemporaryFile()
        for _ in range(5000):
            f.write(b"1234567890!" * 1000)
        filesize = f.tell()
        f.seek(os.SEEK_SET, 0)
        # return the file data via annotation stream (remote iterator)
        annotation_size = 500000
        print("transmitting file via annotations stream (%d bytes in chunks of %d)..." % (filesize, annotation_size))
        with f:
            while True:
                chunk = f.read(annotation_size)
                if not chunk:
                    break
                # store the file data chunk in the FDAT response annotation,
                # and return the current file position and checksum (if asked).
                current_context.response_annotations = {"FDAT": chunk}
                yield f.tell(), zlib.crc32(chunk) if with_checksum else 0 
开发者ID:irmen,项目名称:Pyro5,代码行数:21,代码来源:server.py

示例3: get_shared_library_arch

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def get_shared_library_arch(filename):
    with io.open(filename, 'rb') as fp:
        dos_headers = fp.read(64)
        fp.read(4)

        magic, skip, offset = _struct_unpack(str('2s58sl'), dos_headers)

        if magic != b'MZ':
            raise Exception('Not an executable')

        fp.seek(offset, io.SEEK_SET)
        pe_header = fp.read(6)

        sig, skip, machine = _struct_unpack(str('2s2sH'), pe_header)

        if sig != b'PE':
            raise Exception('Not a PE executable')

        return machine_types.get(machine, 'UNKNOWN') 
开发者ID:MatthieuDartiailh,项目名称:pyclibrary,代码行数:21,代码来源:utils.py

示例4: test_no_clips

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def test_no_clips(self):
        data = json.loads("""
{
  "clips": []
}       
        """)
        # Load from JSON
        clips = AnimClips.from_dict(data)
        self.assertEqual(len(clips.clips), 0)

        # Save to FB
        f = io.BytesIO()
        clips.to_fb_stream(f)
        f.seek(0, io.SEEK_SET)

        # Load from FB
        clips = clips.from_fb_stream(f)
        self.assertEqual(len(clips.clips), 0)

        # Save to JSON
        data2 = clips.to_dict()
        self.assertEqual(data, data2) 
开发者ID:zayfod,项目名称:pycozmo,代码行数:24,代码来源:test_anim_encoder.py

示例5: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset, whence=io.SEEK_SET):
        if whence == io.SEEK_CUR:
            offset = self.tell() + offset
        elif whence == io.SEEK_END:
            offset = self.dir.byte_size + offset
        if offset < 0:
            raise ValueError('New position is before the start of the stream')

        if offset > self.dir.byte_size:
            # logging.debug("overseek %d bytes, padding with zeros" % (offset - self.dir.byte_size))
            self.pos = self.dir.byte_size
            bytes_left = offset - self.dir.byte_size
            min_seek_size = self.storage.sector_size * 4
            while bytes_left:
                bytes_to_write = min(min_seek_size, offset - self.dir.byte_size)
                zeros = bytearray(bytes_to_write)
                self.write(zeros)
                bytes_left -= bytes_to_write

        self.pos = offset
        return offset 
开发者ID:markreidvfx,项目名称:pyaaf2,代码行数:23,代码来源:cfb.py

示例6: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset, mode=io.SEEK_SET):
        """
        Move file pointer.

        :param offset: Offset in bytes.
        :param mode: Starting position. Use 0 for beginning of region, 1
           for current offset, and 2 for end of region.  You cannot move
           the pointer outside the defined region.
        """
        if mode == 1:
            self.pos = self.pos + offset
        elif mode == 2:
            self.pos = self.length + offset
        else:
            self.pos = offset
        # clamp
        self.pos = max(0, min(self.pos, self.length))
        self.fh.seek(self.offset + self.pos) 
开发者ID:tp4a,项目名称:teleport,代码行数:20,代码来源:ContainerIO.py

示例7: setup

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def setup(self):
        # Reset everything.
        self.f.seek(self.beginning, os.SEEK_SET)

        self.whereToWriteNewIFDOffset = None
        self.offsetOfNewPage = 0

        self.IIMM = IIMM = self.f.read(4)
        if not IIMM:
            # empty file - first page
            self.isFirst = True
            return

        self.isFirst = False
        if IIMM == b"II\x2a\x00":
            self.setEndian("<")
        elif IIMM == b"MM\x00\x2a":
            self.setEndian(">")
        else:
            raise RuntimeError("Invalid TIFF file header")

        self.skipIFDs()
        self.goToEnd() 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:TiffImagePlugin.py

示例8: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset, whence=io.SEEK_SET):
        """Change the file position.

        The new position is specified by offset, relative to the
        position indicated by whence. Values for whence are:

            0: start of stream (default); offset must not be negative
            1: current stream position
            2: end of stream; offset must not be positive

        Returns the new file position.

        Note that seeking is emulated, so depending on the parameters,
        this operation may be extremely slow.
        """
        with self._lock:
            self._check_can_seek()
            return self._buffer.seek(offset, whence) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:bz2.py

示例9: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset, whence=io.SEEK_SET):
        """Change the file position.

        The new position is specified by offset, relative to the
        position indicated by whence. Possible values for whence are:

            0: start of stream (default): offset must not be negative
            1: current stream position
            2: end of stream; offset must not be positive

        Returns the new file position.

        Note that seeking is emulated, so depending on the parameters,
        this operation may be extremely slow.
        """
        self._check_can_seek()
        return self._buffer.seek(offset, whence) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:lzma.py

示例10: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset, whence=io.SEEK_SET):
        if self.mode == WRITE:
            if whence != io.SEEK_SET:
                if whence == io.SEEK_CUR:
                    offset = self.offset + offset
                else:
                    raise ValueError('Seek from end not supported')
            if offset < self.offset:
                raise OSError('Negative seek in write mode')
            count = offset - self.offset
            chunk = bytes(1024)
            for i in range(count // 1024):
                self.write(chunk)
            self.write(bytes(count % 1024))
        elif self.mode == READ:
            self._check_not_closed()
            return self._buffer.seek(offset, whence)

        return self.offset 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:gzip.py

示例11: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset, whence=io.SEEK_SET):
        if self.mode == WRITE:
            if whence != io.SEEK_SET:
                if whence == io.SEEK_CUR:
                    offset = self.offset + offset
                else:
                    raise ValueError('Seek from end not supported')
            if offset < self.offset:
                raise OSError('Negative seek in write mode')
            count = offset - self.offset
            chunk = b'\0' * 1024
            for i in range(count // 1024):
                self.write(chunk)
            self.write(b'\0' * (count % 1024))
        elif self.mode == READ:
            self._check_not_closed()
            return self._buffer.seek(offset, whence)

        return self.offset 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:21,代码来源:gzip.py

示例12: testSliceFileStartEnd

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def testSliceFileStartEnd(self):
        with tempfile.TemporaryFile() as f:
            f.write(b'123456789')
            f.flush()
            part = FileSlice(f, 0, 5)
            self.assertEqual(len(part), 5)
            self.assertEqual(part.read(), b'12345')
            self.assertEqual(part.read(3), b'')
            part.seek(0, io.SEEK_SET)
            self.assertEqual(part.read(3), b'123')
            self.assertEqual(part.tell(), 3)
            part.seek(-3, io.SEEK_CUR)
            self.assertEqual(part.tell(), 0)
            part.seek(-2, io.SEEK_END)
            self.assertEqual(part.tell(), 3)
            self.assertEqual(part.readall(), b'45')
            with self.assertRaises(IOError):
                part.write('abc')
            with self.assertRaises(IOError):
                part.writelines(['foo', 'bar']) 
开发者ID:OneDrive,项目名称:onedrive-sdk-python,代码行数:22,代码来源:test_file_slice.py

示例13: testSanityChecks

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def testSanityChecks(self):
        with tempfile.TemporaryFile() as f:
            f.write(b'123456789')
            f.flush()
            with self.assertRaises(ValueError):
                part = FileSlice(f, -5, -2)
            with self.assertRaises(ValueError):
                part = FileSlice(f, 0, -2)
            with self.assertRaises(ValueError):
                part = FileSlice(f, -10, 2)
            with self.assertRaises(ValueError):
                part = FileSlice(f, 10, 2)
            with self.assertRaises(ValueError):
                part = FileSlice(f, 10, length=-2)

            part = FileSlice(f, 1, 5)
            with self.assertRaises(ValueError):
                part.seek(8)
            with self.assertRaises(ValueError):
                part.seek(8, io.SEEK_SET)
            part.seek(3)
            with self.assertRaises(ValueError):
                part.seek(4, io.SEEK_CUR)
            with self.assertRaises(ValueError):
                part.seek(-5, io.SEEK_END) 
开发者ID:OneDrive,项目名称:onedrive-sdk-python,代码行数:27,代码来源:test_file_slice.py

示例14: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset, whence=io.SEEK_SET):
        if whence == io.SEEK_SET:
            desired_pos = self._start + offset
        if whence == io.SEEK_CUR:
            desired_pos = self._handle.tell() + offset
        if whence == io.SEEK_END:
            desired_pos = self._end + offset

        if desired_pos < self._start:
            raise ValueError("Seeking before the file slice")
        if desired_pos > self._end:
            raise ValueError("Seekeing past the end of file slice")

        ret = self._handle.seek(desired_pos, io.SEEK_SET)
        if ret:
            return ret - self._start
        else:
            return ret 
开发者ID:OneDrive,项目名称:onedrive-sdk-python,代码行数:20,代码来源:file_slice.py

示例15: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_SET [as 别名]
def seek(self, offset, whence=io.SEEK_SET):
        if whence == io.SEEK_CUR:
            self.offset += offset
        elif whence == io.SEEK_END:
            self.offset = self.cumsizes[-1] + offset
        elif whence == io.SEEK_SET:
            self.offset = offset

        if self.offset < 0:
            raise Exception("Trying to seek before the start of the file!")
        if self.offset >= self.cumsizes[-1]:
            return self.offset

        i = self._findStencil( self.offset )
        offsetInsideStencil = self.offset - self.cumsizes[i]
        assert offsetInsideStencil >= 0
        assert offsetInsideStencil < self.sizes[i]
        self.fileobj.seek( self.offsets[i] + offsetInsideStencil, io.SEEK_SET )

        return self.offset 
开发者ID:mxmlnkn,项目名称:ratarmount,代码行数:22,代码来源:ratarmount.py


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