MCPcopy Index your code
hub / github.com/python-websockets/websockets / discard

Method discard

src/websockets/protocol.py:641–669  ·  view source on GitHub ↗

Discard incoming data. This coroutine replaces :meth:`parse`: - after receiving a close frame, during a normal closure (1.4); - after sending a close frame, during an abnormal closure (7.1.7).

(self)

Source from the content-addressed store, hash-verified

639 raise AssertionError("parse() shouldn't step after error")
640
641 def discard(self) -> Generator[None]:
642 """
643 Discard incoming data.
644
645 This coroutine replaces :meth:`parse`:
646
647 - after receiving a close frame, during a normal closure (1.4);
648 - after sending a close frame, during an abnormal closure (7.1.7).
649
650 """
651 # After the opening handshake completes, the server closes the TCP
652 # connection in the same circumstances where discard() replaces parse().
653 # The client closes it when it receives EOF from the server or times
654 # out. (The latter case cannot be handled in this Sans-I/O layer.)
655 assert (self.side is SERVER or self.state is CONNECTING) == (self.eof_sent)
656 while not (yield from self.reader.at_eof()):
657 self.reader.discard()
658 if self.debug:
659 self.logger.debug("< EOF")
660 # A server closes the TCP connection immediately, while a client
661 # waits for the server to close the TCP connection.
662 if self.side is CLIENT and self.state is not CONNECTING:
663 self.send_eof()
664 self.state = CLOSED
665 # If discard() completes normally, execution ends here.
666 yield
667 # Once the reader reaches EOF, its feed_data/eof() methods raise an
668 # error, so our receive_data/eof() methods don't step the generator.
669 raise AssertionError("discard() shouldn't step after EOF")
670
671 def recv_frame(self, frame: Frame) -> None:
672 """

Callers 7

failMethod · 0.95
recv_frameMethod · 0.95
parseMethod · 0.45
connection_lostMethod · 0.45
send_responseMethod · 0.45
parseMethod · 0.45
test_discardMethod · 0.45

Calls 2

send_eofMethod · 0.95
at_eofMethod · 0.45

Tested by 1

test_discardMethod · 0.36