Пример #1
0
 def serialize(self):
     sb = StringBuffer(16 + self.total_size)
     sb.pack('<BBHIQ', self.mfs_type, 0, 0, self.entry_no, self.total_size)
     for symbol in self.symbols:
         sb.write(symbol.serialize())
     sb.seek(0)
     return sb
Пример #2
0
 def serialize(self):
     sb = StringBuffer(16 + self.total_size)
     sb.pack('<BBHHHQ', self.mfs_type, self.ver, self.name_size, self.datatype_size, self.dataspace_size, self.total_size)
     if self.attr is not None:
         sb.write(self.attr.serialize())
     sb.seek(0)
     return sb
Пример #3
0
 def serialize(self):
     sb = StringBuffer(16 + self.total_size)
     sb.pack('<BBHIQ', self.mfs_type, 0, 0, self.entry_no, self.total_size)
     for symbol in self.symbols:
         sb.write(symbol.serialize())
     sb.seek(0)
     return sb
Пример #4
0
 def serialize(self):
     sb = StringBuffer(16 + self.total_size)
     sb.pack('<BBBBIQ', self.mfs_type, self.ver, self.dims, self.flags, 0, self.total_size)
     for ds in self.dataspaces:
         sb.write(ds.serialize())
     sb.seek(0)
     return sb
Пример #5
0
    def serialize(self):
        sb = StringBuffer(24)
        sb.pack('<BBH', self.mfs_type, self.mode, self.flags)
        sb.write(self.sha)
        sb.seek(0)

        return sb
Пример #6
0
 def serialize(self):
     sb = StringBuffer(8 + self.symbol_length)
     sb.pack('<HHI', self.idx, 0,
             max(len(self.symbol) + 1,
                 self.symbol_length))  # Account for null-terminator
     sb.write(self.symbol)
     sb.seek(0)
     return sb
Пример #7
0
 def serialize(self):
     sb = StringBuffer(16 + self.total_size)
     sb.pack('<BBHHHQ', self.mfs_type, self.ver, self.name_size,
             self.datatype_size, self.dataspace_size, self.total_size)
     if self.attr is not None:
         sb.write(self.attr.serialize())
     sb.seek(0)
     return sb
Пример #8
0
 def serialize(self):
     sb = StringBuffer(16 + self.total_size)
     sb.pack('<BBBBIQ', self.mfs_type, self.ver, self.dims, self.flags, 0,
             self.total_size)
     for ds in self.dataspaces:
         sb.write(ds.serialize())
     sb.seek(0)
     return sb
Пример #9
0
 def test_fread(self):
     sb = StringBuffer(16)
     with TemporaryFile('w+b') as f:
         fd = f.fileno()
         f.write('hello world\n')
         f.seek(0)
         sb.fread(fd, 8)
         sb.seek(0)
         self.assertEquals(sb.raw_read(8), 'hello wo')
Пример #10
0
    def test_write_sb(self):
        container = StringBuffer(24)
        el = StringBuffer(16)
        el.set('hello world')

        container.write(el)

        container.seek(0)
        self.assertEquals(container.read(), 'hello world')
Пример #11
0
    def create_datatype(self, dtype_class):
        with TemporaryFile('w+b') as f:
            dtype_h = dtype_class()
            sb = dtype_h.serialize()
            sb.fwrite(f.fileno())
            f.seek(0)

            sb = StringBuffer(16)
            sb.fread(f.fileno())
            sb.seek(0)

            dtype_h = MFSObjectHeader.deserialize(sb)
            self.assertIsInstance(dtype_h, DatatypeHeader)
Пример #12
0
    def test_read_uint(self):
        sb = StringBuffer(16)
        sb.pack('<H', 16)

        sb.seek(0)
        i = sb.read_uint(2)
        self.assertEquals(i, 16)

        self.assertEquals(sb.offset(), 2)
        sb.pack('<Q', 1024)
        sb.seek(2)
        i = sb.read_uint(8)
        self.assertEquals(1024, i)
