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

Method parse

src/websockets/client.py:300–341  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

298 self.writes.append(request.serialize())
299
300 def parse(self) -> Generator[None]:
301 if self.state is CONNECTING:
302 try:
303 response = yield from Response.parse(
304 self.reader.read_line,
305 self.reader.read_exact,
306 self.reader.read_to_eof,
307 )
308 except Exception as exc:
309 self.handshake_exc = InvalidMessage(
310 "did not receive a valid HTTP response"
311 )
312 self.handshake_exc.__cause__ = exc
313 self.send_eof()
314 self.parser = self.discard()
315 next(self.parser) # start coroutine
316 yield
317
318 if self.debug:
319 code, phrase = response.status_code, response.reason_phrase
320 self.logger.debug("< HTTP/1.1 %d %s", code, phrase)
321 for key, value in response.headers.raw_items():
322 self.logger.debug("< %s: %s", key, value)
323 if response.body:
324 self.logger.debug("< [body] (%d bytes)", len(response.body))
325
326 try:
327 self.process_response(response)
328 except InvalidHandshake as exc:
329 response._exception = exc
330 self.events.append(response)
331 self.handshake_exc = exc
332 self.send_eof()
333 self.parser = self.discard()
334 next(self.parser) # start coroutine
335 yield
336
337 assert self.state is CONNECTING
338 self.state = OPEN
339 self.events.append(response)
340
341 yield from super().parse()
342
343
344class ClientConnection(ClientProtocol):

Callers

nothing calls this directly

Calls 6

process_responseMethod · 0.95
InvalidMessageClass · 0.85
send_eofMethod · 0.80
raw_itemsMethod · 0.80
appendMethod · 0.80
discardMethod · 0.45

Tested by

no test coverage detected