Skip to content

Commit 531e845

Browse files
authored
Merge pull request #53 from jepler/circuitpython-compat
Fix CircuitPython compatibility
2 parents ba76312 + 9a95271 commit 531e845

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

adafruit_requests.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555

5656
import errno
5757

58+
# CircuitPython 6.0 does not have the bytearray.split method.
59+
# This function emulates buf.split(needle)[0], which is the functionality
60+
# required.
61+
def _buffer_split0(buf, needle):
62+
index = buf.find(needle)
63+
if index == -1:
64+
return buf
65+
return buf[:index]
66+
5867

5968
class _RawResponse:
6069
def __init__(self, response):
@@ -220,7 +229,7 @@ def _readinto(self, buf):
220229
# Consume trailing \r\n for chunks 2+
221230
if self._remaining == 0:
222231
self._throw_away(2)
223-
chunk_header = self._readto(b"\r\n").split(b";", 1)[0]
232+
chunk_header = _buffer_split0(self._readto(b"\r\n"), b";")
224233
http_chunk_size = int(bytes(chunk_header), 16)
225234
if http_chunk_size == 0:
226235
self._chunked = False

0 commit comments

Comments
 (0)