File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,22 @@ Native ports
157157 Returns an instance of :class: `bytes ` when available (Python 2.6
158158 and newer) and :class: `str ` otherwise.
159159
160+ .. method :: read_until(expected=LF, size=None)
161+
162+ :param expected: The byte string to search for.
163+ :param size: Number of bytes to read.
164+ :return: Bytes read from the port.
165+ :rtype: bytes
166+
167+ Read until an expected sequence is found ('\n ' by default), the size
168+ is exceeded or until timeout occurs. If a timeout is set it may
169+ return less characters as requested. With no timeout it will block
170+ until the requested number of bytes is read.
171+
172+ .. versionchanged :: 2.5
173+ Returns an instance of :class: `bytes ` when available (Python 2.6
174+ and newer) and :class: `str ` otherwise.
175+
160176 .. method :: write(data)
161177
162178 :param data: Data to send.
Original file line number Diff line number Diff line change @@ -649,19 +649,19 @@ def read_all(self):
649649 """
650650 return self .read (self .in_waiting )
651651
652- def read_until (self , terminator = LF , size = None ):
652+ def read_until (self , expected = LF , size = None ):
653653 """\
654- Read until a termination sequence is found ('\n ' by default), the size
654+ Read until an expected sequence is found ('\n ' by default), the size
655655 is exceeded or until timeout occurs.
656656 """
657- lenterm = len (terminator )
657+ lenterm = len (expected )
658658 line = bytearray ()
659659 timeout = Timeout (self ._timeout )
660660 while True :
661661 c = self .read (1 )
662662 if c :
663663 line += c
664- if line [- lenterm :] == terminator :
664+ if line [- lenterm :] == expected :
665665 break
666666 if size is not None and len (line ) >= size :
667667 break
You can’t perform that action at this time.
0 commit comments