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


Python _pyio.BytesIO方法代码示例

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


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

示例1: test_getbuffer

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_getbuffer(self):
        memio = self.ioclass(b"1234567890")
        buf = memio.getbuffer()
        self.assertEqual(bytes(buf), b"1234567890")
        memio.seek(5)
        buf = memio.getbuffer()
        self.assertEqual(bytes(buf), b"1234567890")
        # Trying to change the size of the BytesIO while a buffer is exported
        # raises a BufferError.
        self.assertRaises(BufferError, memio.write, b'x' * 100)
        self.assertRaises(BufferError, memio.truncate)
        self.assertRaises(BufferError, memio.close)
        self.assertFalse(memio.closed)
        # Mutating the buffer updates the BytesIO
        buf[3:6] = b"abc"
        self.assertEqual(bytes(buf), b"123abc7890")
        self.assertEqual(memio.getvalue(), b"123abc7890")
        # After the buffer gets released, we can resize and close the BytesIO
        # again
        del buf
        support.gc_collect()
        memio.truncate()
        memio.close()
        self.assertRaises(ValueError, memio.getbuffer) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_memoryio.py

示例2: test_cancel_chunked_upload

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_cancel_chunked_upload():
    chunk_cleanup_queue = FakeQueue()

    args = dict(base_args)
    args["context"] = StorageContext("nyc", chunk_cleanup_queue, None, None)

    swift = FakeSwiftStorage(**args)
    uuid, metadata = swift.initiate_chunked_upload()

    chunks = [b"this", b"is", b"some", b"chunked", b"data", b""]
    offset = 0
    for chunk in chunks:
        bytes_written, metadata, error = swift.stream_upload_chunk(
            uuid, offset, len(chunk), io.BytesIO(chunk), metadata
        )
        assert error is None
        assert len(chunk) == bytes_written
        offset += len(chunk)

    swift.cancel_chunked_upload(uuid, metadata)

    found = chunk_cleanup_queue.get()
    assert found is not None 
开发者ID:quay,项目名称:quay,代码行数:25,代码来源:test_swift.py

示例3: test_sizeof

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_sizeof(self):
        basesize = support.calcobjsize(b'P2PP2P')
        check = self.check_sizeof
        self.assertEqual(object.__sizeof__(io.BytesIO()), basesize)
        check(io.BytesIO(), basesize )
        check(io.BytesIO(b'a'), basesize + 1 + 1 )
        check(io.BytesIO(b'a' * 1000), basesize + 1000 + 1 ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_memoryio.py

示例4: test_sizeof

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_sizeof(self):
        basesize = support.calcobjsize('P2n2Pn')
        check = self.check_sizeof
        self.assertEqual(object.__sizeof__(io.BytesIO()), basesize)
        check(io.BytesIO(), basesize )
        check(io.BytesIO(b'a' * 1000), basesize + sys.getsizeof(b'a' * 1000))

    # Various tests of copy-on-write behaviour for BytesIO. 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_memoryio.py

示例5: _test_cow_mutation

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def _test_cow_mutation(self, mutation):
        # Common code for all BytesIO copy-on-write mutation tests.
        imm = b' ' * 1024
        old_rc = sys.getrefcount(imm)
        memio = self.ioclass(imm)
        self.assertEqual(sys.getrefcount(imm), old_rc + 1)
        mutation(memio)
        self.assertEqual(sys.getrefcount(imm), old_rc) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_memoryio.py

示例6: test_cow_mutable

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_cow_mutable(self):
        # BytesIO should accept only Bytes for copy-on-write sharing, since
        # arbitrary buffer-exporting objects like bytearray() aren't guaranteed
        # to be immutable.
        ba = bytearray(1024)
        old_rc = sys.getrefcount(ba)
        memio = self.ioclass(ba)
        self.assertEqual(sys.getrefcount(ba), old_rc) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_memoryio.py

示例7: test_sizeof

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_sizeof(self):
        basesize = support.calcobjsize('P2nN2Pn')
        check = self.check_sizeof
        self.assertEqual(object.__sizeof__(io.BytesIO()), basesize)
        check(io.BytesIO(), basesize )
        check(io.BytesIO(b'a'), basesize + 1 + 1 )
        check(io.BytesIO(b'a' * 1000), basesize + 1000 + 1 ) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:9,代码来源:test_memoryio.py

示例8: test_stream_read_write

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_stream_read_write():
    swift = FakeSwiftStorage(**base_args)
    assert not swift.exists("somepath")

    swift.stream_write("somepath", io.BytesIO(b"some content here"))
    assert swift.exists("somepath")
    assert swift.get_content("somepath") == b"some content here"
    assert b"".join([c for c in swift.stream_read("somepath")]) == b"some content here" 
开发者ID:quay,项目名称:quay,代码行数:10,代码来源:test_swift.py

示例9: test_stream_read_write_invalid_checksum

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_stream_read_write_invalid_checksum():
    swift = FakeSwiftStorage(fail_checksum=True, **base_args)
    assert not swift.exists("somepath")

    with pytest.raises(IOError):
        swift.stream_write("somepath", io.BytesIO(b"some content here")) 
开发者ID:quay,项目名称:quay,代码行数:8,代码来源:test_swift.py

示例10: test_chunked_upload

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_chunked_upload(chunks, max_chunk_size, read_until_end):
    swift = FakeSwiftStorage(**base_args)
    uuid, metadata = swift.initiate_chunked_upload()

    offset = 0

    with patch("storage.swift._MAXIMUM_SEGMENT_SIZE", max_chunk_size):
        for chunk in chunks:
            chunk_length = len(chunk) if not read_until_end else -1
            bytes_written, metadata, error = swift.stream_upload_chunk(
                uuid, offset, chunk_length, io.BytesIO(chunk), metadata
            )
            assert error is None
            assert len(chunk) == bytes_written
            offset += len(chunk)

        swift.complete_chunked_upload(uuid, "somepath", metadata)
        assert swift.get_content("somepath") == b"".join(chunks)

        # Ensure each of the segments exist.
        for segment in metadata["segments"]:
            assert swift.exists(segment.path)

        # Delete the file and ensure all of its segments were removed.
        swift.remove("somepath")
        assert not swift.exists("somepath")

        for segment in metadata["segments"]:
            assert not swift.exists(segment.path) 
开发者ID:quay,项目名称:quay,代码行数:31,代码来源:test_swift.py

示例11: test_empty_chunks_queued_for_deletion

# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BytesIO [as 别名]
def test_empty_chunks_queued_for_deletion():
    chunk_cleanup_queue = FakeQueue()
    args = dict(base_args)
    args["context"] = StorageContext("nyc", chunk_cleanup_queue, None, None)

    swift = FakeSwiftStorage(**args)
    uuid, metadata = swift.initiate_chunked_upload()

    chunks = [b"this", b"", b"is", b"some", b"", b"chunked", b"data", b""]
    offset = 0
    for chunk in chunks:
        length = len(chunk)
        if length == 0:
            length = 1

        bytes_written, metadata, error = swift.stream_upload_chunk(
            uuid, offset, length, io.BytesIO(chunk), metadata
        )
        assert error is None
        assert len(chunk) == bytes_written
        offset += len(chunk)

    swift.complete_chunked_upload(uuid, "somepath", metadata)
    assert b"".join(chunks) == swift.get_content("somepath")

    # Check the chunk deletion queue and ensure we have the last chunk queued.
    found = chunk_cleanup_queue.get()
    assert found is not None

    found2 = chunk_cleanup_queue.get()
    assert found2 is None 
开发者ID:quay,项目名称:quay,代码行数:33,代码来源:test_swift.py


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