Ejemplo n.º 1
0
def test_from_buffer_large():
    """Test .from_buffer attribute."""
    data = b'\xb8~?./3\x02\x14\xb2\x89\xfc6A\xa4\x02\x05f\xdb\xb1\x04\xc3\x891\xad\x8cW\xcd\xda\x04A'
    assert -72 == c_byte.from_buffer(bytearray(data)).value
    assert 775913144 == c_int.from_buffer(bytearray(data)).value
    assert -72 == c_int8.from_buffer(bytearray(data)).value
    if sys.maxsize > 2**32:  # 64-bit.
        assert 1441771108444372664 == c_long.from_buffer(bytearray(data)).value
    else:
        assert 775913144 == c_long.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_longlong.from_buffer(bytearray(data)).value
    assert 32440 == c_uint16.from_buffer(bytearray(data)).value
    assert 775913144 == c_uint32.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_uint64.from_buffer(bytearray(data)).value
    assert 184 == c_uint8.from_buffer(bytearray(data)).value
    assert 184 == c_ubyte.from_buffer(bytearray(data)).value
    assert 775913144 == c_uint.from_buffer(bytearray(data)).value
    if sys.maxsize > 2**32:  # 64-bit.
        assert 1441771108444372664 == c_ulong.from_buffer(
            bytearray(data)).value
    else:
        assert 775913144 == c_ulong.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_ulonglong.from_buffer(
        bytearray(data)).value
    assert 32440 == c_ushort.from_buffer(bytearray(data)).value
Ejemplo n.º 2
0
def test_maximum():
    """Test maximum valid integer value."""
    assert 127 == c_byte.from_buffer(bytearray(c_byte(127))).value
    assert 2147483647 == c_int.from_buffer(bytearray(c_int(2147483647))).value
    assert 127 == c_int8.from_buffer(bytearray(c_int8(127))).value
    if sys.maxsize > 2**32:  # 64-bit.
        assert 9223372036854775807 == c_long.from_buffer(
            bytearray(c_long(9223372036854775807))).value
    else:
        assert 2147483647 == c_long.from_buffer(bytearray(
            c_long(2147483647))).value
    assert 9223372036854775807 == c_longlong.from_buffer(
        bytearray(c_longlong(9223372036854775807))).value
    assert 65535 == c_uint16.from_buffer(bytearray(c_uint16(65535))).value
    assert 4294967295 == c_uint32.from_buffer(bytearray(
        c_uint32(4294967295))).value
    assert 18446744073709551615 == c_uint64.from_buffer(
        bytearray(c_uint64(18446744073709551615))).value
    assert 255 == c_uint8.from_buffer(bytearray(c_uint8(255))).value
    assert 255 == c_ubyte.from_buffer(bytearray(c_ubyte(255))).value
    assert 4294967295 == c_uint.from_buffer(bytearray(
        c_uint(4294967295))).value
    if sys.maxsize > 2**32:  # 64-bit.
        assert 18446744073709551615 == c_ulong.from_buffer(
            bytearray(c_ulong(18446744073709551615))).value
    else:
        assert 4294967295 == c_ulong.from_buffer(bytearray(
            c_ulong(4294967295))).value
    assert 18446744073709551615 == c_ulonglong.from_buffer(
        bytearray(c_ulonglong(18446744073709551615))).value
    assert 65535 == c_ushort.from_buffer(bytearray(c_ushort(65535))).value
Ejemplo n.º 3
0
Archivo: attr.py Proyecto: 0x90/libnl
def nla_get_u32(nla):
    """Return value of 32 bit integer attribute as an int().

    https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L624

    Positional arguments:
    nla -- 32 bit integer attribute (nlattr class instance).

    Returns:
    Payload as an int().
    """
    return int(c_uint32.from_buffer(nla_data(nla)[:SIZEOF_U32]).value)
Ejemplo n.º 4
0
def nla_get_u32(nla):
    """Return value of 32 bit integer attribute as an int().

    https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L624

    Positional arguments:
    nla -- 32 bit integer attribute (nlattr class instance).

    Returns:
    Payload as an int().
    """
    return int(c_uint32.from_buffer(nla_data(nla)[:SIZEOF_U32]).value)
Ejemplo n.º 5
0
def test_zero():
    """Test zero integer value."""
    assert 0 == c_byte.from_buffer(bytearray(c_byte())).value
    assert 0 == c_int.from_buffer(bytearray(c_int())).value
    assert 0 == c_int8.from_buffer(bytearray(c_int8())).value
    assert 0 == c_long.from_buffer(bytearray(c_long())).value
    assert 0 == c_longlong.from_buffer(bytearray(c_longlong())).value
    assert 0 == c_uint16.from_buffer(bytearray(c_uint16())).value
    assert 0 == c_uint32.from_buffer(bytearray(c_uint32())).value
    assert 0 == c_uint64.from_buffer(bytearray(c_uint64())).value
    assert 0 == c_uint8.from_buffer(bytearray(c_uint8())).value
    assert 0 == c_ubyte.from_buffer(bytearray(c_ubyte())).value
    assert 0 == c_uint.from_buffer(bytearray(c_uint())).value
    assert 0 == c_ulong.from_buffer(bytearray(c_ulong())).value
    assert 0 == c_ulonglong.from_buffer(bytearray(c_ulonglong())).value
    assert 0 == c_ushort.from_buffer(bytearray(c_ushort())).value
