framing: fix bytes handling for Python 2.6

This commit is contained in:
Roman Zeyde
2015-01-05 12:53:15 +02:00
parent 1728bba109
commit 3901b32cc5
2 changed files with 4 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"

View File

@@ -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))