
    Vh)                         d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      Zy)z+
Tests for L{twisted.words.im.ircsupport}.
    )StringTransport)ChatUIConversationGroupConversation)
IRCAccountIRCProto)OfflineError)IRCTestCasec                       e Zd Zd Zd Zy)StubConversationc                      y N selfs    R/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/test/test_ircsupport.pyshowzStubConversation.show           c                      || _         || _        y r   )messagemetadata)r   r   r   s      r   showMessagezStubConversation.showMessage   s     r   N)__name__
__module____qualname__r   r   r   r   r   r   r      s    !r   r   c                        e Zd Zd Zd ZddZy)StubGroupConversationc                      || _         || _        y r   )topic
topicSetBy)r   r    nicknames      r   setTopiczStubGroupConversation.setTopic   s    
"r   c                      y r   r   r   s    r   r   zStubGroupConversation.show   r   r   Nc                 .    || _         || _        || _         y r   )r   text)r   senderr&   r   s       r   showGroupMessagez&StubGroupConversation.showGroupMessage    s     	 r   r   )r   r   r   r#   r   r(   r   r   r   r   r      s    #!r   r   c                   $    e Zd ZedfdZedfdZy)
StubChatUIr   c                 2    t        j                  | |||      S r   r   getGroupConversationr   groupClass
stayHiddens       r   getConversationzStubChatUI.getConversation'       **4zJJr   c                 2    t        j                  | |||      S r   r,   r.   s       r   r-   zStubChatUI.getGroupConversation*   r3   r   N)r   r   r   r   r2   r   r-   r   r   r   r*   r*   &   s    +; K 1FRS Kr   r*   c                       e Zd ZdZddZddZddZddZddZddZ	dd	Z
dd
ZddZddZddZddZddZddZddZy)IRCProtoTestsz 
    Tests for L{IRCProto}.
    Nc                     t        dddd dd      | _        t        | j                  t               d       | _        t               | _        y )NzSome accountFalicezexample.comi  )r   accountr   r*   protor   	transportr   s    r   setUpzIRCProtoTests.setUp3   s=    !E7D-
 dllJL$?
(*r   c                     | j                   j                  | j                         | j                  | j                  j	                         d       y)z
        When L{IRCProto} is connected to a transport, it sends I{NICK} and
        I{USER} commands with the username from the account object.
        z1NICK alice
USER alice foo bar :Twisted-IM user
N)r:   makeConnectionr;   assertEqualBufferValuevaluer   s    r   
test_loginzIRCProtoTests.test_login:   s;    
 	

!!$..1##NN  "F	
r   c                     d| j                   _        | j                  j                  | j                         | j                  | j                  j                         d       y)z
        If created with an account with a password, L{IRCProto} sends a
        I{PASS} command before the I{NICK} and I{USER} commands.
        secretz>PASS secret
NICK alice
USER alice foo bar :Twisted-IM user
N)r9   passwordr:   r>   r;   r?   r@   r   s    r   test_authenticatezIRCProtoTests.test_authenticateE   sI    
 !)

!!$..1##NN  "6	
r   c                     ddg| j                   _        | j                  j                  | j                         | j                  | j                  j                         d       y)z
        If created with an account with a list of channels, L{IRCProto}
        joins each of those channels after registering.
        #fooz#barzGNICK alice
USER alice foo bar :Twisted-IM user
JOIN #foo
JOIN #bar
N)r9   channelsr:   r>   r;   r?   r@   r   s    r   test_channelszIRCProtoTests.test_channelsS   sN    
 "( 0

!!$..1##NN  "	
r   c                     | j                   j                  | j                         | j                   j                  d       | j	                  d| j                   j
                  j                  d             y)z
        L{IRCProto} can interpret I{ISUPPORT} (I{005}) messages from the server
        and reflect their information in its C{supported} attribute.
        z3:irc.example.com 005 alice MODES=4 CHANLIMIT=#:20
   MODESN)r:   r>   r;   dataReceivedassertEqual	supported
getFeaturer   s    r   test_isupportzIRCProtoTests.test_isupportb   sR    
 	

