
    Yf)                         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dS )z+
Tests for L{twisted.words.im.ircsupport}.
    )StringTransport)ChatUIConversationGroupConversation)
IRCAccountIRCProto)OfflineError)IRCTestCasec                       e Zd Zd Zd ZdS )StubConversationc                     d S N selfs    T/var/www/html/env/lib/python3.11/site-packages/twisted/words/test/test_ircsupport.pyshowzStubConversation.show           c                 "    || _         || _        d S r   )messagemetadata)r   r   r   s      r   showMessagezStubConversation.showMessage   s     r   N)__name__
__module____qualname__r   r   r   r   r   r   r      s2          ! ! ! ! !r   r   c                   "    e Zd Zd Zd ZddZdS )StubGroupConversationc                 "    || _         || _        d S r   )topic
topicSetBy)r   r    nicknames      r   setTopiczStubGroupConversation.setTopic   s    
"r   c                     d S r   r   r   s    r   r   zStubGroupConversation.show   r   r   Nc                 0    || _         || _        || _         d S 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      sF        # # #  ! ! ! ! ! !r   r   c                   &    e Zd ZedfdZedfdZdS )
StubChatUIr   c                 0    t          j        | |||          S r   r   getGroupConversationr   groupClass
stayHiddens       r   getConversationzStubChatUI.getConversation'       *4zJJJr   c                 0    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*   &   sT        +; K K K K 1FRS K K K K K 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dS )IRCProtoTestsz 
    Tests for L{IRCProto}.
    returnNc                     t          dddd dd          | _        t          | j        t                      d           | _        t                      | _        d S )NzSome accountFalicezexample.comi  )r   accountr   r*   protor   	transportr   s    r   setUpzIRCProtoTests.setUp3   sL    !E7D-
 
 dlJLL$??
(**r   c                     | j                             | j                   |                     | j                                        d           dS )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:   sR    
 	
!!$.111##N  ""F	
 	
 	
 	
 	
r   c                     d| j         _        | j                            | j                   |                     | j                                        d           dS )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)r:   passwordr;   r?   r<   r@   rA   r   s    r   test_authenticatezIRCProtoTests.test_authenticateE   s^    
 !)
!!$.111##N  ""6	
 	
 	
 	
 	
r   c                     ddg| j         _        | j                            | j                   |                     | j                                        d           dS )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)r:   channelsr;   r?   r<   r@   rA   r   s    r   test_channelszIRCProtoTests.test_channelsS   sc    
 "( 0
!!$.111##N  ""	
 	
 	
 	
 	
r   c                     | j                             | j                   | j                             d           |                     d| j         j                            d                     dS )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   sb    
 	
!!$.111
 WXXXDJ0;;GDDEEEEEr   c                    | j                             | j                   | j                             d           | j                             d           | j                             d           | j                             d           |                     d| j         j                   |                     d| j         j                   dS )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<   rN   assertIn	_ingroupsassertNotInr   s    r   	test_nickzIRCProtoTests.test_nickk   s     	
!!$.111
 9:::
 :;;;
 :;;;
 ;<<<i!56664:#788888r   c                 D   | j                             | j                   | j                             d           |                     d| j         j        d                    |                     d| j         j        d                    | j                             d           | j                             d           | j                             d           |                     d| j         j        d                    |                     d| j         j        d                    dS )	zF
        IRC PART command removes a user from an IRC channel.
        rT   group1rV   group2z:alice PART #group1
z:alice1 PART #group1
z:alice1 PART #group2
NrW   r   s    r   	test_partzIRCProtoTests.test_partw   s     	
!!$.111
 :;;;h
 4X >???4:#7#ABBB
 9:::
 :;;;
 :;;;4:#7#ABBB4:#7#ABBBBBr   c                 d   | j                             | j                   | j                             d           |                     d| j         j        d                    |                     d| j         j        d                    | j                             d           |                     d| j         j        d                    | j                             d           |                     t          | j         j        d                   dk               | j                             d	           d
S )zH
        IRC QUIT command removes a user from all IRC channels.
        rT   r]   rV   r^   z:alice1 JOIN #group3
group3z:alice1 QUIT
r   z:alice3 QUIT
N)	r;   r?   r<   rN   rX   rY   rZ   
assertTruelenr   s    r   	test_quitzIRCProtoTests.test_quit   s    	
!!$.111
 :;;;h
 4X >???4:#7#ABBB
 :;;;h
 4X >???
 2333DJ0:;;q@AAA
 233333r   c                 L   | j                             | j                   | j                             d           | j                             d           | j                             d          }|                     |j        d           |                     |j        d           dS )zH
        IRC TOPIC command changes the topic of an IRC channel.
        rT   z :alice1 TOPIC #group1 newtopic
r]   newtopicrV   N)r;   r?   r<   rN   r-   rO   r    r!   )r   groupConversations     r   
test_topiczIRCProtoTests.test_topic   s     	
!!$.111
 :;;;
 DEEE J;;HEE*0*===*5x@@@@@r   c                 P   | j                             | j                   | j                             d           | j         j                            | j                             d                    }|                     |j        d           | j                             d           | j         	                    d          }|                     |j
        d           | j                             d           | j                             d           | j         	                    d	          }|                     t          |d
                     | j         j                            | j                             d                    }|                     t          |d                     dS )zG
        PRIVMSG sends a private message to a user or channel.
        z#:alice1 PRIVMSG t2 test_message_1
