diff options
author | IWAMOTO Toshihiro <iwamoto@valinux.co.jp> | 2015-07-03 11:27:11 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-03 11:38:00 +0900 |
commit | 8df05b17d00994738d04391808412e56e9c5d176 (patch) | |
tree | 459508f2adc3f03de6cbf3a123e455f36159599c | |
parent | 0fc3d72ba27b268eeaf7cbfb2ce2ef29761d609a (diff) |
python3: Convert str to six.binary_type
Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/packet/icmpv6.py | 18 | ||||
-rw-r--r-- | ryu/lib/packet/igmp.py | 9 | ||||
-rw-r--r-- | ryu/lib/packet/packet.py | 3 | ||||
-rw-r--r-- | ryu/lib/packet/sctp.py | 30 | ||||
-rw-r--r-- | ryu/lib/packet/tcp.py | 3 | ||||
-rw-r--r-- | ryu/tests/unit/packet/test_ipv6.py | 65 | ||||
-rw-r--r-- | ryu/tests/unit/packet/test_lldp.py | 3 | ||||
-rw-r--r-- | ryu/tests/unit/packet/test_tcp.py | 3 | ||||
-rw-r--r-- | ryu/tests/unit/packet/test_vrrp.py | 13 |
9 files changed, 77 insertions, 70 deletions
diff --git a/ryu/lib/packet/icmpv6.py b/ryu/lib/packet/icmpv6.py index 9b0f2d96..16d55eb1 100644 --- a/ryu/lib/packet/icmpv6.py +++ b/ryu/lib/packet/icmpv6.py @@ -225,7 +225,7 @@ class nd_neighbor(stringify.StringifyMixin): hdr.extend(self.option.serialize()) else: hdr.extend(self.option) - return str(hdr) + return six.binary_type(hdr) def __len__(self): length = self._MIN_LEN @@ -294,7 +294,7 @@ class nd_router_solicit(stringify.StringifyMixin): hdr.extend(self.option.serialize()) else: hdr.extend(self.option) - return str(hdr) + return six.binary_type(hdr) def __len__(self): length = self._MIN_LEN @@ -379,7 +379,7 @@ class nd_router_advert(stringify.StringifyMixin): hdr.extend(option.serialize()) else: hdr.extend(option) - return str(hdr) + return six.binary_type(hdr) def __len__(self): length = self._MIN_LEN @@ -451,7 +451,7 @@ class nd_option_la(nd_option): if 0 == self.length: self.length = len(buf) // 8 struct.pack_into('!B', buf, 1, self.length) - return str(buf) + return six.binary_type(buf) def __len__(self): length = self._MIN_LEN @@ -609,7 +609,7 @@ class nd_option_pi(nd_option): if 0 == self.length: self.length = len(hdr) // 8 struct.pack_into('!B', hdr, 1, self.length) - return str(hdr) + return six.binary_type(hdr) @icmpv6.register_icmpv6_type(ICMPV6_ECHO_REPLY, ICMPV6_ECHO_REQUEST) @@ -790,7 +790,7 @@ class mldv2_query(mld): if 0 == self.num: self.num = len(self.srcs) struct.pack_into('!H', buf, 22, self.num) - return str(buf) + return six.binary_type(buf) def __len__(self): return self._MIN_LEN + len(self.srcs) * 16 @@ -850,7 +850,7 @@ class mldv2_report(mld): if 0 == self.record_num: self.record_num = len(self.records) struct.pack_into('!H', buf, 2, self.record_num) - return str(buf) + return six.binary_type(buf) def __len__(self): records_len = 0 @@ -930,12 +930,12 @@ class mldv2_report_group(stringify.StringifyMixin): mod = len(self.aux) % 4 if mod: self.aux += bytearray(4 - mod) - self.aux = str(self.aux) + self.aux = six.binary_type(self.aux) buf.extend(self.aux) if 0 == self.aux_len: self.aux_len = len(self.aux) // 4 struct.pack_into('!B', buf, 1, self.aux_len) - return str(buf) + return six.binary_type(buf) def __len__(self): return self._MIN_LEN + len(self.srcs) * 16 + self.aux_len * 4 diff --git a/ryu/lib/packet/igmp.py b/ryu/lib/packet/igmp.py index f819fa6c..8392765a 100644 --- a/ryu/lib/packet/igmp.py +++ b/ryu/lib/packet/igmp.py @@ -117,6 +117,7 @@ where each Group Record has the following internal format: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ """ +import six import struct from ryu.lib import addrconv @@ -301,7 +302,7 @@ class igmpv3_query(igmp): if 0 == self.csum: self.csum = packet_utils.checksum(buf) struct.pack_into('!H', buf, 2, self.csum) - return str(buf) + return six.binary_type(buf) def __len__(self): return self._MIN_LEN + len(self.srcs) * 4 @@ -374,7 +375,7 @@ class igmpv3_report(igmp): if 0 == self.csum: self.csum = packet_utils.checksum(buf) struct.pack_into('!H', buf, 2, self.csum) - return str(buf) + return six.binary_type(buf) def __len__(self): records_len = 0 @@ -457,12 +458,12 @@ class igmpv3_report_group(stringify.StringifyMixin): mod = len(self.aux) % 4 if mod: self.aux += bytearray(4 - mod) - self.aux = str(self.aux) + self.aux = six.binary_type(self.aux) buf.extend(self.aux) if 0 == self.aux_len: self.aux_len = len(self.aux) // 4 struct.pack_into('!B', buf, 1, self.aux_len) - return str(buf) + return six.binary_type(buf) def __len__(self): return self._MIN_LEN + len(self.srcs) * 4 + self.aux_len * 4 diff --git a/ryu/lib/packet/packet.py b/ryu/lib/packet/packet.py index e25db3d5..6f420cb6 100644 --- a/ryu/lib/packet/packet.py +++ b/ryu/lib/packet/packet.py @@ -14,6 +14,7 @@ # limitations under the License. import inspect +import six import struct from . import packet_base @@ -72,7 +73,7 @@ class Packet(object): prev = r[i + 1] data = p.serialize(self.data, prev) else: - data = str(p) + data = six.binary_type(p) self.data = data + self.data def add_protocol(self, proto): diff --git a/ryu/lib/packet/sctp.py b/ryu/lib/packet/sctp.py index a59ac680..ff2c46b9 100644 --- a/ryu/lib/packet/sctp.py +++ b/ryu/lib/packet/sctp.py @@ -300,7 +300,7 @@ class chunk_init_base(chunk): if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return six.binary_type(buf) @six.add_metaclass(abc.ABCMeta) @@ -333,7 +333,7 @@ class chunk_heartbeat_base(chunk): if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return six.binary_type(buf) @six.add_metaclass(abc.ABCMeta) @@ -457,7 +457,7 @@ class chunk_data(chunk): if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return six.binary_type(buf) @sctp.register_chunk_type @@ -651,7 +651,7 @@ class chunk_sack(chunk): if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return six.binary_type(buf) @sctp.register_chunk_type @@ -813,7 +813,7 @@ class chunk_abort(chunk): if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return six.binary_type(buf) @sctp.register_chunk_type @@ -966,7 +966,7 @@ class chunk_error(chunk): if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return six.binary_type(buf) @sctp.register_chunk_type @@ -1026,7 +1026,7 @@ class chunk_cookie_echo(chunk): mod = len(buf) % 4 if mod: buf.extend(bytearray(4 - mod)) - return str(buf) + return six.binary_type(buf) @sctp.register_chunk_type @@ -1230,7 +1230,7 @@ class cause_with_value(cause): mod = len(buf) % 4 if mod: buf.extend(bytearray(4 - mod)) - return str(buf) + return six.binary_type(buf) @chunk_abort.register_cause_code @@ -1347,7 +1347,7 @@ class cause_missing_param(cause): mod = len(buf) % 4 if mod: buf.extend(bytearray(4 - mod)) - return str(buf) + return six.binary_type(buf) @chunk_abort.register_cause_code @@ -1474,7 +1474,7 @@ class cause_unresolvable_addr(cause_with_value): mod = len(buf) % 4 if mod: buf.extend(bytearray(4 - mod)) - return str(buf) + return six.binary_type(buf) @chunk_abort.register_cause_code @@ -1703,7 +1703,7 @@ class cause_restart_with_new_addr(cause_with_value): mod = len(buf) % 4 if mod: buf.extend(bytearray(4 - mod)) - return str(buf) + return six.binary_type(buf) @chunk_abort.register_cause_code @@ -1803,7 +1803,7 @@ class param(stringify.StringifyMixin): mod = len(buf) % 4 if mod: buf.extend(bytearray(4 - mod)) - return str(buf) + return six.binary_type(buf) def __len__(self): length = self.length @@ -2064,7 +2064,7 @@ class param_supported_addr(param): mod = len(buf) % 4 if mod: buf.extend(bytearray(4 - mod)) - return str(buf) + return six.binary_type(buf) @chunk_init.register_param_type @@ -2119,7 +2119,7 @@ class param_ipv4(param): if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return six.binary_type(buf) @chunk_init.register_param_type @@ -2174,4 +2174,4 @@ class param_ipv6(param): if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return six.binary_type(buf) diff --git a/ryu/lib/packet/tcp.py b/ryu/lib/packet/tcp.py index f0e86452..7262e245 100644 --- a/ryu/lib/packet/tcp.py +++ b/ryu/lib/packet/tcp.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import six import struct from . import packet_base @@ -108,4 +109,4 @@ class tcp(packet_base.PacketBase): self.csum = packet_utils.checksum_ip(prev, total_length, h + payload) struct.pack_into('!H', h, 16, self.csum) - return str(h) + return six.binary_type(h) diff --git a/ryu/tests/unit/packet/test_ipv6.py b/ryu/tests/unit/packet/test_ipv6.py index 914d314e..455dc8c3 100644 --- a/ryu/tests/unit/packet/test_ipv6.py +++ b/ryu/tests/unit/packet/test_ipv6.py @@ -17,6 +17,7 @@ import unittest import logging import inspect +import six import struct from nose.tools import * @@ -262,7 +263,7 @@ class Test_ipv6(unittest.TestCase): self.test_init() def test_parser(self): - _res = self.ip.parser(str(self.buf)) + _res = self.ip.parser(six.binary_type(self.buf)) if type(_res) is tuple: res = _res[0] else: @@ -307,7 +308,7 @@ class Test_ipv6(unittest.TestCase): prev = None buf = self.ip.serialize(data, prev) - res = struct.unpack_from(ipv6.ipv6._PACK_STR, str(buf)) + res = struct.unpack_from(ipv6.ipv6._PACK_STR, six.binary_type(buf)) eq_(self.v_tc_flow, res[0]) eq_(self.payload_length, res[1]) @@ -323,7 +324,7 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None buf = self.ip.serialize(data, prev) - hop_opts = ipv6.hop_opts.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + hop_opts = ipv6.hop_opts.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:])) eq_(repr(self.hop_opts), repr(hop_opts)) def test_serialize_with_dst_opts(self): @@ -333,7 +334,7 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None buf = self.ip.serialize(data, prev) - dst_opts = ipv6.dst_opts.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + dst_opts = ipv6.dst_opts.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:])) eq_(repr(self.dst_opts), repr(dst_opts)) def test_serialize_with_routing_type3(self): @@ -343,7 +344,7 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None buf = self.ip.serialize(data, prev) - routing = ipv6.routing.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + routing = ipv6.routing.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:])) eq_(repr(self.routing), repr(routing)) def test_serialize_with_fragment(self): @@ -353,7 +354,7 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None buf = self.ip.serialize(data, prev) - fragment = ipv6.fragment.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + fragment = ipv6.fragment.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:])) eq_(repr(self.fragment), repr(fragment)) def test_serialize_with_auth(self): @@ -363,7 +364,7 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None buf = self.ip.serialize(data, prev) - auth = ipv6.auth.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + auth = ipv6.auth.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:])) eq_(repr(self.auth), repr(auth)) def test_serialize_with_multi_headers(self): @@ -374,9 +375,9 @@ class Test_ipv6(unittest.TestCase): prev = None buf = self.ip.serialize(data, prev) offset = ipv6.ipv6._MIN_LEN - hop_opts = ipv6.hop_opts.parser(str(buf[offset:])) + hop_opts = ipv6.hop_opts.parser(six.binary_type(buf[offset:])) offset += len(hop_opts) - auth = ipv6.auth.parser(str(buf[offset:])) + auth = ipv6.auth.parser(six.binary_type(buf[offset:])) eq_(repr(self.hop_opts), repr(hop_opts)) eq_(repr(self.auth), repr(auth)) @@ -448,7 +449,7 @@ class Test_ipv6(unittest.TestCase): def test_default_args(self): ip = ipv6.ipv6() buf = ip.serialize(bytearray(), None) - res = struct.unpack(ipv6.ipv6._PACK_STR, str(buf)) + res = struct.unpack(ipv6.ipv6._PACK_STR, six.binary_type(buf)) eq_(res[0], 6 << 28) eq_(res[1], 0) @@ -464,7 +465,7 @@ class Test_ipv6(unittest.TestCase): ipv6.option(5, 2, b'\x00\x00'), ipv6.option(1, 0, None)])]) buf = ip.serialize(bytearray(), None) - res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', str(buf)) + res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', six.binary_type(buf)) eq_(res[0], 6 << 28) eq_(res[1], 8) @@ -547,17 +548,17 @@ class Test_hop_opts(unittest.TestCase): def test_serialize(self): buf = self.hop.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.nxt, res[0]) eq_(self.size, res[1]) offset = struct.calcsize(self.form) - opt1 = ipv6.option.parser(str(buf[offset:])) + opt1 = ipv6.option.parser(six.binary_type(buf[offset:])) offset += len(opt1) - opt2 = ipv6.option.parser(str(buf[offset:])) + opt2 = ipv6.option.parser(six.binary_type(buf[offset:])) offset += len(opt2) - opt3 = ipv6.option.parser(str(buf[offset:])) + opt3 = ipv6.option.parser(six.binary_type(buf[offset:])) offset += len(opt3) - opt4 = ipv6.option.parser(str(buf[offset:])) + opt4 = ipv6.option.parser(six.binary_type(buf[offset:])) eq_(5, opt1.type_) eq_(2, opt1.len_) eq_(b'\x00\x00', opt1.data) @@ -577,12 +578,12 @@ class Test_hop_opts(unittest.TestCase): def test_default_args(self): hdr = ipv6.hop_opts() buf = hdr.serialize() - res = struct.unpack('!BB', str(buf[:2])) + res = struct.unpack('!BB', six.binary_type(buf[:2])) eq_(res[0], 6) eq_(res[1], 0) opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00') - eq_(str(buf[2:]), opt.serialize()) + eq_(six.binary_type(buf[2:]), opt.serialize()) class Test_dst_opts(unittest.TestCase): @@ -628,17 +629,17 @@ class Test_dst_opts(unittest.TestCase): def test_serialize(self): buf = self.dst.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.nxt, res[0]) eq_(self.size, res[1]) offset = struct.calcsize(self.form) - opt1 = ipv6.option.parser(str(buf[offset:])) + opt1 = ipv6.option.parser(six.binary_type(buf[offset:])) offset += len(opt1) - opt2 = ipv6.option.parser(str(buf[offset:])) + opt2 = ipv6.option.parser(six.binary_type(buf[offset:])) offset += len(opt2) - opt3 = ipv6.option.parser(str(buf[offset:])) + opt3 = ipv6.option.parser(six.binary_type(buf[offset:])) offset += len(opt3) - opt4 = ipv6.option.parser(str(buf[offset:])) + opt4 = ipv6.option.parser(six.binary_type(buf[offset:])) eq_(5, opt1.type_) eq_(2, opt1.len_) eq_(b'\x00\x00', opt1.data) @@ -658,12 +659,12 @@ class Test_dst_opts(unittest.TestCase): def test_default_args(self): hdr = ipv6.dst_opts() buf = hdr.serialize() - res = struct.unpack('!BB', str(buf[:2])) + res = struct.unpack('!BB', six.binary_type(buf[:2])) eq_(res[0], 6) eq_(res[1], 0) opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00') - eq_(str(buf[2:]), opt.serialize()) + eq_(six.binary_type(buf[2:]), opt.serialize()) class Test_option(unittest.TestCase): @@ -862,7 +863,7 @@ class Test_routing_type3(unittest.TestCase): def test_serialize(self): buf = self.routing.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.nxt, res[0]) eq_(self.size, res[1]) eq_(self.type_, res[2]) @@ -916,7 +917,7 @@ class Test_routing_type3(unittest.TestCase): cmpe, pad) buf = routing.serialize() form = '!BBBBBB2x' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(nxt, res[0]) eq_(size, res[1]) eq_(type_, res[2]) @@ -980,7 +981,7 @@ class Test_routing_type3(unittest.TestCase): nxt, size, type_, seg, cmpi, cmpe, adrs) buf = routing.serialize() form = '!BBBBBB2x8s8s8s' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(nxt, res[0]) eq_(size, res[1]) eq_(type_, res[2]) @@ -999,7 +1000,7 @@ class Test_routing_type3(unittest.TestCase): hdr = ipv6.routing_type3() buf = hdr.serialize() LOG.info(repr(buf)) - res = struct.unpack_from(ipv6.routing_type3._PACK_STR, str(buf)) + res = struct.unpack_from(ipv6.routing_type3._PACK_STR, six.binary_type(buf)) LOG.info(res) eq_(res[0], 6) @@ -1043,7 +1044,7 @@ class Test_fragment(unittest.TestCase): def test_serialize(self): buf = self.fragment.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.nxt, res[0]) eq_(self.off_m, res[1]) eq_(self.id_, res[2]) @@ -1096,7 +1097,7 @@ class Test_auth(unittest.TestCase): def test_serialize(self): buf = self.auth.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.nxt, res[0]) eq_(self.size, res[1]) eq_(self.spi, res[2]) @@ -1117,7 +1118,7 @@ class Test_auth(unittest.TestCase): hdr = ipv6.auth() buf = hdr.serialize() LOG.info(repr(buf)) - res = struct.unpack_from(ipv6.auth._PACK_STR, str(buf)) + res = struct.unpack_from(ipv6.auth._PACK_STR, six.binary_type(buf)) LOG.info(res) eq_(res[0], 6) diff --git a/ryu/tests/unit/packet/test_lldp.py b/ryu/tests/unit/packet/test_lldp.py index fb1f4dc6..12f78d1e 100644 --- a/ryu/tests/unit/packet/test_lldp.py +++ b/ryu/tests/unit/packet/test_lldp.py @@ -17,6 +17,7 @@ import unittest import logging +import six import struct import inspect from nose.tools import ok_, eq_, nottest @@ -334,7 +335,7 @@ class TestLLDPOptionalTLV(unittest.TestCase): pkt.serialize() # self.data has many organizationally specific TLVs - data = str(pkt.data[:-2]) + data = six.binary_type(pkt.data[:-2]) eq_(data, self.data[:len(data)]) def test_to_string(self): diff --git a/ryu/tests/unit/packet/test_tcp.py b/ryu/tests/unit/packet/test_tcp.py index 56115ee4..862ad6f4 100644 --- a/ryu/tests/unit/packet/test_tcp.py +++ b/ryu/tests/unit/packet/test_tcp.py @@ -17,6 +17,7 @@ import unittest import logging +import six import struct from struct import * from nose.tools import * @@ -97,7 +98,7 @@ class Test_tcp(unittest.TestCase): t = tcp(self.src_port, self.dst_port, self.seq, self.ack, offset, self.bits, self.window_size, csum, self.urgent) buf = t.serialize(bytearray(), prev) - res = struct.unpack(tcp._PACK_STR, str(buf)) + res = struct.unpack(tcp._PACK_STR, six.binary_type(buf)) eq_(res[0], self.src_port) eq_(res[1], self.dst_port) diff --git a/ryu/tests/unit/packet/test_vrrp.py b/ryu/tests/unit/packet/test_vrrp.py index a26bc90f..51131278 100644 --- a/ryu/tests/unit/packet/test_vrrp.py +++ b/ryu/tests/unit/packet/test_vrrp.py @@ -18,6 +18,7 @@ import unittest import logging +import six import struct import inspect @@ -109,7 +110,7 @@ class Test_vrrpv2(unittest.TestCase): buf = vrrp_.serialize(bytearray(), prev) pack_str = vrrp.vrrpv2._PACK_STR + '4sII' pack_len = struct.calcsize(pack_str) - res = struct.unpack(pack_str, str(buf)) + res = struct.unpack(pack_str, six.binary_type(buf)) eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V2, type_)) eq_(res[1], vrid) eq_(res[2], priority) @@ -135,7 +136,7 @@ class Test_vrrpv2(unittest.TestCase): primary_ip = '192.168.0.2' p0 = self.vrrpv2.create_packet(primary_ip) p0.serialize() - p1 = packet.Packet(str(p0.data)) + p1 = packet.Packet(six.binary_type(p0.data)) p1.serialize() eq_(p0.data, p1.data) @@ -272,7 +273,7 @@ class Test_vrrpv3_ipv4(unittest.TestCase): print(len(buf), type(buf), buf) pack_str = vrrp.vrrpv3._PACK_STR + '4s' pack_len = struct.calcsize(pack_str) - res = struct.unpack(pack_str, str(buf)) + res = struct.unpack(pack_str, six.binary_type(buf)) eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_)) eq_(res[1], vrid) eq_(res[2], priority) @@ -300,7 +301,7 @@ class Test_vrrpv3_ipv4(unittest.TestCase): primary_ip = '192.168.0.2' p0 = self.vrrpv3.create_packet(primary_ip) p0.serialize() - p1 = packet.Packet(str(p0.data)) + p1 = packet.Packet(six.binary_type(p0.data)) p1.serialize() eq_(p0.data, p1.data) @@ -437,7 +438,7 @@ class Test_vrrpv3_ipv6(unittest.TestCase): print(len(buf), type(buf), buf) pack_str = vrrp.vrrpv3._PACK_STR + '16s' pack_len = struct.calcsize(pack_str) - res = struct.unpack(pack_str, str(buf)) + res = struct.unpack(pack_str, six.binary_type(buf)) eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_)) eq_(res[1], vrid) eq_(res[2], priority) @@ -466,7 +467,7 @@ class Test_vrrpv3_ipv6(unittest.TestCase): p0 = self.vrrpv3.create_packet(primary_ip) p0.serialize() print(len(p0.data), p0.data) - p1 = packet.Packet(str(p0.data)) + p1 = packet.Packet(six.binary_type(p0.data)) p1.serialize() print(len(p0.data), p0.data) print(len(p1.data), p1.data) |