proxyprotocol.result

proxyprotocol.result.is_local(result)[source]

Checks if the result is an unproxied local connection.

Parameters:

result (ProxyResult) – The proxy protocol result.

Return type:

TypeGuard[ProxyResultLocal]

proxyprotocol.result.is_unknown(result)[source]

Checks if the result is a proxied connection from an unknown origin.

Parameters:

result (ProxyResult) – The proxy protocol result.

Return type:

TypeGuard[ProxyResultUnknown]

proxyprotocol.result.is_ipv4(result)[source]

Checks if the result is a proxied IPv4 connection.

Parameters:

result (ProxyResult) – The proxy protocol result.

Return type:

TypeGuard[ProxyResultIPv4]

proxyprotocol.result.is_ipv6(result)[source]

Checks if the result is a proxied IPv6 connection.

Parameters:

result (ProxyResult) – The proxy protocol result.

Return type:

TypeGuard[ProxyResultIPv6]

proxyprotocol.result.is_unix(result)[source]

Checks if the result is a proxied UNIX connection.

Parameters:

result (ProxyResult) – The proxy protocol result.

Return type:

TypeGuard[ProxyResultUnix]

class proxyprotocol.result.ProxyResultType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

The type of proxy result.

LOCAL = (1, 'AF_UNSPEC')

The connection is not proxied at all.

UNKNOWN = (2, 'AF_UNSPEC')

The connection is proxied from an unknown address family.

IPv4 = (3, 'AF_INET')

The connection is proxied from an IPv4 address.

IPv6 = (4, 'AF_INET6')

The connection is proxied from an IPv6 address.

UNIX = (5, 'AF_UNIX')

The connection is proxied from a UNIX socket.

property family: AddressFamily

The address family corresponding to the proxy result type.

Raises:

AttributeError – The address family does not exist on the current platform, e.g. AF_UNIX on Windows.

class proxyprotocol.result.ProxyResult[source]

Base class for PROXY protocol results.

abstract property type: ProxyResultType

The type of proxy result.

abstract property proxied: bool

True if the result should override the information in the underlying socket.

abstract property source: None | str | Tuple[IPv4Address, int] | Tuple[IPv6Address, int]

The original source address info for the connection.

abstract property dest: None | str | Tuple[IPv4Address, int] | Tuple[IPv6Address, int]

The original destination address info for the connection.

property family: AddressFamily

The original socket address family.

Raises:

AttributeError – An address family was proxied to a platform that does not support it. Use type instead when possible.

property protocol: SocketKind | None

The original socket protocol.

abstract property tlv: ProxyProtocolTLV

Additional information about the connection.

abstract property peername: None | str | Tuple[str, int] | Tuple[str, int, int, int]

The source value in SockAddr form.

abstract property sockname: None | str | Tuple[str, int] | Tuple[str, int, int, int]

The dest value in SockAddr form.

class proxyprotocol.result.ProxyResultLocal(*, tlv=ProxyProtocolTLV())[source]

Indicates that the connection should be treated as if it is not proxied. The real socket getpeername() and getsockname() will provide the correct address information.

Parameters:

tlv (ProxyProtocolTLV) – Additional information about the connection.

property proxied: Literal[False]

True if the result should override the information in the underlying socket.

property source: None

The original source address info for the connection.

property dest: None

The original destination address info for the connection.

property peername: None

The source value in SockAddr form.

property sockname: None

The dest value in SockAddr form.

property tlv: ProxyProtocolTLV

Additional information about the connection.

class proxyprotocol.result.ProxyResultUnknown(exception=None, *, tlv=ProxyProtocolTLV())[source]

Indicates that the source of the connection is unknown.

Parameters:
  • exception (Optional[Exception]) – The exception that occurred, if any.

  • tlv (ProxyProtocolTLV) – Additional information about the connection.

property exception: Exception | None

An exception that occurred during reading or parsing the PROXY protocol header.

property proxied: Literal[True]

True if the result should override the information in the underlying socket.

property source: None

The original source address info for the connection.

property dest: None

The original destination address info for the connection.

property peername: None

The source value in SockAddr form.

property sockname: None

The dest value in SockAddr form.

property tlv: ProxyProtocolTLV

Additional information about the connection.

class proxyprotocol.result.ProxyResultIPv4(source, dest, *, protocol=None, tlv=ProxyProtocolTLV())[source]

The original connection was made with an IPv4 socket. The source and dest properties will contain a tuple of an IPv4Address and a port number.

Parameters:
  • source (Tuple[IPv4Address, int]) – The source address of the connection.

  • dest (Tuple[IPv4Address, int]) – The destination address of the connection.

  • protocol (Optional[SocketKind]) – The socket protocol (or type).

  • tlv (ProxyProtocolTLV) – Additional information about the connection.

property proxied: Literal[True]

True if the result should override the information in the underlying socket.

property source: Tuple[IPv4Address, int]

The original source address info for the connection.

property dest: Tuple[IPv4Address, int]

The original destination address info for the connection.

property protocol: SocketKind | None

The original socket protocol.

property tlv: ProxyProtocolTLV

Additional information about the connection.

property peername: Tuple[str, int]

The source value in SockAddr form.

property sockname: Tuple[str, int]

The dest value in SockAddr form.

class proxyprotocol.result.ProxyResultIPv6(source, dest, *, protocol=None, tlv=ProxyProtocolTLV())[source]

The original connection was made with an IPv6 socket. The source and dest properties will contain a tuple of an IPv6Address and a port number.

Parameters:
  • source (Tuple[IPv6Address, int]) – The source address of the connection.

  • dest (Tuple[IPv6Address, int]) – The destination address of the connection.

  • protocol (Optional[SocketKind]) – The socket protocol (or type).

  • tlv (ProxyProtocolTLV) – Additional information about the connection.

property proxied: Literal[True]

True if the result should override the information in the underlying socket.

property source: Tuple[IPv6Address, int]

The original source address info for the connection.

property dest: Tuple[IPv6Address, int]

The original destination address info for the connection.

property protocol: SocketKind | None

The original socket protocol.

property tlv: ProxyProtocolTLV

Additional information about the connection.

property peername: Tuple[str, int, int, int]

The source value in SockAddr form.

property sockname: Tuple[str, int, int, int]

The dest value in SockAddr form.

class proxyprotocol.result.ProxyResultUnix(source, dest, *, protocol=None, tlv=ProxyProtocolTLV())[source]

The original connection was made with a UNIX socket. The source and dest properties will contain a the full path to the socket file.

Parameters:
  • source (str) – The source address file of the connection.

  • dest (str) – The destination address file of the connection.

  • protocol (Optional[SocketKind]) – The socket protocol (or type).

  • tlv (ProxyProtocolTLV) – Additional information about the connection.

property proxied: Literal[True]

True if the result should override the information in the underlying socket.

property source: str

The original source address info for the connection.

property dest: str

The original destination address info for the connection.

property protocol: SocketKind | None

The original socket protocol.

property tlv: ProxyProtocolTLV

Additional information about the connection.

property peername: str

The source value in SockAddr form.

property sockname: str

The dest value in SockAddr form.