o
    ¯b  ã                   @   sˆ   d Z ddlmZmZ ddlmZmZmZmZ	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZdS )z1
Tests for L{twisted.protocols.haproxy._parser}.
é    )ÚTypeÚUnion)ÚTCP4ServerEndpointÚTCP6ServerEndpointÚUNIXServerEndpointÚ_parseÚ_WrapperServerEndpointÚserverFromString)ÚMemoryReactor)ÚSynchronousTestCaseé   )ÚunparseEndpoint)ÚHAProxyWrappingFactoryc                   @   s^   e Zd ZdZdeddfdd„Zddd„Zdd	d
„Zddd„Zddd„Z	ddd„Z
ddd„ZdS )ÚUnparseEndpointTestszg
    Tests to ensure that un-parsing an endpoint string round trips through
    escaping properly.
    ÚinputÚreturnNc                 C   s   |   tt|ƒŽ |¡ dS )aA  
        Check that the input unparses into the output, raising an assertion
        error if it doesn't.

        @param input: an input in endpoint-string-description format.  (To
            ensure determinism, keyword arguments should be in alphabetical
            order.)
        @type input: native L{str}
        N)ÚassertEqualr   ÚparseEndpoint)Úselfr   © r   úL/usr/lib/python3/dist-packages/twisted/protocols/haproxy/test/test_parser.pyÚcheck   s   
zUnparseEndpointTests.checkc                 C   ó   |   d¡ dS )z%
        An individual word.
        ÚwordN©r   ©r   r   r   r   Útest_basicUnparse)   ó   z&UnparseEndpointTests.test_basicUnparsec                 C   r   )z%
        Multiple arguments.
        zone:twoNr   r   r   r   r   Útest_multipleArguments/   r   z+UnparseEndpointTests.test_multipleArgumentsc                 C   r   )z$
        Keyword arguments.
        zaleph=one:bet=twoNr   r   r   r   r   Útest_keywords5   r   z"UnparseEndpointTests.test_keywordsc                 C   r   )z
        Escaped ":".
        zhello\:colon\:worldNr   r   r   r   r   Útest_colonInArgument;   r   z)UnparseEndpointTests.test_colonInArgumentc                 C   r   )z/
        Escaped ":" in keyword value.
        zhello=\:Nr   r   r   r   r   Útest_colonInKeywordValueA   r   z-UnparseEndpointTests.test_colonInKeywordValuec                 C   r   )z.
        Escaped ":" in keyword name.
        z\:=helloNr   r   r   r   r   Útest_colonInKeywordNameG   r   z,UnparseEndpointTests.test_colonInKeywordName©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r   r   r    r!   r"   r   r   r   r   r      s    




r   c                   @   sZ   e Zd ZdZdedeee ee ee	 f de
fdd„Zddd	„Zdd
d„Zddd„ZdS )ÚHAProxyServerParserTestsz@
    Tests that the parser generates the correct endpoints.
    ÚdescriptionÚexpectedClassr   c                 C   sJ   t ƒ }t||ƒ}|  |t¡ t|tƒsJ ‚|  |j|¡ |  |jt¡ |S )a%  
        Test the C{haproxy} enpdoint prefix against one sub-endpoint type.

        @param description: A string endpoint description beginning with
            C{haproxy}.
        @type description: native L{str}

        @param expectedClass: the expected sub-endpoint class given the
            description.
        @type expectedClass: L{type}

        @return: the parsed endpoint
        @rtype: L{IStreamServerEndpoint}

        @raise twisted.trial.unittest.Failtest: if the parsed endpoint doesn't
            match expectations.
        )	r
   r	   ÚassertIsInstancer   Ú
isinstanceÚ_wrappedEndpointÚassertIsÚ_wrapperFactoryr   )r   r*   r+   ÚreactorÚendpointr   r   r   Ú	onePrefixS   s   
z"HAProxyServerParserTests.onePrefixNc                 C   ó   |   dt¡ dS )zG
        Test if the parser generates a wrapped TCP4 endpoint.
        zhaproxy:tcp:8080N)r3   r   r   r   r   r   Ú	test_tcp4u   ó   z"HAProxyServerParserTests.test_tcp4c                 C   r4   )zG
        Test if the parser generates a wrapped TCP6 endpoint.
        zhaproxy:tcp6:8080N)r3   r   r   r   r   r   Ú	test_tcp6{   r6   z"HAProxyServerParserTests.test_tcp6c                 C   r4   )zG
        Test if the parser generates a wrapped UNIX endpoint.
        z haproxy:unix:address=/tmp/socketN)r3   r   r   r   r   r   Ú	test_unix�   r6   z"HAProxyServerParserTests.test_unixr#   )r$   r%   r&   r'   r(   r   r   r   r   r   r   r3   r5   r7   r8   r   r   r   r   r)   N   s"    þþÿý
ø
"
r)   N)r'   Útypingr   r   Útwisted.internet.endpointsr   r   r   r   r   r   r	   Útwisted.test.proto_helpersr
   Útwisted.trial.unittestr   ÚTestCaseÚ_parserr   Ú_wrapperr   r   r)   r   r   r   r   Ú<module>   s    7