
    hI                         S r SSKJrJrJr  SSKJr  SSKJr  SSK	J
r
   " S S\
R                  5      r " S S	5      r " S
 S\\
R                  5      rg)z2
Test cases for twisted.protocols.postfix module.
    )DictListTuple)StringTransport)postfix)unittestc                   "    \ rS rSr/ SQrS rSrg)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                     U R                    He  nUS   nUSS  nU R                  [        R                  " U5      US   5        U H)  nU R                  [        R                  " U5      U5        M+     Mg     g )Nr      )dataassertEqualr   quoteunquote)selfentryrawquotedqs        `/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_postfix.pytestData PostfixTCPMapQuoteTests.testData!   sd    YYE(C12YFW]]3/;  !3S9       N)__name__
__module____qualname____firstlineno__r   r   __static_attributes__r   r   r   r
   r
      s    D":r   r
   c                   ^    \ rS rSr% 0 r\\\4   \S'   / r\	\
\\4      \S'   S rS rS rSrg)	PostfixTCPMapServerTestCase+   r   chatc                    [         R                  " U R                  5      n[        5       n[         R                  " 5       nXl        Xl        UR                  U5        U R                   Ha  u  pEUR                  U5        U R                  UR                  5       USU< SU< SUR                  5       < 35        UR                  5         Mc     UR                  S5        g)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_chat%PostfixTCPMapServerTestCase.test_chat4   s     88C#%	..0""	*&*ii"E!!%(!/9??+<> OO '0 	D!r   c                    [         R                  " U R                  5      n[        5       n[         R                  " 5       nXl        Xl        UR                  U5        U R                   He  u  pEUR                  U5        U R                  UR                  5       USR                  XEUR                  5       5      5        UR                  5         Mg     UR                  S5        g)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/   r0   s         r   test_deferredChat-PostfixTCPMapServerTestCase.test_deferredChatM   s     AA$))L#%	..0""	*&*ii"E!!%(!6==IOO,= OO '0 	D!r   c                      " S S5      n[         R                  " 5       nU" 5       Ul        [        5       Ul        UR                  S5        U R                  UR                  R                  5       S5        g)zF
If the factory throws an exception,
error code 400 must be returned.
c                       \ rS rSrSrS rSrg)CPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactorym   z-
Factory that raises an error on key lookup.
c                     [        S5      e)NzThis is a test error)	Exception)r   keys     r   getGPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactory.getr   s     677r   r   N)r   r   r   r    __doc__rC   r!   r   r   r   ErrorFactoryr>   m   s    8r   rF   s   get examples   400 This is a test error
N)r   r(   r*   r   r1   r,   r   r-   )r   rF   servers      r   test_getException-PostfixTCPMapServerTestCase.test_getExceptiong   s^    	8 	8 ,,.%*,N+))//13PQr   r   N)r   r   r   r    r   r   bytes__annotations__r%   r   r   r5   r:   rH   r!   r   r   r   r#   r#   +   sE     D$ue|
 'D$uUE\"
# "2"4Rr   r#   c                   &    \ rS rSrSSS.r/ SQrSrg)
ValidTests|   s
   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 foorP   )s   put foo bar baz    500 put is not implemented yet.
)s   put foo barrQ   )s   get foos   200 ThisIs%20Foo
)s   get bars'   200 %20bar%20really%20is%20found%0D%0A
)s   get bazrO   )r   s   400 unknown command
r   N)r   r   r   r    r   r%   r!   r   r   r   rM   rM   |   s    +DDr   rM   N)rE   typingr   r   r   twisted.internet.testingr   twisted.protocolsr   twisted.trialr   TestCaser
   r#   rM   r   r   r   <module>rW      sQ    % $ 4 % ":h// :8NR NRb,h.?.? r   