%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/protocols/haproxy/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/protocols/haproxy/__pycache__/_wrapper.cpython-312.pyc

�

Ϫ�f]����dZddlmZmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	lmZdd
lmZGd�de	j$�ZGd
�de	j(�Zdej,defd�Zy)z@
Protocol wrapper that provides HAProxy PROXY protocol support.
�)�Optional�Union)�
interfaces)�_WrapperServerEndpoint)�policies�)�_info)�InvalidProxyHeader)�V1Parser)�V2Parserc���eZdZdZdej
dejf�fd�Zde	ddfd�Z
dejfd	�Zdejfd
�Z
�xZS)�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.
    �factory�wrappedProtocolc�B��t�|�||�d|_d|_y�N)�super�__init__�
_proxyInfo�_parser)�selfrr�	__class__s   ��D/usr/lib/python3/dist-packages/twisted/protocols/haproxy/_wrapper.pyrzHAProxyProtocolWrapper.__init__s"���	����/�2�59���8<����data�returnNc�>�|j�|jj|�S|j}|��t	|�dk\r<|ddt
jk(r&t|dd�dzdk(rt�x|_}nGt	|�dk\r(|ddtjk(rt�x|_}n|j�y	|j|�\|_}|r|jj|�yy#t$r|j�YywxYw)N���
��� ��)
rr�dataReceivedr�lenr�PREFIX�ordr�PROXYSTR�loseConnection�feedr
)rr�parser�	remainings    rr%z#HAProxyProtocolWrapper.dataReceived$s���?�?�&��'�'�4�4�T�:�:������>��D�	�R����"�I����0���R���$�z�1�T�9�(0�
�2���v��T��a��D��!�H��0A�0A�$A�(0�
�2���v��#�#�%��	"�)/���T�):�&�D�O�Y���$�$�1�1�)�<���!�	"����!�	"�s�6D�D�Dc���|jr,|jjr|jjS|jsJ�|jj�Sr)r�source�	transport�getPeer�rs rr1zHAProxyProtocolWrapper.getPeer=sD���?�?�t���5�5��?�?�)�)�)��~�~��~��~�~�%�%�'�'rc���|jr,|jjr|jjS|jsJ�|jj�Sr)r�destinationr0�getHostr2s rr5zHAProxyProtocolWrapper.getHostCsD���?�?�t���:�:��?�?�.�.�.��~�~��~��~�~�%�%�'�'r)�__name__�
__module__�__qualname__�__doc__r�WrappingFactoryr�	IProtocolr�bytesr%�IAddressr1r5�
__classcell__)rs@rrrs`����=��/�/�=�BL�BV�BV�=�"��"�4�"�2(��,�,�(�(��,�,�(rrc� �eZdZdZeZdefd�Zy)�HAProxyWrappingFactoryzL
    A Factory wrapper that adds PROXY protocol support to connections.
    rc���tjj|j�r|jj	�}n |jj
j}|�d�S)z�
        Annotate the wrapped factory's log prefix with some text indicating
        the PROXY protocol is in use.

        @rtype: C{str}
        z (PROXY))r�ILoggingContext�
providedBy�wrappedFactory�	logPrefixrr6)rrEs  rrEz HAProxyWrappingFactory.logPrefixQsV���%�%�0�0��1D�1D�E��+�+�5�5�7�I��+�+�5�5�>�>�I���H�%�%rN)r6r7r8r9r�protocol�strrE�rrr@r@Js���&�H�&�3�&rr@�wrappedEndpointrc�"�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@)rIs r�
proxyEndpointrK_s��"�/�3I�J�JrN)r9�typingrr�twisted.internetr�twisted.internet.endpointsr�twisted.protocolsr�r	�_exceptionsr
�	_v1parserr�	_v2parserr�ProtocolWrapperrr:r@�IStreamServerEndpointrKrHrr�<module>rVsg���#�'�=�&��+���3(�X�5�5�3(�l&�X�5�5�&�*K��5�5�K��Kr

Zerion Mini Shell 1.0