ó
    Ö›‘h]  ã                   óæ   • S r SSKJrJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJr  SS
KJr   " S S\	R$                  5      r " S S\	R(                  5      rS\R,                  S\4S jrg)z@
Protocol wrapper that provides HAProxy PROXY protocol support.
é    )ÚOptionalÚUnion)Ú
interfaces)Ú_WrapperServerEndpoint)Úpoliciesé   )Ú_info)ÚInvalidProxyHeader)ÚV1Parser)ÚV2Parserc                   ó¶   ^ • \ rS rSrSrS\R                  S\R                  4U 4S jjr	S\
SS4S	 jrS\R                  4S
 jrS\R                  4S jrSrU =r$ )ÚHAProxyProtocolWrapperé   zò
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                 ó@   >• [         TU ]  X5        S U l        S U l        g ©N)ÚsuperÚ__init__Ú
_proxyInfoÚ_parser)Úselfr   r   Ú	__class__s      €ÚfC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/protocols/haproxy/_wrapper.pyr   ÚHAProxyProtocolWrapper.__init__   s    ø€ ô 	‰Ñ˜Ô2Ø59ˆŒØ8<ˆ�ó    ÚdataÚreturnNc                 óX  • U R                   b  U R                  R                  U5      $ U R                  nUc–  [	        U5      S:¼  a>  US S [
        R                  :X  a'  [        USS 5      S-  S:X  a  [        5       =U l        nOI[	        U5      S:¼  a)  US S [        R                  :X  a  [        5       =U l        nOU R                  5         g  UR                  U5      u  U l         nU(       a  U R                  R                  U5        g g ! [         a    U R                  5          g f = f)Né   é   é   éð   é    é   é   )r   r   ÚdataReceivedr   Úlenr   ÚPREFIXÚordr   ÚPROXYSTRÚloseConnectionÚfeedr
   )r   r   ÚparserÚ	remainings       r   r'   Ú#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   Ã;D ÄD)Ä(D)c                 óà   • U R                   (       a1  U R                   R                  (       a  U R                   R                  $ U R                  (       d   eU R                  R                  5       $ r   )r   ÚsourceÚ	transportÚgetPeer©r   s    r   r4   ÚHAProxyProtocolWrapper.getPeer=   sD   € Ø�?�?˜tŸ™×5×5Ø—?‘?×)Ñ)Ð)Ø�~�~Ðˆ~Ø�~‰~×%Ñ%Ó'Ð'r   c                 óà   • U R                   (       a1  U R                   R                  (       a  U R                   R                  $ U R                  (       d   eU R                  R                  5       $ r   )r   Údestinationr3   ÚgetHostr5   s    r   r9   ÚHAProxyProtocolWrapper.getHostC   sD   € Ø�?�?˜tŸ™×:×:Ø—?‘?×.Ñ.Ð.Ø�~�~Ðˆ~Ø�~‰~×%Ñ%Ó'Ð'r   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚWrappingFactoryr   Ú	IProtocolr   Úbytesr'   ÚIAddressr4   r9   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      se   ø† ñð=Ø×/Ñ/ð=ØBL×BVÑBV÷=ð" ð "¨4ô "ð2(˜×,Ñ,ô (ð(˜×,Ñ,÷ (ò (r   r   c                   ó*   • \ rS rSrSr\rS\4S jrSr	g)ÚHAProxyWrappingFactoryéJ   zD
A Factory wrapper that adds PROXY protocol support to connections.
r   c                 óÞ   • [         R                  R                  U R                  5      (       a  U R                  R	                  5       nO U R                  R
                  R                  nU S3$ )zs
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Ú	logPrefixr   r;   )r   rM   s     r   rM   Ú HAProxyWrappingFactory.logPrefixQ   sY   € ô ×%Ñ%×0Ñ0°×1DÑ1D×EÑEØ×+Ñ+×5Ñ5Ó7‰Ià×+Ñ+×5Ñ5×>Ñ>ˆIØ�˜HÐ%Ð%r   © N)
r;   r<   r=   r>   r?   r   ÚprotocolÚstrrM   rD   rO   r   r   rG   rG   J   s   † ñð &€Hð&˜3÷ &r   rG   ÚwrappedEndpointr   c                 ó"   • [        U [        5      $ )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}
)r   rG   )rR   s    r   ÚproxyEndpointrT   _   s   € ô " /Ô3IÓJÐJr   N)r?   Útypingr   r   Útwisted.internetr   Útwisted.internet.endpointsr   Útwisted.protocolsr   Ú r	   Ú_exceptionsr
   Ú	_v1parserr   Ú	_v2parserr   ÚProtocolWrapperr   r@   rG   ÚIStreamServerEndpointrT   rO   r   r   Ú<module>r_      sg   ðñ÷ #å 'Ý =Ý &Ý Ý +Ý Ý ô3(˜X×5Ñ5ô 3(ôl&˜X×5Ñ5ô &ð*KØ×5Ñ5ðKàõKr   