HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/protocols/haproxy/__pycache__/_wrapper.cpython-38.pyc
U


W[��@s~dZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZGd	d
�d
ej
e�ZGdd�dej�Zd
d�ZdS)z@
Protocol wrapper that provides HAProxy PROXY protocol support.
�)�policies)�
interfaces)�_WrapperServerEndpoint�)�InvalidProxyHeader)�V1Parser)�V2Parserc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�HAProxyProtocolWrappera
    A Protocol wrapper that provides HAProxy support.

    This protocol reads the PROXY stream header, v1 or v2, parses the provided
    connection data, and modifies the behavior of getPeer and getHost to return
    the data provided by the PROXY header.
    cCs tj�|||�d|_d|_dS�N)r�ProtocolWrapper�__init__�
_proxyInfo�_parser)�self�factory�wrappedProtocol�r�D/usr/lib/python3/dist-packages/twisted/protocols/haproxy/_wrapper.pyrszHAProxyProtocolWrapper.__init__cCs�|jdk	r|j�|�S|jdkr�t|�dkr`|dd�tjkr`t|dd��d@dkr`t�|_n4t|�dkr�|dd�tj	kr�t�|_n|�
�dSz&|j�|�\|_}|r�|j�|�Wntk
r�|�
�YnXdS)N���
��� ��)
r
r�dataReceivedr�lenrZPREFIX�ordrZPROXYSTRZloseConnectionZfeedr)r�dataZ	remainingrrrr#s(


���

z#HAProxyProtocolWrapper.dataReceivedcCs |jr|jjr|jjS|j��Sr
)r
�source�	transport�getPeer�rrrrr!<szHAProxyProtocolWrapper.getPeercCs |jr|jjr|jjS|j��Sr
)r
Zdestinationr �getHostr"rrrr#BszHAProxyProtocolWrapper.getHostN)�__name__�
__module__�__qualname__�__doc__rrr!r#rrrrr	s
r	c@seZdZdZeZdd�ZdS)�HAProxyWrappingFactoryzL
    A Factory wrapper that adds PROXY protocol support to connections.
    cCs.tj�|j�r|j��}n
|jjj}d|fS)z�
        Annotate the wrapped factory's log prefix with some text indicating
        the PROXY protocol is in use.

        @rtype: C{str}
        z
%s (PROXY))rZILoggingContextZ
providedByZwrappedFactory�	logPrefix�	__class__r$)rr)rrrr)Os
z HAProxyWrappingFactory.logPrefixN)r$r%r&r'r	Zprotocolr)rrrrr(Isr(cCs
t|t�S)a�
    Wrap an endpoint with PROXY protocol support, so that the transport's
    C{getHost} and C{getPeer} methods reflect the attributes of the proxied
    connection rather than the underlying connection.

    @param wrappedEndpoint: The underlying listening endpoint.
    @type wrappedEndpoint: L{IStreamServerEndpoint}

    @return: a new listening endpoint that speaks the PROXY protocol.
    @rtype: L{IStreamServerEndpoint}
    )rr()ZwrappedEndpointrrr�
proxyEndpoint^sr+N)r'Ztwisted.protocolsrZtwisted.internetrZtwisted.internet.endpointsr�_exceptionsrZ	_v1parserrZ	_v2parserrr�objectr	ZWrappingFactoryr(r+rrrr�<module>s5