%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__/_v2parser.cpython-312.pyc

�

Ϫ�f����dZddlZddlZddlmZmZmZmZddlm	Z	ddl
mZmZddlm
Z
ddlmZddlmZd	d
lmZmZd	dlmZmZmZmZGd�d
e�ZGd�de�ZdZdZdZdZe	ej@�Gd�d��Z!y)zD
IProxyParser implementation for version two of the PROXY protocol.
�N)�Callable�Tuple�Type�Union)�implementer)�
ValueConstant�Values)�Literal)�address)�compat�)�_info�_interfaces)�InvalidNetworkProtocol�InvalidProxyHeader�MissingAddressData�convertErrorc�P�eZdZdZed�Zed�Zed�Zed�Zy)�	NetFamilyz(
    Values for the 'family' field.
    r�� �0N)	�__name__�
__module__�__qualname__�__doc__r�UNSPEC�INET�INET6�UNIX���E/usr/lib/python3/dist-packages/twisted/protocols/haproxy/_v2parser.pyrrs1����4�
 �F����D��$��E����Dr"rc�@�eZdZdZed�Zed�Zed�Zy)�NetProtocolz&
    Values for 'protocol' field.
    rr
�N)rrrrrr�STREAM�DGRAMr!r"r#r%r%)s'����1�
�F�
�1�
�F��!��Er"r%����LOCAL�PROXYc���eZdZdZdZdgZeed�Zddddddd�Z	dd�Z
ded	ee
ejefe
d
ffd�Zeded	efd��Zeded	efd��Zeded	ejfd��Zy
)�V2Parserzn
    PROXY protocol version two header parser.

    Version two of the PROXY protocol is a binary format.
    s


QUIT
r)rr
z!4s4s2Hz	!16s16s2Hz	!108s108s)���!�"�1�2�returnNc��d|_y)Nr")�buffer)�selfs r#�__init__zV2Parser.__init__Ps	����r"�data�NNc�h�|xj|z
c_t|j�dkr
t��tjd|jdd�ddz}t|j�|kry|jd||j|d}}d|_|j|�}||fS)a�
        Consume a chunk of data and attempt to parse it.

        @param data: A bytestring.
        @type data: 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.
        rz!H�rr;Nr")r7�lenr�struct�unpack�parse)r8r:�size�header�	remaining�infos      r#�feedz
V2Parser.feedSs���"	
���t����t�{�{��b� �$�&�&��}�}�T�4�;�;�r�"�#5�6�q�9�B�>���t�{�{��d�"�� �K�K���.����D�E�0B�	������z�z�&�!���i� � r"�
bytestringc�X�djd�tj|�D��S)a7
        Convert packed 32-bit IPv4 address bytes into a dotted-quad ASCII bytes
        representation of that address.

        @param bytestring: 4 octets representing an IPv4 address.
        @type bytestring: L{bytes}

        @return: a dotted-quad notation IPv4 address.
        @rtype: L{bytes}
        �.c3�XK�|]"}dt|�fzjd����$y�w)z%i�asciiN)�ord�encode)�.0�bs  r#�	<genexpr>z(V2Parser._bytesToIPv4.<locals>.<genexpr>}s+����
�34�T�S��V�I�
�%�%�g�.�
�s�(*)�joinr�	iterbytes)rGs r#�_bytesToIPv4zV2Parser._bytesToIPv4qs-���y�y�
�8>�8H�8H��8T�
�
�	
r"c�x��tj|��dj�fd�tddd�D��S)a=
        Convert packed 128-bit IPv6 address bytes into a colon-separated ASCII
        bytes representation of that address.

        @param bytestring: 16 octets representing an IPv6 address.
        @type bytestring: L{bytes}

        @return: a dotted-quad notation IPv6 address.
        @rtype: L{bytes}
        �:c3�d�K�|]'}t�||dzd�d�jd����)y�w)�r�xrKN)�intrM)rNrO�	hexStrings  �r#rPz(V2Parser._bytesToIPv6.<locals>.<genexpr>�s;�����
