Skip to content

Commit 48d6af5

Browse files
committed
Fix pure Python implementation for Python 3.3 and later
Python 3.3 changed the type of byte memoryview indexed items: memoryview(b'abc')[0] == b'abc'[0] == 97 In Python 3.2 and earlier: memoryview(b'abc')[0] == b'a'
1 parent 664f549 commit 48d6af5

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

python3/cobs/cobs/_cobs_py.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def _get_buffer_view(in_bytes):
1313
mv = memoryview(in_bytes)
1414
if mv.ndim > 1 or mv.itemsize > 1:
1515
raise BufferError('object must be a single-dimension buffer of bytes.')
16+
try:
17+
mv = mv.cast('c')
18+
except AttributeError:
19+
pass
1620
return mv
1721

1822
def encode(in_bytes):

python3/cobs/cobsr/_cobsr_py.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def _get_buffer_view(in_bytes):
1313
mv = memoryview(in_bytes)
1414
if mv.ndim > 1 or mv.itemsize > 1:
1515
raise BufferError('object must be a single-dimension buffer of bytes.')
16+
try:
17+
mv = mv.cast('c')
18+
except AttributeError:
19+
pass
1620
return mv
1721

1822
def encode(in_bytes):

0 commit comments

Comments
 (0)