From fb6256ab17f4837a9ae2f4adc89c2a88c22cf18e Mon Sep 17 00:00:00 2001 From: IWAMOTO Toshihiro Date: Tue, 30 Jun 2015 17:01:55 +0900 Subject: [PATCH] python3: Use b'str' for binary data Signed-off-by: IWAMOTO Toshihiro Signed-off-by: FUJITA Tomonori --- ryu/ofproto/ofproto_v1_3_parser.py | 6 +++--- ryu/ofproto/ofproto_v1_4_parser.py | 6 +++--- ryu/tests/unit/test_utils.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ryu/ofproto/ofproto_v1_3_parser.py b/ryu/ofproto/ofproto_v1_3_parser.py index 62b56a70..85b80298 100644 --- a/ryu/ofproto/ofproto_v1_3_parser.py +++ b/ryu/ofproto/ofproto_v1_3_parser.py @@ -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: diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py index b359f025..b9b873fc 100644 --- a/ryu/ofproto/ofproto_v1_4_parser.py +++ b/ryu/ofproto/ofproto_v1_4_parser.py @@ -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: diff --git a/ryu/tests/unit/test_utils.py b/ryu/tests/unit/test_utils.py index 70843cf4..64886c3c 100644 --- a/ryu/tests/unit/test_utils.py +++ b/ryu/tests/unit/test_utils.py @@ -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):