���I�a�!�a�%�(�"�-�a�0�9�9�'�B�
�s�-0rrrW)�binascii�b2a_hexrQ�range)rGrZs @r#�_bytesToIPv6zV2Parser._bytesToIPv6�s;����$�$�Z�0�	��y�y�
��1�b�!�_�
�
�	
r"�linec
��|dd}d}ttt�5t|dd�}t|dd�}ddd�||jk7r
t��t
z|tz}}||jvs||jvr
t��|j|tk(rtj|dd�St
z|tz}	}ttt�5tj|�}t j|	�}	ddd�|tj"us|	t j"urtj|dd�S|j$|}
|ddt'j(|
�z}|tj*ur�tt&j,t.�5t'j0|
|�\}}ddd�tj|t3j4j7d��t3j4j7d���Sd}
|	t j8urd}
t2j:}|j<}|tj>urt2j@}|jB}tt&j,t.�5t'j0|
|�}|\}}}}ddd�tj|||
|�jE��||
|�jE���S#1swY���xYw#1swY��xYw#1swY��rxYw#1swY�xYw)	a�
        Parse a bytestring as a full PROXY protocol header.

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

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

        @raises InvalidProxyHeader: If the bytestring does not represent a
            valid PROXY header.
        N��
r=r��TCP�UDP)#r�
IndexErrorrrL�PREFIX�_HIGH�_LOW�VERSIONS�COMMANDS�
_LOCALCOMMANDr�	ProxyInfo�
ValueErrorrr�
lookupByValuer%r�ADDRESSFORMATSr?�calcsizer �errorrr@r�UNIXAddress�rstripr(�IPv4AddressrSr�IPv6Addressr^�decode)�clsr_�prefix�addrInfo�versionCommand�familyProto�version�command�family�netproto�
addressFormat�source�dest�addrType�addrCls�
addrParserrE�sPort�dPorts                   r#rAzV2Parser.parse�s����c�r�����
�*�&8�
9�	+�!��b���-�N��d�2�b�k�*�K�		+��S�Z�Z��$�&�&�)�E�1�>�D�3H����#�,�,�&�'����*E�$�&�&��<�<�� �M�1��?�?�4��t�4�4�&��.��d�0B���
�*�&<�
=�	;��,�,�V�4�F�"�0�0��:�H�	;��Y�%�%�%��[�5G�5G�)G��?�?�4��t�4�4��*�*�;�7�
���R�&�/�/�-�"@�@�A���Y�^�^�#��f�l�l�,>�?�
F�%�}�}�]�H�E����
F��?�?���#�#�F�M�M�'�$:�;��#�#�D�K�K��$8�9��
�;@���{�(�(�(��H�
���	�03�/?�/?�
��Y�_�_�$��)�)�G��)�)�J�
�&�,�,�(:�
;�	.��=�=���9�D�)-�&�F�D�%��	.������H�j��0�7�7�9�5�A��H�j��.�5�5�7��?�
�	
�c	+�	+��"	;�	;��
F�
F��&	.�	.�s/�L�%+L*�-L7�(M�L'�*L4�7M�M
)r5N)rrrrrgrjrl�
_PROXYCOMMANDrkrpr9�bytesrrrrmrF�staticmethodrSr^�classmethodrAr!r"r#r.r.9s����A�F��t�H� �]�3�H�
������
�N��!��!�	�u�U�_�_�e�+�,�e�J�.?�?�	@�!�<�

��

�5�

��

��
��
�5�
��
�"�E
��E
�5�?�?�E
��E
r"r.)"rr[r?�typingrrrr�zope.interfacer�
constantlyrr	r
�twisted.internetr�twisted.pythonr�rr�_exceptionsrrrrrr%rhrirlr��IProxyParserr.r!r"r#�<module>r�s�����
�/�/�&�,��$�!� �������&��	�����
��
�
�[�
%�
%�&�_
�_
�'�_
r"

Zerion Mini Shell 1.0