MCPcopy Create free account
hub / github.com/python-websockets/websockets / PayloadTooBig

Class PayloadTooBig

src/websockets/exceptions.py:381–432  ·  view source on GitHub ↗

Raised when parsing a frame with a payload that exceeds the maximum size. The Sans-I/O layer uses this exception internally. It doesn't bubble up to the I/O layer. The :meth:`~websockets.extensions.Extension.decode` method of extensions must raise :exc:`PayloadTooBig` if decod

Source from the content-addressed store, hash-verified

379
380
381class PayloadTooBig(WebSocketException):
382 """
383 Raised when parsing a frame with a payload that exceeds the maximum size.
384
385 The Sans-I/O layer uses this exception internally. It doesn't bubble up to
386 the I/O layer.
387
388 The :meth:`~websockets.extensions.Extension.decode` method of extensions
389 must raise :exc:`PayloadTooBig` if decoding a frame would exceed the limit.
390
391 """
392
393 def __init__(
394 self,
395 size_or_message: int | None | str,
396 max_size: int | None = None,
397 current_size: int | None = None,
398 ) -> None:
399 if isinstance(size_or_message, str):
400 assert max_size is None
401 assert current_size is None
402 warnings.warn( # deprecated in 14.0 - 2024-11-09
403 "PayloadTooBig(message) is deprecated; "
404 "change to PayloadTooBig(size, max_size)",
405 DeprecationWarning,
406 )
407 self.message: str | None = size_or_message
408 else:
409 self.message = None
410 self.size: int | None = size_or_message
411 assert max_size is not None
412 self.max_size: int = max_size
413 self.current_size: int | None = None
414 self.set_current_size(current_size)
415
416 def __str__(self) -> str:
417 if self.message is not None:
418 return self.message
419 else:
420 message = "frame "
421 if self.size is not None:
422 message += f"with {self.size} bytes "
423 if self.current_size is not None:
424 message += f"after reading {self.current_size} bytes "
425 message += f"exceeds limit of {self.max_size} bytes"
426 return message
427
428 def set_current_size(self, current_size: int | None) -> None:
429 assert self.current_size is None
430 if current_size is not None:
431 self.max_size += current_size
432 self.current_size = current_size
433
434
435class InvalidState(WebSocketException, AssertionError):

Callers 5

parseMethod · 0.85
readMethod · 0.85
decodeMethod · 0.85
test_strMethod · 0.85

Calls

no outgoing calls

Tested by 2

test_strMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…