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__/_v1parser.cpython-38.pyc
U


W[��@sjdZddlmZddlmZddlmZmZmZm	Z	ddl
mZddl
mZeej
�Gdd	�d	e��Zd
S)zD
IProxyParser implementation for version one of the PROXY protocol.
�)�implementer)�address�)�convertError�InvalidProxyHeader�InvalidNetworkProtocol�MissingAddressData)�_info)�_interfacesc@sJeZdZdZdZdZdZdZeeefZdZ	dd�Z
d	d
�Zedd��Z
d
S)�V1Parserz�
    PROXY protocol version one header parser.

    Version one of the PROXY protocol is a human readable format represented
    by a single, newline delimited binary string that contains all of the
    relevant source and destination data.
    sPROXYsUNKNOWNsTCP4sTCP6s
cCs
d|_dS)N�)�buffer)�self�r�E/usr/lib/python3/dist-packages/twisted/protocols/haproxy/_v1parser.py�__init__+szV1Parser.__init__cCsv|j|7_t|j�dkr.|j|jkr.t��|j�|jd�}t|�dksNdSd|_|��}|��}|�|�}||fS)a�
        Consume a chunk of data and attempt to parse it.

        @param data: A bytestring.
        @type data: L{bytes}

        @return: A two-tuple containing, in order, a
            L{_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 InvalidProxyHeader: If the bytes fed to the parser create an
            invalid PROXY header.
        �kr)NNr)r
�len�NEWLINEr�split�pop�parse)r�data�linesZ	remaining�header�inforrr�feed/s
z
V1Parser.feedc	
Cs�|}d}d}d}d}d}d}ttt��|�dd�\}}W5QRX||jkrRt��ttt��|�dd�\}}W5QRX||jkr�t��||jkr�t�	|dd�Sttt
��|�dd�\}}W5QRXttt
��|�dd�\}}W5QRXttt
��|�dd�\}}W5QRXttt
��|�d�d}W5QRX||jk�rlt�	|t�
d|t|��t�
d|t|���St�	|t�d|t|��t�d|t|���S)a�
        Parse a bytestring as a full PROXY protocol header line.

        @param line: A bytestring that represents a valid HAProxy PROXY
            protocol header line.
        @type line: bytes

        @return: A L{_interfaces.IProxyInfo} containing the parsed data.

        @raises InvalidProxyHeader: If the bytestring does not represent a
            valid PROXY header.

        @raises InvalidNetworkProtocol: When no protocol can be parsed or is
            not one of the allowed values.

        @raises MissingAddressData: When the protocol is TCP* but the header
            does not contain a complete set of addresses and ports.
        N� rrZTCP)r�
ValueErrorrr�PROXYSTRr�ALLOWED_NET_PROTOS�
UNKNOWN_PROTOr	Z	ProxyInfor�
TCP4_PROTOrZIPv4Address�intZIPv6Address)	�cls�lineZoriginalLineZproxyStrZnetworkProtocolZ
sourceAddrZ
sourcePortZdestAddrZdestPortrrrrKsH


��zV1Parser.parseN)�__name__�
__module__�__qualname__�__doc__rr!r"Z
TCP6_PROTOr rrr�classmethodrrrrrrs�rN)r)Zzope.interfacerZtwisted.internetr�_exceptionsrrrr�r	r
ZIProxyParser�objectrrrrr�<module>s