
    \dK                         d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
  G d de
j                  Z G d d	          Z G d
 dee
j                  ZdS )z2
Test cases for twisted.protocols.postfix module.
    )DictListTuple)postfix)StringTransport)unittestc                       e Zd Zg dZd ZdS )PostfixTCPMapQuoteTests))   foor   )s   foo bars	   foo%20bar)s   foo	bars	   foo%09bar)s   foo
bars	   foo%0Abars	   foo%0abar)s   foo
bars   foo%0D%0Abars   foo%0D%0abars   foo%0d%0Abars   foo%0d%0abar)s   foo s   foo%20)s    foos   %20fooc                     | j         D ]o}|d         }|dd          }|                     t          j        |          |d                    |D ]*}|                     t          j        |          |           +pd S )Nr      )dataassertEqualr   quoteunquote)selfentryrawquotedqs        9lib/python3.11/site-packages/twisted/test/test_postfix.pytestDataz PostfixTCPMapQuoteTests.testData!   s    Y 	: 	:E(C122YFW]3//;;; : :  !3!3S9999:	: 	:    N)__name__
__module____qualname__r   r    r   r   r
   r
      s4          D": : : : :r   r
   c                   j    e Zd ZU i Zeeef         ed<   g Zee	eef                  ed<   d Z
d Zd ZdS )PostfixTCPMapServerTestCaser   chatc                    t          j        | j                  }t                      }t          j                    }||_        ||_        |                    |           | j        D ]r\  }}|	                    |           | 
                    |                                |d|d|d|                                           |                                 s|                    d           dS )z
        Test that I{get} and I{put} commands are responded to correctly by
        L{postfix.PostfixTCPMapServer} when its factory is an instance of
        L{postifx.PostfixTCPMapDictServerFactory}.
        zFor z, expected z	 but got N)r   PostfixTCPMapDictServerFactoryr   r   PostfixTCPMapServerservicefactorymakeConnectionr    lineReceivedr   valueclear
setTimeoutr   r%   	transportprotocolinputexpected_outputs         r   	test_chatz%PostfixTCPMapServerTestCase.test_chat4   s     8CC#%%	.00""	***&*i 	 	"E?!!%(((!!55///9??+<+<+<>   OOD!!!!!r   c                    t          j        | j                  }t                      }t          j                    }||_        ||_        |                    |           | j        D ]~\  }}|	                    |           | 
                    |                                |d                    |||                                                     |                                 |                    d           dS )z
        Test that I{get} and I{put} commands are responded to correctly by
        L{postfix.PostfixTCPMapServer} when its factory is an instance of
        L{postifx.PostfixTCPMapDeferringDictServerFactory}.
        z$For {!r}, expected {!r} but got {!r}N)r   'PostfixTCPMapDeferringDictServerFactoryr   r   r#   r$   r%   r&   r    r'   r   r(   formatr)   r*   r+   s         r   test_deferredChatz-PostfixTCPMapServerTestCase.test_deferredChatM   s     A$)LL#%%	.00""	***&*i 		 		"E?!!%(((!!6==?IOO,=,=    OOD!!!!!r   c                     G d d          }t          j                    } |            |_        t                      |_        |                    d           |                     |j                                        d           dS )z^
        If the factory throws an exception,
        error code 400 must be returned.
        c                       e Zd ZdZd ZdS )CPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactoryzE
            Factory that raises an error on key lookup.
            c                      t          d          )NzThis is a test error)	Exception)r   keys     r   getzGPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactory.getr   s     6777r   N)r   r   r   __doc__r;   r   r   r   ErrorFactoryr7   m   s-         8 8 8 8 8r   r=   s   get examples   400 This is a test error
N)r   r#   r%   r   r,   r'   r   r(   )r   r=   servers      r   test_getExceptionz-PostfixTCPMapServerTestCase.test_getExceptiong   s    	8 	8 	8 	8 	8 	8 	8 	8 ,..%*,,N+++)//113PQQQQQr   N)r   r   r   r   r   bytes__annotations__r    r   r   r0   r4   r?   r   r   r   r   r   +   s          D$ue|
   'D$uUE\"
#   " " "2" " "4R R R R Rr   r   c                        e Zd ZdddZg dZdS )
ValidTestss
   ThisIs Foos    bar really is found
)r   s   bar)
)s   gets&   400 Command 'get' takes 1 parameters.
)s   get foo bar   500 
)s   put&   400 Command 'put' takes 2 parameters.
)s   put foorE   )s   put foo bar baz    500 put is not implemented yet.
)s   put foo barrF   )s   get foos   200 ThisIs%20Foo
)s   get bars'   200 %20bar%20really%20is%20found%0D%0A
)s   get bazrD   )r   s   400 unknown command
N)r   r   r   r   r    r   r   r   rC   rC   |   s1        + D  DDDr   rC   N)r<   typingr   r   r   twisted.protocolsr   twisted.test.proto_helpersr   twisted.trialr   TestCaser
   r   rC   r   r   r   <module>rL      s    % $ $ $ $ $ $ $ $ $ % % % % % % 6 6 6 6 6 6 " " " " " ": : : : :h/ : : :8NR NR NR NR NR NR NR NRb    ,h.?     r   