Пример #13
0
    def create_datatype(self, dtype_class):
        with TemporaryFile('w+b') as f:
            dtype_h = dtype_class()
            sb = dtype_h.serialize()
            sb.fwrite(f.fileno())
            f.seek(0)

            sb = StringBuffer(16)
            sb.fread(f.fileno())
            sb.seek(0)

            dtype_h = MFSObjectHeader.deserialize(sb)
            self.assertIsInstance(dtype_h, DatatypeHeader)
Пример #14
0
    def test_overflow(self):
        sb = StringBuffer(24)
        with self.assertRaises(BufferOverflow):
            sb.write('this string is definitely longer than 24 characters and should raise an error')

        self.assertRaises(OverflowError, sb.seek, -1)

        sb = StringBuffer(8)
        sb.set('01234567')
        sb.seek(0)
        buf = sb.raw_read(8)
        self.assertEquals(buf, '01234567')
        self.assertRaises(BufferOverflow, sb.raw_read, 1)
Пример #15
0
    def header_check(self, f, dtype_h, datatype, flags, size, total_size):
        sb = dtype_h.serialize()
        sb.fwrite(f.fileno())
        f.seek(0)

        sb = StringBuffer(16)
        sb.fread(f.fileno())
        sb.seek(0)

        dtype_h = MFSObjectHeader.deserialize(sb)

        self.assertIsInstance(dtype_h, DatatypeHeader)
        self.assertEquals(dtype_h.datatype, datatype)
        self.assertEquals(dtype_h.flags, flags)
        self.assertEquals(dtype_h.size, size)
        self.assertEquals(dtype_h.total_size, total_size)
Пример #16
0
    def header_check(self, f, dtype_h, datatype, flags, size, total_size):
        sb = dtype_h.serialize()
        sb.fwrite(f.fileno())
        f.seek(0)

        sb = StringBuffer(16)
        sb.fread(f.fileno())
        sb.seek(0)

        dtype_h = MFSObjectHeader.deserialize(sb)

        self.assertIsInstance(dtype_h, DatatypeHeader)
        self.assertEquals(dtype_h.datatype, datatype)
        self.assertEquals(dtype_h.flags, flags)
        self.assertEquals(dtype_h.size, size)
        self.assertEquals(dtype_h.total_size, total_size)
Пример #17
0
    def test_buffer(self):
        sb = StringBuffer(128)
        sb.write('hello world')
        sb.seek(0)
        self.assertEquals(sb.read(), 'hello world')

        self.assertEquals(sb.offset(), 0)
        sb.write('jello')
        self.assertEquals(sb.offset(), 5)
        sb.seek(0)
        self.assertEquals(sb.read(), 'jello world')

        sb.set('hi')
        self.assertEquals(sb.offset(), 0)
        self.assertEquals(sb.read(), 'hi')

        sb = StringBuffer("Hello World")
        self.assertEquals(sb.read(), 'Hello World')

        sb = StringBuffer(sb)
        self.assertEquals(sb.read(), 'Hello World')
Пример #18
0
 def serialize(self):
     sb = StringBuffer(8 + self.symbol_length)
     sb.pack('<HHI', self.idx, 0, max(len(self.symbol)+1, self.symbol_length)) # Account for null-terminator
     sb.write(self.symbol)
     sb.seek(0)
     return sb
Пример #19
0
 def serialize(self):
     sb = StringBuffer(16)
     sb.pack('<BBHIQ', self.mfs_type, self.datatype, self.flags, self.size, self.total_size)
     sb.seek(0)
     return sb
Пример #20
0
 def serialize(self):
     sb = StringBuffer(8)
     sb.pack('<Q', self.dim_size)
     sb.seek(0)
     return sb
Пример #21
0
 def serialize(self):
     sb = StringBuffer(8)
     sb.pack('<Q', self.dim_size)
     sb.seek(0)
     return sb