From 3901b32cc5f8a881acdcf1e04f07706af573d970 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 5 Jan 2015 12:53:15 +0200 Subject: [PATCH] framing: fix bytes handling for Python 2.6 --- .travis.yml | 1 + amodem/framing.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08fb936..72f5c62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python python: + - "2.6" - "2.7" - "3.2" - "3.3" diff --git a/amodem/framing.py b/amodem/framing.py index 7cc1d32..f5c62b9 100644 --- a/amodem/framing.py +++ b/amodem/framing.py @@ -7,7 +7,7 @@ import struct import logging log = logging.getLogger(__name__) -_crc32 = lambda x, mask: binascii.crc32(x) & mask +_crc32 = lambda x, mask: binascii.crc32(bytes(x)) & mask # (so the result will be unsigned on Python 2/3) @@ -21,7 +21,7 @@ class Checksum(object): return struct.pack(self.fmt, checksum) + payload def decode(self, data): - received, = struct.unpack(self.fmt, data[:self.size]) + received, = struct.unpack(self.fmt, bytes(data[:self.size])) payload = data[self.size:] expected = self.func(payload) if received != expected: @@ -65,7 +65,7 @@ class Framer(object): chunk = bytearray(itertools.islice(data, length)) if len(chunk) < length: raise ValueError('missing prefix data') - return struct.unpack(fmt, chunk) + return struct.unpack(fmt, bytes(chunk)) def _take_len(self, data, length): chunk = bytearray(itertools.islice(data, length))