!!$..1

 WXDJJ00;;GDEr   c                    | j                   j                  | j                         | j                   j                  d       | j                   j                  d       | j                   j                  d       | j                   j                  d       | j	                  d| j                   j
                         | j                  d| j                   j
                         y)zB
        IRC NICK command changes the nickname of a user.
        z:alice JOIN #group1
:alice1 JOIN #group1
z:alice1 NICK newnick
z:alice3 NICK newnick3
newnickalice1Nr:   r>   r;   rM   assertIn	_ingroupsassertNotInr   s    r   	test_nickzIRCProtoTests.test_nickk   s     	

!!$..1

 9:

 :;

 :;

 ;<i!5!564::#7#78r   c                 n   | j                   j                  | j                         | j                   j                  d       | j	                  d| j                   j
                  d          | j                  d| j                   j
                  d          | j                   j                  d       | j                   j                  d       | j                   j                  d       | j                  d| j                   j
                  d          | j                  d| j                   j
                  d          y)	zF
        IRC PART command removes a user from an IRC channel.
        rS   group1rU   group2z:alice PART #group1
z:alice1 PART #group1
z:alice1 PART #group2
NrV   r   s    r   	test_partzIRCProtoTests.test_partw   s     	

!!$..1

 :;h

 4 4X >?4::#7#7#AB

 9:

 :;

 :;4::#7#7#AB4::#7#7#ABr   c                    | j                   j                  | j                         | j                   j                  d       | j	                  d| j                   j
                  d          | j                  d| j                   j
                  d          | j                   j                  d       | j	                  d| j                   j
                  d          | j                   j                  d       | j                  t        | j                   j
                  d         dk(         | j                   j                  d	       y
)zH
        IRC QUIT command removes a user from all IRC channels.
        rS   r\   rU   r]   z:alice1 JOIN #group3
group3z:alice1 QUIT
r   z:alice3 QUIT
N)	r:   r>   r;   rM   rW   rX   rY   
assertTruelenr   s    r   	test_quitzIRCProtoTests.test_quit   s     	

