Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/aiohttp/http_exceptions.py
7763 views
"""Low-level http related exceptions."""123from typing import Optional, Union45from .typedefs import _CIMultiDict67__all__ = ("HttpProcessingError",)8910class HttpProcessingError(Exception):11"""HTTP error.1213Shortcut for raising HTTP errors with custom code, message and headers.1415code: HTTP Error code.16message: (optional) Error message.17headers: (optional) Headers to be sent in response, a list of pairs18"""1920code = 021message = ""22headers = None2324def __init__(25self,26*,27code: Optional[int] = None,28message: str = "",29headers: Optional[_CIMultiDict] = None,30) -> None:31if code is not None:32self.code = code33self.headers = headers34self.message = message3536def __str__(self) -> str:37return f"{self.code}, message={self.message!r}"3839def __repr__(self) -> str:40return f"<{self.__class__.__name__}: {self}>"414243class BadHttpMessage(HttpProcessingError):4445code = 40046message = "Bad Request"4748def __init__(self, message: str, *, headers: Optional[_CIMultiDict] = None) -> None:49super().__init__(message=message, headers=headers)50self.args = (message,)515253class HttpBadRequest(BadHttpMessage):5455code = 40056message = "Bad Request"575859class PayloadEncodingError(BadHttpMessage):60"""Base class for payload errors"""616263class ContentEncodingError(PayloadEncodingError):64"""Content encoding error."""656667class TransferEncodingError(PayloadEncodingError):68"""transfer encoding error."""697071class ContentLengthError(PayloadEncodingError):72"""Not enough data for satisfy content length header."""737475class LineTooLong(BadHttpMessage):76def __init__(77self, line: str, limit: str = "Unknown", actual_size: str = "Unknown"78) -> None:79super().__init__(80f"Got more than {limit} bytes ({actual_size}) when reading {line}."81)82self.args = (line, limit, actual_size)838485class InvalidHeader(BadHttpMessage):86def __init__(self, hdr: Union[bytes, str]) -> None:87if isinstance(hdr, bytes):88hdr = hdr.decode("utf-8", "surrogateescape")89super().__init__(f"Invalid HTTP Header: {hdr}")90self.hdr = hdr91self.args = (hdr,)929394class BadStatusLine(BadHttpMessage):95def __init__(self, line: str = "") -> None:96if not isinstance(line, str):97line = repr(line)98super().__init__(f"Bad status line {line!r}")99self.args = (line,)100self.line = line101102103class InvalidURLError(BadHttpMessage):104pass105106107