module documentation

Tools for pedantically processing the HTTP protocol.

Function _decint Parse a decimal integer of the form 1*DIGIT, i.e. consisting only of decimal digits. The integer may be embedded in whitespace (space and horizontal tab). This differs from the built-in int() function by disallowing a leading ...
Function _hexint Decode a hexadecimal integer.
Function _ishexdigits Is the string case-insensitively hexidecimal?
Function _istoken Is the string a token per RFC 9110 section 5.6.2?
def _decint(data: bytes) -> int: (source)

Parse a decimal integer of the form 1*DIGIT, i.e. consisting only of decimal digits. The integer may be embedded in whitespace (space and horizontal tab). This differs from the built-in int() function by disallowing a leading + character and various forms of whitespace (note that we sanitize linear whitespace in header values in twisted.web.http_headers.Headers).

Parameters
data:bytesValue to parse.
Returns
intA non-negative integer.
Raises
ValueErrorWhen value contains non-decimal characters.
def _hexint(b: bytes) -> int: (source)

Decode a hexadecimal integer.

Unlike int(b, 16), this raises ValueError when the integer has a prefix like b'0x', b'+', or b'-', which is desirable when parsing network protocols.

def _ishexdigits(b: bytes) -> bool: (source)

Is the string case-insensitively hexidecimal?

It must be composed of one or more characters in the ranges a-f, A-F and 0-9.

def _istoken(b: bytes) -> bool: (source)

Is the string a token per RFC 9110 section 5.6.2?