python3: Use b'str' for binary data

Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
IWAMOTO Toshihiro 2015-06-30 17:01:55 +09:00 committed by FUJITA Tomonori
parent 675f33d664
commit fb6256ab17
3 changed files with 8 additions and 8 deletions

View File

@ -2268,7 +2268,7 @@ class OFPPort(ofproto_parser.namedtuple('OFPPort', (
i = cls._fields.index('hw_addr')
port[i] = addrconv.mac.bin_to_text(port[i])
i = cls._fields.index('name')
port[i] = port[i].rstrip('\0')
port[i] = port[i].rstrip(b'\0')
ofpport = cls(*port)
ofpport.length = ofproto.OFP_PORT_SIZE
return ofpport
@ -3649,7 +3649,7 @@ class OFPDescStats(ofproto_parser.namedtuple('OFPDescStats', (
desc = struct.unpack_from(ofproto.OFP_DESC_PACK_STR,
buf, offset)
desc = list(desc)
desc = [x.rstrip('\0') for x in desc]
desc = [x.rstrip(b'\0') for x in desc]
stats = cls(*desc)
stats.length = ofproto.OFP_DESC_SIZE
return stats
@ -4916,7 +4916,7 @@ class OFPTableFeaturesStats(StringifyMixin):
table_features.max_entries
) = struct.unpack_from(ofproto.OFP_TABLE_FEATURES_PACK_STR,
buf, offset)
table_features.name = name.rstrip('\0')
table_features.name = name.rstrip(b'\0')
props = []
rest = buf[offset + ofproto.OFP_TABLE_FEATURES_SIZE:

View File

@ -1841,7 +1841,7 @@ class OFPPort(StringifyMixin):
(port_no, length, hw_addr, name, config, state) = struct.unpack_from(
ofproto.OFP_PORT_PACK_STR, buf, offset)
hw_addr = addrconv.mac.bin_to_text(hw_addr)
name = name.rstrip('\0')
name = name.rstrip(b'\0')
props = []
rest = buf[offset + ofproto.OFP_PORT_SIZE:offset + length]
while rest:
@ -2101,7 +2101,7 @@ class OFPDescStats(ofproto_parser.namedtuple('OFPDescStats', (
desc = struct.unpack_from(ofproto.OFP_DESC_PACK_STR,
buf, offset)
desc = list(desc)
desc = [x.rstrip('\0') for x in desc]
desc = [x.rstrip(b'\0') for x in desc]
stats = cls(*desc)
stats.length = ofproto.OFP_DESC_SIZE
return stats
@ -2197,7 +2197,7 @@ class OFPTableFeaturesStats(StringifyMixin):
table_features.max_entries
) = struct.unpack_from(ofproto.OFP_TABLE_FEATURES_PACK_STR,
buf, offset)
table_features.name = name.rstrip('\0')
table_features.name = name.rstrip(b'\0')
props = []
rest = buf[offset + ofproto.OFP_TABLE_FEATURES_SIZE:

View File

@ -33,13 +33,13 @@ class Test_utils(unittest.TestCase):
def test_hex_array_string(self):
''' Test string conversion into array of hexes '''
expected_result = '0x1 0x2 0x3 0x4'
data = '\01\02\03\04'
data = b'\01\02\03\04'
eq_(expected_result, utils.hex_array(data))
def test_hex_array_bytearray(self):
''' Test bytearray conversion into array of hexes '''
expected_result = '0x1 0x2 0x3 0x4'
data = bytearray('\01\02\03\04')
data = bytearray(b'\01\02\03\04')
eq_(expected_result, utils.hex_array(data))
def test_hex_array_invalid(self):