codekingpro/portable-devtools
114k
1"""2h2/errors3~~~~~~~~~4 5Global error code registry containing the established HTTP/2 error codes.6 7The current registry is available at:8https://tools.ietf.org/html/rfc7540#section-11.49"""10from __future__ import annotations11 12import enum13 14 15class ErrorCodes(enum.IntEnum):16 """17 All known HTTP/2 error codes.18 19 .. versionadded:: 2.5.020 """21 22 #: Graceful shutdown.23 NO_ERROR = 0x024 25 #: Protocol error detected.26 PROTOCOL_ERROR = 0x127 28 #: Implementation fault.29 INTERNAL_ERROR = 0x230 31 #: Flow-control limits exceeded.32 FLOW_CONTROL_ERROR = 0x333 34 #: Settings not acknowledged.35 SETTINGS_TIMEOUT = 0x436 37 #: Frame received for closed stream.38 STREAM_CLOSED = 0x539 40 #: Frame size incorrect.41 FRAME_SIZE_ERROR = 0x642 43 #: Stream not processed.44 REFUSED_STREAM = 0x745 46 #: Stream cancelled.47 CANCEL = 0x848 49 #: Compression state not updated.50 COMPRESSION_ERROR = 0x951 52 #: TCP connection error for CONNECT method.53 CONNECT_ERROR = 0xa54 55 #: Processing capacity exceeded.56 ENHANCE_YOUR_CALM = 0xb57 58 #: Negotiated TLS parameters not acceptable.59 INADEQUATE_SECURITY = 0xc60 61 #: Use HTTP/1.1 for the request.62 HTTP_1_1_REQUIRED = 0xd63 64 65def _error_code_from_int(code: int) -> ErrorCodes | int:66 """67 Given an integer error code, returns either one of :class:`ErrorCodes68 <h2.errors.ErrorCodes>` or, if not present in the known set of codes,69 returns the integer directly.70 """71 try:72 return ErrorCodes(code)73 except ValueError:74 return code75 76 77__all__ = ["ErrorCodes"]78 