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


Python io.SEEK_END属性代码示例

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


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

示例1: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [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: test_readinto_partial_back_to_front

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def test_readinto_partial_back_to_front(self, name, BQM, version):

        bqm = BQM(np.triu(np.arange(25).reshape((5, 5))), 'BINARY')
        bqm.offset = 14

        fv = FileView(bqm, version=version)

        buff = fv.readall()

        for pos in range(1, fv.quadratic_end):
            fv.seek(-pos, io.SEEK_END)

            subbuff = bytearray(pos)  # length pos

            self.assertEqual(fv.readinto(subbuff), len(subbuff))
            self.assertEqual(buff[-pos:], subbuff) 
开发者ID:dwavesystems,项目名称:dimod,代码行数:18,代码来源:test_serialization_fileview.py

示例3: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [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

示例4: _find_offset

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def _find_offset(self, fp):

        s = fp.read(160)

        if s[:4] == b"%!PS":
            # for HEAD without binary preview
            fp.seek(0, io.SEEK_END)
            length = fp.tell()
            offset = 0
        elif i32(s[0:4]) == 0xC6D3D0C5:
            # FIX for: Some EPS file not handled correctly / issue #302
            # EPS can contain binary data
            # or start directly with latin coding
            # more info see:
            # https://web.archive.org/web/20160528181353/http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
            offset = i32(s[4:8])
            length = i32(s[8:12])
        else:
            raise SyntaxError("not an EPS file")

        return (length, offset) 
开发者ID:tp4a,项目名称:teleport,代码行数:23,代码来源:EpsImagePlugin.py

示例5: __init__

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def __init__(self, fp, decomp_factory, trailing_error=(), **decomp_args):
        self._fp = fp
        self._eof = False
        self._pos = 0  # Current offset in decompressed stream

        # Set to size of decompressed stream once it is known, for SEEK_END
        self._size = -1

        # Save the decompressor factory and arguments.
        # If the file contains multiple compressed streams, each
        # stream will need a separate decompressor object. A new decompressor
        # object is also needed when implementing a backwards seek().
        self._decomp_factory = decomp_factory
        self._decomp_args = decomp_args
        self._decompressor = self._decomp_factory(**self._decomp_args)

        # Exception class to catch from decompressor signifying invalid
        # trailing data to ignore
        self._trailing_error = trailing_error 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:_compression.py

示例6: test_seek_and_read

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def test_seek_and_read(self):

        def mkfile(basename, content):
            part = os.path.join(self.tmpdir.name, basename)
            with fopen(part, 'wb') as f:
                f.write(content)
            return part

        content = b'abc\nd\nefgh\nij'
        part1 = mkfile('1', content[:4])
        part2 = mkfile('2', content[4:5])
        part3 = mkfile('3', content[5:])

        with MultiFileReader(part1, part2, part3) as m:
            self.assertEqual(m.size, len(content))
            m.seek(2)
            self.assertEqual(m.read(2), content[2:4])
            m.seek(1)
            self.assertEqual(m.read(len(content) - 2), content[1:-1])
            m.seek(-1, whence=io.SEEK_END)
            self.assertEqual(m.read(10), content[-1:])

            m.seek(4)
            m.seek(-2, whence=io.SEEK_CUR)
            self.assertEqual(m.read(3), content[2:5]) 
开发者ID:itkach,项目名称:slob,代码行数:27,代码来源:slob.py

示例7: find_camera_model

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def find_camera_model(videos_folder):
    from mapillary_tools.uploader import get_video_file_list

    file_list = get_video_file_list(videos_folder)

    fd = open(file_list[0], 'rb')

    fd.seek(0, io.SEEK_END)
    eof = fd.tell()
    fd.seek(0)
    while fd.tell() < eof:
        try:
            box = Box.parse_stream(fd)
        except RangeError:
            print('error parsing blackvue GPS information, exiting')
            sys.exit(1)
        except ConstError:
            print('error parsing blackvue GPS information, exiting')
            sys.exit(1)

        if box.type.decode('utf-8') == 'free':# or 'ftyp':     
            return box.data[29:39] 
开发者ID:mapillary,项目名称:mapillary_tools,代码行数:24,代码来源:prepare_blackvue_videos.py

示例8: _add_payloads

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def _add_payloads(self):
        """
        Adds all the stored payload to artifact.
        Each payload is itself a compressed tar.
        """
        filenames = sorted(list(self._payloads.keys()))
        for filename in filenames:
            fd = self._payloads[filename]

            size = fd.seek(0, io.SEEK_END)
            fd.seek(0)

            payload_tarbin = io.BytesIO()
            payload_tar = tarfile.open(fileobj=payload_tarbin, mode="w:gz")
            tarhdr = tarfile.TarInfo(os.path.basename(filename))
            tarhdr.size = size
            payload_tar.addfile(tarhdr, fd)
            payload_tar.close()

            tarhdr = tarfile.TarInfo(os.path.dirname(filename) + ".tar.gz")
            tarhdr.size = payload_tarbin.tell()
            self._compute_checksum(filename, fd)
            payload_tarbin.seek(0)
            self._tarfact.addfile(tarhdr, payload_tarbin) 
开发者ID:mendersoftware,项目名称:integration,代码行数:26,代码来源:artifact.py

示例9: _detect_size

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def _detect_size(self):
        uncompressed_size = 0
        if self.path.endswith(".gz"):
            # This logic follow after the C# implementation
            # See IngstionHelpers.cs for an explanation as to what stands behind it
            with open(self.path, "rb") as f:
                disk_size = f.seek(-4, SEEK_END)
                uncompressed_size = struct.unpack("I", f.read(4))[0]
                if (disk_size >= uncompressed_size) or (disk_size >= self.GZIP_MAX_DISK_SIZE_FOR_DETECTION):
                    uncompressed_size = disk_size * self.DEFAULT_COMPRESSION_RATIO

        elif self.path.endswith(".zip"):
            with ZipFile(self.path) as zip_archive:
                for f in zip_archive.infolist():
                    uncompressed_size += f.file_size

        else:
            uncompressed_size = os.path.getsize(self.path)

        self._size = uncompressed_size 
开发者ID:Azure,项目名称:azure-kusto-python,代码行数:22,代码来源:descriptors.py

示例10: testSliceFileStartEnd

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [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

示例11: testSanityChecks

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [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

示例12: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [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

示例13: __init__

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def __init__(self, filename: str, tree_conf: TreeConf,
                 cache_size: int=512):
        self._filename = filename
        self._tree_conf = tree_conf
        self._lock = rwlock.RWLock()

        if cache_size == 0:
            self._cache = FakeCache()
        else:
            self._cache = cachetools.LRUCache(maxsize=cache_size)

        self._fd, self._dir_fd = open_file_in_dir(filename)

        self._wal = WAL(filename, tree_conf.page_size)
        if self._wal.needs_recovery:
            self.perform_checkpoint(reopen_wal=True)

        # Get the next available page
        self._fd.seek(0, io.SEEK_END)
        last_byte = self._fd.tell()
        self.last_page = int(last_byte / self._tree_conf.page_size)
        self._freelist_start_page = 0

        # Todo: Remove this, it should only be in Tree
        self._root_node_page = 0 
开发者ID:NicolasLM,项目名称:bplustree,代码行数:27,代码来源:memory.py

示例14: _add_frame

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [as 别名]
def _add_frame(self, frame_type: FrameType, page: Optional[int]=None,
                   page_data: Optional[bytes]=None):
        if frame_type is FrameType.PAGE and (not page or not page_data):
            raise ValueError('PAGE frame without page data')
        if page_data and len(page_data) != self._page_size:
            raise ValueError('Page data is different from page size')
        if not page:
            page = 0
        if frame_type is not FrameType.PAGE:
            page_data = b''
        data = (
            frame_type.value.to_bytes(FRAME_TYPE_BYTES, ENDIAN) +
            page.to_bytes(PAGE_REFERENCE_BYTES, ENDIAN) +
            page_data
        )
        self._fd.seek(0, io.SEEK_END)
        write_to_file(self._fd, self._dir_fd, data,
                      fsync=frame_type != FrameType.PAGE)
        self._index_frame(frame_type, page, self._fd.tell() - self._page_size) 
开发者ID:NicolasLM,项目名称:bplustree,代码行数:21,代码来源:memory.py

示例15: seek

# 需要导入模块: import io [as 别名]
# 或者: from io import SEEK_END [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_END属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。