Current File : //lib/python3/dist-packages/twisted/protocols/haproxy/__pycache__/_v1parser.cpython-312.pyc |
�
Ϫ�f� � � � d Z ddlmZmZ ddlmZ ddlmZ ddlm Z m
Z
ddlmZm
Z
mZmZ ee
j � G d� d � � Zy
)zD
IProxyParser implementation for version one of the PROXY protocol.
� )�Tuple�Union)�implementer)�address� )�_info�_interfaces)�InvalidNetworkProtocol�InvalidProxyHeader�MissingAddressData�convertErrorc � � e Zd ZdZdZdZdZdZeeefZdZ dd �Z
d
edee
ej ef e
d f fd�Zed
edej fd�� Zy)�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.
s PROXYs UNKNOWNs TCP4s TCP6s
�returnNc � � d| _ y )N� )�buffer)�selfs �E/usr/lib/python3/dist-packages/twisted/protocols/haproxy/_v1parser.py�__init__zV1Parser.__init__, s � ���r �data�NNc � � | xj |z
c_ t | j � dkD r"| j | j vr
t � �| j j | j d� }t |� dkD syd| _ |j � }|j � }| j
|� }||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.
�k r r r )r �len�NEWLINEr �split�pop�parse)r r �lines� remaining�header�infos r �feedz
V1Parser.feed/ s� � �"