8000 Compatibility with Python 3.2 · netzulo/python-io-chunks@5687c10 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5687c10

Browse files
committed
Compatibility with Python 3.2
1 parent 9f4c4bb commit 5687c10

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ python:
88
- "3.6"
99
install:
1010
- pip install .
11-
script: nosetests
11+
script: nosetests -v

io_chunks/chunks.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
)
77

88

9+
def memoryview_compat(bytes_, castTo='B'):
10+
obj = memoryview(bytes_)
11+
try:
12+
obj.cast(castTo)
13+
except AttributeError:
14+
obj.format = castTo
15+
return obj
16+
17+
918
class RawIOChunk(RawIOBase):
1019
"""
1120
An IO read-only object with access to a portion of another IO object.
@@ -65,7 +74,7 @@ def readinto(self, array):
6574
remaining = self._size - self._cursor
6675
if remaining <= 0:
6776
return 0
68-
array = memoryview(array).cast('B')
77+
array = memoryview_compat(array, 'B')
6978
position = self._stream.tell()
7079
self._stream.seek(self._start + self._cursor)
7180
if len(array) > remaining:

0 commit comments

Comments
 (0)
0