Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
exceptions.py195 linesDownload Raw Back to h2
1"""2h2/exceptions3~~~~~~~~~~~~~4 5Exceptions for the HTTP/2 module.6"""7from __future__ import annotations8 9from .errors import ErrorCodes10 11 12class H2Error(Exception):13    """14    The base class for all exceptions for the HTTP/2 module.15    """16 17 18class ProtocolError(H2Error):19    """20    An action was attempted in violation of the HTTP/2 protocol.21    """22 23    #: The error code corresponds to this kind of Protocol Error.24    error_code = ErrorCodes.PROTOCOL_ERROR25 26 27class FrameTooLargeError(ProtocolError):28    """29    The frame that we tried to send or that we received was too large.30    """31 32    #: The error code corresponds to this kind of Protocol Error.33    error_code = ErrorCodes.FRAME_SIZE_ERROR34 35 36class FrameDataMissingError(ProtocolError):37    """38    The frame that we received is missing some data.39 40    .. versionadded:: 2.0.041    """42 43    #: The error code corresponds to this kind of Protocol Error.44    error_code = ErrorCodes.FRAME_SIZE_ERROR45 46 47class TooManyStreamsError(ProtocolError):48    """49    An attempt was made to open a stream that would lead to too many concurrent50    streams.51    """52 53 54 55class FlowControlError(ProtocolError):56    """57    An attempted action violates flow control constraints.58    """59 60    #: The error code corresponds to this kind of Protocol Error.61    error_code = ErrorCodes.FLOW_CONTROL_ERROR62 63 64class StreamIDTooLowError(ProtocolError):65    """66    An attempt was made to open a stream that had an ID that is lower than the67    highest ID we have seen on this connection.68    """69 70    def __init__(self, stream_id: int, max_stream_id: int) -> None:71        #: The ID of the stream that we attempted to open.72        self.stream_id = stream_id73 74        #: The current highest-seen stream ID.75        self.max_stream_id = max_stream_id76 77    def __str__(self) -> str:78        return f"StreamIDTooLowError: {self.stream_id} is lower than {self.max_stream_id}"79 80 81class NoAvailableStreamIDError(ProtocolError):82    """83    There are no available stream IDs left to the connection. All stream IDs84    have been exhausted.85 86    .. versionadded:: 2.0.087    """88 89 90 91class NoSuchStreamError(ProtocolError):92    """93    A stream-specific action referenced a stream that does not exist.94 95    .. versionchanged:: 2.0.096       Became a subclass of :class:`ProtocolError97       <h2.exceptions.ProtocolError>`98    """99 100    def __init__(self, stream_id: int) -> None:101        #: The stream ID corresponds to the non-existent stream.102        self.stream_id = stream_id103 104 105class StreamClosedError(NoSuchStreamError):106    """107    A more specific form of108    :class:`NoSuchStreamError <h2.exceptions.NoSuchStreamError>`. Indicates109    that the stream has since been closed, and that all state relating to that110    stream has been removed.111    """112 113    def __init__(self, stream_id: int) -> None:114        #: The stream ID corresponds to the nonexistent stream.115        self.stream_id = stream_id116 117        #: The relevant HTTP/2 error code.118        self.error_code = ErrorCodes.STREAM_CLOSED119 120        # Any events that internal code may need to fire. Not relevant to121        # external users that may receive a StreamClosedError.122        self._events = []  # type: ignore123 124 125class InvalidSettingsValueError(ProtocolError, ValueError):126    """127    An attempt was made to set an invalid Settings value.128 129    .. versionadded:: 2.0.0130    """131 132    def __init__(self, msg: str, error_code: ErrorCodes) -> None:133        super().__init__(msg)134        self.error_code = error_code135 136 137class InvalidBodyLengthError(ProtocolError):138    """139    The remote peer sent more or less data that the Content-Length header140    indicated.141 142    .. versionadded:: 2.0.0143    """144 145    def __init__(self, expected: int, actual: int) -> None:146        self.expected_length = expected147        self.actual_length = actual148 149    def __str__(self) -> str:150        return f"InvalidBodyLengthError: Expected {self.expected_length} bytes, received {self.actual_length}"151 152 153class UnsupportedFrameError(ProtocolError):154    """155    The remote peer sent a frame that is unsupported in this context.156 157    .. versionadded:: 2.1.0158 159    .. versionchanged:: 4.0.0160       Removed deprecated KeyError parent class.161    """162 163 164 165class RFC1122Error(H2Error):166    """167    Emitted when users attempt to do something that is literally allowed by the168    relevant RFC, but is sufficiently ill-defined that it's unwise to allow169    users to actually do it.170 171    While there is some disagreement about whether or not we should be liberal172    in what accept, it is a truth universally acknowledged that we should be173    conservative in what emit.174 175    .. versionadded:: 2.4.0176    """177 178    # shazow says I'm going to regret naming the exception this way. If that179    # turns out to be true, TELL HIM NOTHING.180 181 182class DenialOfServiceError(ProtocolError):183    """184    Emitted when the remote peer exhibits a behaviour that is likely to be an185    attempt to perform a Denial of Service attack on the implementation. This186    is a form of ProtocolError that carries a different error code, and allows187    more easy detection of this kind of behaviour.188 189    .. versionadded:: 2.5.0190    """191 192    #: The error code corresponds to this kind of193    #: :class:`ProtocolError <h2.exceptions.ProtocolError>`194    error_code = ErrorCodes.ENHANCE_YOUR_CALM195 
codekingpro/portable-devtools · Team Ai