!!$..1

 :;h

 4 4X >?4::#7#7#AB

 :;h

 4 4X >?

 23DJJ00:;q@A

 23r   c                 `   | j                   j                  | j                         | j                   j                  d       | j                   j                  d       | j                   j	                  d      }| j                  |j                  d       | j                  |j                  d       y)zH
        IRC TOPIC command changes the topic of an IRC channel.
        rS   z :alice1 TOPIC #group1 newtopic
r\   newtopicrU   N)r:   r>   r;   rM   r-   rN   r    r!   )r   groupConversations     r   
test_topiczIRCProtoTests.test_topic   s     	

!!$..1

 :;

 DE JJ;;HE*00*=*55x@r   c                 f   | j                   j                  | j                         | j                   j                  d       | j                   j                  j                  | j                   j                  d            }| j                  |j                  d       | j                   j                  d       | j                   j                  d      }| j                  |j                  d       | j                   j                  d       | j                   j                  d       | j                   j                  d	      }| j                  t        |d
             | j                   j                  j                  | j                   j                  d            }| j                  t        |d             y)zG
        PRIVMSG sends a private message to a user or channel.
        z#:alice1 PRIVMSG t2 test_message_1
rU   test_message_1z(:alice1 PRIVMSG #group1 test_message_2
r\   test_message_2r8   z$:alice PRIVMSG #foo test_message_3
foor&   r   Nr:   r>   r;   rM   chatr2   	getPersonrN   r   r-   r&   setNickassertFalsehasattrr   conversationrf   s      r   test_privmsgzIRCProtoTests.test_privmsg   s7    	

!!$..1

 GHzz66tzz7K7KH7UV--/?@

 LM JJ;;HE*//1AB

7#

 HI JJ;;EB!2F;<zz66tzz7K7KG7TUy9:r   c                 f   | j                   j                  | j                         | j                   j                  d       | j                   j                  j                  | j                   j                  d            }| j                  |j                  d       | j                   j                  d       | j                   j                  d      }| j                  |j                  d       | j                   j                  d       | j                   j                  d       | j                   j                  d	      }| j                  t        |d
             | j                   j                  j                  | j                   j                  d            }| j                  t        |d             y)z3
        CTCP ACTION to a user or channel.
        z):alice1 PRIVMSG alice1 :ACTION smiles
rU   smilesz*:alice1 PRIVMSG #group1 :ACTION laughs
r\   laughsr8   z(:alice PRIVMSG #group1 :ACTION cries
rk   r&   r   Nrl   rr   s      r   test_actionzIRCProtoTests.test_action   s5    	

!!$..1

 QRzz66tzz7K7KH7UV--x8

 RS JJ;;HE*//:

7#

 PQ JJ;;EB!2F;<zz66tzz7K7KG7TUy9:r   c                 8   | j                   j                  | j                         | j                   j                  d       dgdgdgdgdgd}dg di}| j	                  || j                   j
                         | j	                  || j                   j                         | j                   j                  d       | j	                  i | j                   j                         | j                   j                  d      }| j	                  |d   |j                         y)z
        RPL_NAMREPLY server response (353) lists all the users in a channel.
        RPL_ENDOFNAMES server response (363) is sent at the end of RPL_NAMREPLY
        to indicate that there are no more names.
        z>:example.com 353 z3p = #bnl :pSwede Dan- SkOyg @MrOp +MrPlus
bnl)Dan-pSwedeSkOygMrOpMrPlus)r|   r{   r}   r~   r   z1:example.com 366 alice #bnl :End of /NAMES list
N)	r:   r>   r;   rM   rN   rX   _namrepliesr-   members)r   expectedInGroupsexpectedNamRepliesrf   s       r   test_rplNamreplyzIRCProtoTests.test_rplNamreply   s     	

!!$..1

N	
 GgWGg
 $%RS)4::+?+?@+TZZ-C-CD

 UVTZZ334 JJ;;EB+E24E4M4MNr   c                     | j                   j                  | j                         | j                   j                  d       | j	                  d| j                   j
                  d          y)z[
        RPL_TOPIC server response (332) is sent when a channel's topic is changed
        z1:example.com 332 alice, #foo :Some random topic
zSome random topicrk   N)r:   r>   r;   rM   rN   _topicsr   s    r   test_rplTopiczIRCProtoTests.test_rplTopic   sM     	

!!$..1

 UV,djj.@.@.GHr   c                 ~   | j                   j                  | j                         | j                   j                  d      }| j	                  t
        |j                  d       | j                   |j                  _        | j                  j                          |j                  d       | j                  | j                  j                  j                         d       | j                  j                          |j                  dddi       | j                  | j                  j                  j                         d       y	)
z*
        L{IRCPerson.sendMessage}
        r8   Some messageSome message 2s   PRIVMSG alice :Some message 2
rv   styleemotes    PRIVMSG alice :ACTION smiles
N)r:   r>   r;   rn   assertRaisesr	   sendMessager9   clientclearrN   iogetvalue)r   persons     r   test_sendMessagezIRCProtoTests.test_sendMessage   s     	

!!$..1%%g.,(:(:NK $

+,NN&&(*N	
 	8gw%78NN&&(*U	
r   c                    | j                   j                  | j                         | j                   j                  j	                  d| j                         }| j                  t        |j                  d       | j                   |j                  _	        | j                  j                          |j                  d       | j                  | j                  j                  j                         d       | j                  j                          |j                  dddi       | j                  | j                  j                  j                         d       y	)
z.
        L{IRCGroup.sendGroupMessage}
        rG   r   r   s   PRIVMSG #foo :Some message 2
rv   r   r   s   PRIVMSG #foo :ACTION smiles
N)r:   r>   r;   rm   getGroupr   r	   sendGroupMessager9   r   r   rN   r   r   )r   r/   s     r   test_sendGroupMessagez#IRCProtoTests.test_sendGroupMessage   s     	

!!$..1

((<,(>(>O#zz/0NN&&(*M	
 	x'7);<NN&&(*T	
r   )returnN)r   r   r   __doc__r<   rA   rE   rI   rQ   rZ   r^   rc   rg   rt   rx   r   r   r   r   r   r   r   r6   r6   .   sW    +	


F
9C4	A;(;(O4I
*
r   r6   N)r   twisted.internet.testingr   twisted.words.im.basechatr   r   r   twisted.words.im.ircsupportr   r   twisted.words.im.localsr	   twisted.words.test.test_ircr
   r   r   r*   r6   r   r   r   <module>r      sS    5 M M < 0 3!| !!- !K Kb
K b
r   