コード例 #1
0
ファイル: test_list.py プロジェクト: william-ml-leslie/capnpy
def test_list_comparisons():
    buf1 = (
        '\x01\x00\x00\x00\x00\x00\x00\x00'  # 1
        '\x02\x00\x00\x00\x00\x00\x00\x00'  # 2
        '\x03\x00\x00\x00\x00\x00\x00\x00'  # 3
        '\x04\x00\x00\x00\x00\x00\x00\x00')  # 4
    buf2 = 'garbage0' + buf1
    #
    lst1 = List.from_buffer(buf1, 0, ptr.LIST_SIZE_64, 4,
                            PrimitiveItemType(Types.int64))
    lst2 = List.from_buffer(buf2, 8, ptr.LIST_SIZE_64, 4,
                            PrimitiveItemType(Types.int64))
    lst3 = List.from_buffer(buf1, 0, ptr.LIST_SIZE_64, 3,
                            PrimitiveItemType(Types.int64))
    #
    assert lst1 == lst2
    assert not lst1 != lst2
    #
    assert not lst1 == lst3  # different item_count
    assert lst1 != lst3
    #
    py.test.raises(TypeError, "lst1 <  lst2")
    py.test.raises(TypeError, "lst1 <= lst2")
    py.test.raises(TypeError, "lst1 >  lst2")
    py.test.raises(TypeError, "lst1 >= lst2")
コード例 #2
0
 def _read_list(self, offset, item_type, default_=None):
     p = self._read_fast_ptr(offset)
     if ptr.kind(p) == ptr.FAR:
         offset, p = self._read_far_ptr(offset)
     else:
         offset += self._ptrs_offset
     if p == 0:
         return default_
     assert ptr.kind(p) == ptr.LIST
     list_offset = ptr.deref(p, offset)
     # in theory we could simply use List.from_buffer; however, Cython is
     # not able to compile classmethods, so we create it manually
     obj = List.__new__(List)
     obj._init_from_buffer(self._seg, list_offset, ptr.list_size_tag(p),
                           ptr.list_item_count(p), item_type)
     return obj
コード例 #3
0
 def get_handlers(self):
     res = self.handlers
     if res is None:
         return _List.from_buffer(b'', 0, 0, 0, _TextItemType(_Types.text))
     return res