class documentation

class V2Parser: (source)

Implements interfaces: twisted.protocols.haproxy._interfaces.IProxyParser

View In Hierarchy

PROXY protocol version two header parser.

Version two of the PROXY protocol is a binary format.

Class Method parse Parse a bytestring as a full PROXY protocol header.
Method __init__ Undocumented
Method feed Consume a chunk of data and attempt to parse it.
Class Variable ADDRESSFORMATS Undocumented
Class Variable COMMANDS Undocumented
Class Variable PREFIX Undocumented
Class Variable VERSIONS Undocumented
Instance Variable buffer Undocumented
Static Method _bytesToIPv4 Convert packed 32-bit IPv4 address bytes into a dotted-quad ASCII bytes representation of that address.
Static Method _bytesToIPv6 Convert packed 128-bit IPv6 address bytes into a colon-separated ASCII bytes representation of that address.
@classmethod
def parse(cls, line): (source)
Parse a bytestring as a full PROXY protocol header.
Parameters
line:bytesA bytestring that represents a valid HAProxy PROXY protocol version 2 header.
Returns
_info.ProxyInfoA _interfaces.IProxyInfo containing the parsed data.
Raises
InvalidProxyHeaderIf the bytestring does not represent a valid PROXY header.
def __init__(self): (source)

Undocumented

def feed(self, data): (source)
Consume a chunk of data and attempt to parse it.
Parameters
data:bytesA bytestring.
Returns
Union[Tuple[_info.ProxyInfo, bytes], Tuple[None, None]]A two-tuple containing, in order, a _interfaces.IProxyInfo and any bytes fed to the parser that followed the end of the header. Both of these values are None until a complete header is parsed.
Raises
InvalidProxyHeaderIf the bytes fed to the parser create an invalid PROXY header.
ADDRESSFORMATS: dict[int, str] = (source)

Undocumented

COMMANDS = (source)

Undocumented

PREFIX: bytes = (source)

Undocumented

VERSIONS: list[int] = (source)

Undocumented

buffer: bytes = (source)

Undocumented

@staticmethod
def _bytesToIPv4(bytestring): (source)
Convert packed 32-bit IPv4 address bytes into a dotted-quad ASCII bytes representation of that address.
Parameters
bytestring:bytes4 octets representing an IPv4 address.
Returns
bytesa dotted-quad notation IPv4 address.
@staticmethod
def _bytesToIPv6(bytestring): (source)
Convert packed 128-bit IPv6 address bytes into a colon-separated ASCII bytes representation of that address.
Parameters
bytestring:bytes16 octets representing an IPv6 address.
Returns
bytesa dotted-quad notation IPv6 address.