Skip to content

Commit

Permalink
Merge c0d27b4 into 75cc3c3
Browse files Browse the repository at this point in the history
  • Loading branch information
peace-maker committed Mar 25, 2024
2 parents 75cc3c3 + c0d27b4 commit 42bcd88
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions pwnlib/tubes/tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,22 @@ def recvline(self, keepends=True, timeout=default):
Receive a single line from the tube.
A "line" is any sequence of bytes terminated by the byte sequence
set in :attr:`newline`, which defaults to ``'\n'``.
set in :attr:`newline`, which defaults to ``b'\n'``.
If the connection is closed (:class:`EOFError`) before a newline is received, the
buffered data is returned. If the buffer is empty, an :class:`EOFError` is raised.
If the request is not satisfied before ``timeout`` seconds pass,
all data is buffered and an empty string (``''``) is returned.
all data is buffered and an empty byte string (``b''``) is returned.
Arguments:
keepends(bool): Keep the line ending (:const:`True`).
timeout(int): Timeout
Raises:
exceptions.EOFError: The connection closed before the request
could be satisfied and the buffer is empty
Return:
All bytes received over the tube until the first
newline ``'\n'`` is received. Optionally retains
Expand All @@ -494,8 +501,30 @@ def recvline(self, keepends=True, timeout=default):
>>> t.newline = b'\r\n'
>>> t.recvline(keepends = False)
b'Foo\nBar'
>>> t = tube()
>>> def _recv_eof(n):
... if not _recv_eof.throw:
... _recv_eof.throw = True
... return b'real line\ntrailing data'
... raise EOFError
>>> _recv_eof.throw = False
>>> t.recv_raw = _recv_eof
>>> t.recvline()
b'real line\n'
>>> t.recvline()
b'trailing data'
>>> t.recvline() # doctest: +ELLIPSIS
Traceback (most recent call last):
...
EOFError
"""
return self.recvuntil(self.newline, drop = not keepends, timeout = timeout)
try:
return self.recvuntil(self.newline, drop = not keepends, timeout = timeout)
except EOFError:
if self.buffer.size > 0:
self.warn_once('EOFError during recvline. Returning buffered data without trailing newline.')
return self.buffer.get()
raise

def recvline_pred(self, pred, keepends=False, timeout=default):
r"""recvline_pred(pred, keepends=False) -> bytes
Expand Down

0 comments on commit 42bcd88

Please sign in to comment.