Python2's array.array('H', x) does not produce an array of two-byte ints
if x is of type bytearray, but it does if x is of type str.
In Python3 array.array('H', x) produces an array of two-byte ints
regardless of whether x is bytes or bytearray. In python3 str(x)
evaluates to something like "bytearray('bytes')" when x is a bytearray,
which breaks the behaviour.
bytes(x) evaluates to str(x) in py2 and bytes(x) in py3, so it works for
both when x is a bytearray.Signed-off-by: James Guthrie <[email protected]> --- ryu/lib/packet/packet_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ryu/lib/packet/packet_utils.py b/ryu/lib/packet/packet_utils.py index 3839e69..dcf4612 100644 --- a/ryu/lib/packet/packet_utils.py +++ b/ryu/lib/packet/packet_utils.py @@ -28,7 +28,7 @@ def checksum(data): if len(data) % 2: data += '\x00' - data = str(data) # input can be bytearray. + data = bytes(data) # input can be bytearray s = sum(array.array('H', data)) s = (s & 0xffff) + (s >> 16) s += (s >> 16) -- 2.4.1 ------------------------------------------------------------------------------ _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