Ejemplo n.º 6
0
def test_zero():
    """Test zero integer value."""
    assert 0 == c_byte.from_buffer(bytearray(c_byte())).value
    assert 0 == c_int.from_buffer(bytearray(c_int())).value
    assert 0 == c_int8.from_buffer(bytearray(c_int8())).value
    assert 0 == c_long.from_buffer(bytearray(c_long())).value
    assert 0 == c_longlong.from_buffer(bytearray(c_longlong())).value
    assert 0 == c_uint16.from_buffer(bytearray(c_uint16())).value
    assert 0 == c_uint32.from_buffer(bytearray(c_uint32())).value
    assert 0 == c_uint64.from_buffer(bytearray(c_uint64())).value
    assert 0 == c_uint8.from_buffer(bytearray(c_uint8())).value
    assert 0 == c_ubyte.from_buffer(bytearray(c_ubyte())).value
    assert 0 == c_uint.from_buffer(bytearray(c_uint())).value
    assert 0 == c_ulong.from_buffer(bytearray(c_ulong())).value
    assert 0 == c_ulonglong.from_buffer(bytearray(c_ulonglong())).value
    assert 0 == c_ushort.from_buffer(bytearray(c_ushort())).value
Ejemplo n.º 7
0
def test_middle():
    """Test with arbitrary positive value."""
    assert 123 == c_byte.from_buffer(bytearray(c_byte(123))).value
    assert 1234567890 == c_int.from_buffer(bytearray(c_int(1234567890))).value
    assert 123 == c_int8.from_buffer(bytearray(c_int8(123))).value
    assert 1234567890 == c_long.from_buffer(bytearray(c_long(1234567890))).value
    assert 1234567890123456789 == c_longlong.from_buffer(bytearray(c_longlong(1234567890123456789))).value
    assert 12345 == c_uint16.from_buffer(bytearray(c_uint16(12345))).value
    assert 1234567890 == c_uint32.from_buffer(bytearray(c_uint32(1234567890))).value
    assert 12345678901234567890 == c_uint64.from_buffer(bytearray(c_uint64(12345678901234567890))).value
    assert 123 == c_uint8.from_buffer(bytearray(c_uint8(123))).value
    assert 123 == c_ubyte.from_buffer(bytearray(c_ubyte(123))).value
    assert 1234567890 == c_uint.from_buffer(bytearray(c_uint(1234567890))).value
    assert 1234567890 == c_ulong.from_buffer(bytearray(c_ulong(1234567890))).value
    assert 12345678901234567890 == c_ulonglong.from_buffer(bytearray(c_ulonglong(12345678901234567890))).value
    assert 12345 == c_ushort.from_buffer(bytearray(c_ushort(12345))).value
Ejemplo n.º 8
0
def test_maximum():
    """Test maximum valid integer value."""
    assert 127 == c_byte.from_buffer(bytearray(c_byte(127))).value
    assert 2147483647 == c_int.from_buffer(bytearray(c_int(2147483647))).value
    assert 127 == c_int8.from_buffer(bytearray(c_int8(127))).value
    if sys.maxsize > 2 ** 32:  # 64-bit.
        assert 9223372036854775807 == c_long.from_buffer(bytearray(c_long(9223372036854775807))).value
    else:
        assert 2147483647 == c_long.from_buffer(bytearray(c_long(2147483647))).value
    assert 9223372036854775807 == c_longlong.from_buffer(bytearray(c_longlong(9223372036854775807))).value
    assert 65535 == c_uint16.from_buffer(bytearray(c_uint16(65535))).value
    assert 4294967295 == c_uint32.from_buffer(bytearray(c_uint32(4294967295))).value
    assert 18446744073709551615 == c_uint64.from_buffer(bytearray(c_uint64(18446744073709551615))).value
    assert 255 == c_uint8.from_buffer(bytearray(c_uint8(255))).value
    assert 255 == c_ubyte.from_buffer(bytearray(c_ubyte(255))).value
    assert 4294967295 == c_uint.from_buffer(bytearray(c_uint(4294967295))).value
    if sys.maxsize > 2 ** 32:  # 64-bit.
        assert 18446744073709551615 == c_ulong.from_buffer(bytearray(c_ulong(18446744073709551615))).value
    else:
        assert 4294967295 == c_ulong.from_buffer(bytearray(c_ulong(4294967295))).value
    assert 18446744073709551615 == c_ulonglong.from_buffer(bytearray(c_ulonglong(18446744073709551615))).value
    assert 65535 == c_ushort.from_buffer(bytearray(c_ushort(65535))).value
