Пример #1
0
 def buffer_callback(buffer: PickleBuffer) -> None:
     value = buffer.raw()
     offset = self.__offset
     length = len(value)
     if offset + length > self.block.size:
         raise ValueTooLarge(
             f"value exceeds available space in block, {length} bytes needed but {self.block.size - offset} bytes free"
         )
     self.block.buf[offset:offset + length] = value
     self.__offset += length
     buffers.append((offset, length))
Пример #2
0
 def test_raw_released(self):
     pb = PickleBuffer(b"foo")
     pb.release()
     with self.assertRaises(ValueError) as raises:
         pb.raw()
Пример #3
0
 def check_raw_non_contiguous(self, obj):
     pb = PickleBuffer(obj)
     with self.assertRaisesRegex(BufferError, "non-contiguous"):
         pb.raw()
Пример #4
0
 def check_raw(self, obj, equiv):
     pb = PickleBuffer(obj)
     with pb.raw() as m:
         self.assertIsInstance(m, memoryview)
         self.check_memoryview(m, equiv)