rV   test_message_1z(:alice1 PRIVMSG #group1 test_message_2
r]   test_message_2r9   z$:alice PRIVMSG #foo test_message_3
foor&   r   Nr;   r?   r<   rN   chatr2   	getPersonrO   r   r-   r&   setNickassertFalsehasattrr   conversationrg   s      r   test_privmsgzIRCProtoTests.test_privmsg   si    	
!!$.111
 GHHHz66tz7K7KH7U7UVV-/?@@@
 LMMM J;;HEE*/1ABBB
7###
 HIII J;;EBB!2F;;<<<z66tz7K7KG7T7TUUy99:::::r   c                 P   | j                             | j                   | j                             d           | j         j                            | j                             d                    }|                     |j        d           | j                             d           | j         	                    d          }|                     |j
        d           | j                             d           | j                             d           | j         	                    d	          }|                     t          |d
                     | j         j                            | j                             d                    }|                     t          |d                     dS )z3
        CTCP ACTION to a user or channel.
        z):alice1 PRIVMSG alice1 :ACTION smiles
rV   smilesz*:alice1 PRIVMSG #group1 :ACTION laughs
r]   laughsr9   z(:alice PRIVMSG #group1 :ACTION cries
rl   r&   r   Nrm   rs   s      r   test_actionzIRCProtoTests.test_action   sg    	
!!$.111
 QRRRz66tz7K7KH7U7UVV-x888
 RSSS J;;HEE*/:::
7###
 PQQQ J;;EBB!2F;;<<<z66tz7K7KG7T7TUUy99:::::r   c                    | j                             | j                   | j                             d           dgdgdgdgdgd}dg di}|                     || j         j                   |                     || j         j                   | j                             d           |                     i | j         j                   | j                             d          }|                     |d         |j                   dS )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<   rN   rO   rY   _namrepliesr-   members)r   expectedInGroupsexpectedNamRepliesrg   s       r   test_rplNamreplyzIRCProtoTests.test_rplNamreply   s    	
!!$.111
N	
 	
 	
 GgWGg
 
 $%R%R%RS)4:+?@@@+TZ-CDDD
 UVVVTZ3444 J;;EBB+E24E4MNNNNNr   c                     | j                             | j                   | j                             d           |                     d| j         j        d                    dS )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 topicrl   N)r;   r?   r<   rN   rO   _topicsr   s    r   test_rplTopiczIRCProtoTests.test_rplTopic   sZ     	
!!$.111
 UVVV,dj.@.GHHHHHr   c                 b   | j                             | j                   | j                             d          }|                     t
          |j        d           | j         |j        _        | j        	                                 |                    d           | 
                    | j        j                                        d           | j        	                                 |                    dddi           | 
                    | j        j                                        d           d	S )
z*
        L{IRCPerson.sendMessage}
        r9   Some messageSome message 2s   PRIVMSG alice :Some message 2
rw   styleemotes    PRIVMSG alice :ACTION smiles
N)r;   r?   r<   ro   assertRaisesr	   sendMessager:   clientclearrO   iogetvalue)r   persons     r   test_sendMessagezIRCProtoTests.test_sendMessage   s    	
!!$.111%%g..,(:NKKK $
+,,,N&&((*N	
 	
 	
 	8gw%7888N&&((*U	
 	
 	
 	
 	
r   c                 x   | j                             | j                   | j         j                            d| j                   }|                     t          |j        d           | j         |j        _	        | j        
                                 |                    d           |                     | j        j                                        d           | j        
                                 |                    dddi           |                     | j        j                                        d           d	S )
z.
        L{IRCGroup.sendGroupMessage}
        rH   r   r   s   PRIVMSG #foo :Some message 2
rw   r   r   s   PRIVMSG #foo :ACTION smiles
N)r;   r?   r<   rn   getGroupr   r	   sendGroupMessager:   r   r   rO   r   r   )r   r/   s     r   test_sendGroupMessagez#IRCProtoTests.test_sendGroupMessage   s     	
!!$.111
((<<,(>OOO#z/000N&&((*M	
 	
 	
 	x'7);<<<N&&((*T	
 	
 	
 	
 	
r   )r7   N)r   r   r   __doc__r=   rB   rF   rJ   rR   r[   r_   rd   rh   ru   ry   r   r   r   r   r   r   r   r6   r6   .   s^        + + + +	
 	
 	
 	

 
 
 

 
 
 
F F F F
9 
9 
9 
9C C C C4 4 4 4	A 	A 	A 	A; ; ; ;(; ; ; ;(O O O O4I I I 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      sB    5 4 4 4 4 4 M M M M M M M M M M < < < < < < < < 0 0 0 0 0 0 3 3 3 3 3 3! ! ! ! !| ! ! !! ! ! ! !- ! ! !K K K K K K K Kb
 b
 b
 b
 b
K b
 b
 b
 b
 b
r   