Ejemplo n.º 9
0
def test_from_buffer_large():
    """Test .from_buffer attribute."""
    data = b'\xb8~?./3\x02\x14\xb2\x89\xfc6A\xa4\x02\x05f\xdb\xb1\x04\xc3\x891\xad\x8cW\xcd\xda\x04A'
    assert -72 == c_byte.from_buffer(bytearray(data)).value
    assert 775913144 == c_int.from_buffer(bytearray(data)).value
    assert -72 == c_int8.from_buffer(bytearray(data)).value
    if sys.maxsize > 2 ** 32:  # 64-bit.
        assert 1441771108444372664 == c_long.from_buffer(bytearray(data)).value
    else:
        assert 775913144 == c_long.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_longlong.from_buffer(bytearray(data)).value
    assert 32440 == c_uint16.from_buffer(bytearray(data)).value
    assert 775913144 == c_uint32.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_uint64.from_buffer(bytearray(data)).value
    assert 184 == c_uint8.from_buffer(bytearray(data)).value
    assert 184 == c_ubyte.from_buffer(bytearray(data)).value
    assert 775913144 == c_uint.from_buffer(bytearray(data)).value
    if sys.maxsize > 2 ** 32:  # 64-bit.
        assert 1441771108444372664 == c_ulong.from_buffer(bytearray(data)).value
    else:
        assert 775913144 == c_ulong.from_buffer(bytearray(data)).value
    assert 1441771108444372664 == c_ulonglong.from_buffer(bytearray(data)).value
    assert 32440 == c_ushort.from_buffer(bytearray(data)).value
Ejemplo n.º 10
0
def test_middle():
    """Test with arbitrary positive value."""
    assert 123 == c_byte.from_buffer(bytearray(c_byte(123))).value
    assert 1234567890 == c_int.from_buffer(bytearray(c_int(1234567890))).value
    assert 123 == c_int8.from_buffer(bytearray(c_int8(123))).value
    assert 1234567890 == c_long.from_buffer(bytearray(
        c_long(1234567890))).value
    assert 1234567890123456789 == c_longlong.from_buffer(
        bytearray(c_longlong(1234567890123456789))).value
    assert 12345 == c_uint16.from_buffer(bytearray(c_uint16(12345))).value
    assert 1234567890 == c_uint32.from_buffer(bytearray(
        c_uint32(1234567890))).value
    assert 12345678901234567890 == c_uint64.from_buffer(
        bytearray(c_uint64(12345678901234567890))).value
    assert 123 == c_uint8.from_buffer(bytearray(c_uint8(123))).value
    assert 123 == c_ubyte.from_buffer(bytearray(c_ubyte(123))).value
    assert 1234567890 == c_uint.from_buffer(bytearray(
        c_uint(1234567890))).value
    assert 1234567890 == c_ulong.from_buffer(bytearray(
        c_ulong(1234567890))).value
    assert 12345678901234567890 == c_ulonglong.from_buffer(
        bytearray(c_ulonglong(12345678901234567890))).value
    assert 12345 == c_ushort.from_buffer(bytearray(c_ushort(12345))).value
Ejemplo n.º 11
0
 def nlmsg_len(self):
     """Length of message including header."""
     return c_uint32.from_buffer(self.bytearray[self._get_slicers(0)]).value
Ejemplo n.º 12
0
Archivo: netlink.py Proyecto: ewa/libnl
 def nlmsg_seq(self):
     """Sequence number."""
     return c_uint32.from_buffer(self.bytearray[self._get_slicers(3)]).value
Ejemplo n.º 13
0
Archivo: netlink.py Proyecto: ewa/libnl
 def nlmsg_len(self):
     """Length of message including header."""
     return c_uint32.from_buffer(self.bytearray[self._get_slicers(0)]).value
Ejemplo n.º 14
0
Archivo: netlink.py Proyecto: ewa/libnl
 def nlmsg_pid(self):
     """Sending process port ID."""
     return c_uint32.from_buffer(self.bytearray[self._get_slicers(4)]).value
Ejemplo n.º 15
0
 def nl_groups(self):
     """Port ID."""
     return c_uint32.from_buffer(self.bytearray[self._get_slicers(3)]).value
Ejemplo n.º 16
0
 def nlmsg_pid(self):
     """Sending process port ID."""
     return c_uint32.from_buffer(self.bytearray[self._get_slicers(4)]).value
Ejemplo n.º 17
0
 def nlmsg_seq(self):
     """Sequence number."""
     return c_uint32.from_buffer(self.bytearray[self._get_slicers(3)]).value
Ejemplo n.º 18
0
Archivo: netlink.py Proyecto: ewa/libnl
 def nl_pid(self):
     """Port ID."""
     return c_uint32.from_buffer(self.bytearray[self._get_slicers(2)]).value