Skip to content

Commit c36a72d

Browse files
authored
Merge pull request #150 from tekktrik/feature/configurable-eol
Add configurable EOL to readline()
2 parents 13102f3 + 4a21b4c commit c36a72d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,21 @@ def write(self, data):
9292
"""
9393
self.send(data)
9494

95-
def readline(self):
96-
"""Attempt to return as many bytes as we can up to but not including '\r\n'"""
95+
def readline(self, eol=b"\r\n"):
96+
"""Attempt to return as many bytes as we can up to but not including
97+
end-of-line character (default is '\\r\\n')"""
98+
9799
# print("Socket readline")
98100
stamp = time.monotonic()
99-
while b"\r\n" not in self._buffer:
101+
while eol not in self._buffer:
100102
# there's no line already in there, read some more
101103
avail = self.available()
102104
if avail:
103105
self._buffer += _the_interface.socket_read(self._socknum, avail)
104106
elif self._timeout > 0 and time.monotonic() - stamp > self._timeout:
105107
self.close() # Make sure to close socket so that we don't exhaust sockets.
106108
raise RuntimeError("Didn't receive full response, failing out")
107-
firstline, self._buffer = self._buffer.split(b"\r\n", 1)
109+
firstline, self._buffer = self._buffer.split(eol, 1)
108110
gc.collect()
109111
return firstline
110112

0 commit comments

Comments
 (0)