
    Vh                         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
e      Z G d de      Zy)z1
Tests for L{twisted.protocols.haproxy._parser}.
    )TypeUnion)TCP4ServerEndpointTCP6ServerEndpointUNIXServerEndpoint_parse_WrapperServerEndpointserverFromString)MemoryReactor)SynchronousTestCase   )unparseEndpoint)HAProxyWrappingFactoryc                   P    e Zd ZdZdeddfdZddZddZddZdd	Z	dd
Z
ddZy)UnparseEndpointTestszg
    Tests to ensure that un-parsing an endpoint string round trips through
    escaping properly.
    inputreturnNc                 F    | j                  t        t        |       |       y)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   s     Z/home/dcms/DCMS/lib/python3.12/site-packages/twisted/protocols/haproxy/test/test_parser.pycheckzUnparseEndpointTests.check   s     	-*>?G    c                 &    | j                  d       y)z%
        An individual word.
        wordNr   r   s    r   test_basicUnparsez&UnparseEndpointTests.test_basicUnparse)   s     	

6r   c                 &    | j                  d       y)z%
        Multiple arguments.
        zone:twoNr   r   s    r   test_multipleArgumentsz+UnparseEndpointTests.test_multipleArguments/   s     	

9r   c                 &    | j                  d       y)z$
        Keyword arguments.
        zaleph=one:bet=twoNr   r   s    r   test_keywordsz"UnparseEndpointTests.test_keywords5   s     	

&'r   c                 &    | j                  d       y)z
        Escaped ":".
        zhello\:colon\:worldNr   r   s    r   test_colonInArgumentz)UnparseEndpointTests.test_colonInArgument;   s     	

*+r   c                 &    | j                  d       y)z/
        Escaped ":" in keyword value.
        zhello=\:Nr   r   s    r   test_colonInKeywordValuez-UnparseEndpointTests.test_colonInKeywordValueA        	

;r   c                 &    | j                  d       y)z.
        Escaped ":" in keyword name.
        z\:=helloNr   r   s    r   test_colonInKeywordNamez,UnparseEndpointTests.test_colonInKeywordNameG   r(   r   r   N)__name__
__module____qualname____doc__strr   r   r!   r#   r%   r'   r*    r   r   r   r      s;    

H3 
H4 
H(,  r   r   c                   Z    e Zd ZdZdedeee   ee   ee	   f   de
fdZd
dZd
dZd
d	Zy)HAProxyServerParserTestsz@
    Tests that the parser generates the correct endpoints.
    descriptionexpectedClassr   c                     t               }t        ||      }| j                  |t               t	        |t              sJ | j                  |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   r4   r5   reactorendpoints        r   	onePrefixz"HAProxyServerParserTests.onePrefixS   si    4  /#G[9h(>?($:;;;h77Gh..0FGr   Nc                 0    | j                  dt               y)zG
        Test if the parser generates a wrapped TCP4 endpoint.
        zhaproxy:tcp:8080N)r>   r   r   s    r   	test_tcp4z"HAProxyServerParserTests.test_tcp4u   s     	)+=>r   c                 0    | j                  dt               y)zG
        Test if the parser generates a wrapped TCP6 endpoint.
        zhaproxy:tcp6:8080N)r>   r   r   s    r   	test_tcp6z"HAProxyServerParserTests.test_tcp6{   s     	*,>?r   c                 0    | j                  dt               y)zG
        Test if the parser generates a wrapped UNIX endpoint.
        z haproxy:unix:address=/tmp/socketN)r>   r   r   s    r   	test_unixz"HAProxyServerParserTests.test_unix   s     	9;MNr   r+   )r,   r-   r.   r/   r0   r   r   r   r   r   r	   r>   r@   rB   rD   r1   r   r   r3   r3   N   s_       #$#$#$&
  
  D?@Or   r3   N)r/   typingr   r   twisted.internet.endpointsr   r   r   r   r   r	   r
   twisted.internet.testingr   twisted.trial.unittestr   TestCase_parserr   _wrapperr   r   r3   r1   r   r   <module>rL      sB      3 B % -4 8 4 n7Ox 7Or   