HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/words/test/__pycache__/test_irc_service.cpython-38.pyc
U


W[�%�@s�dZddlmZmZddlmZddlmZddlm	Z	m
Z
mZddlm
Z
Gdd�de
�ZGd	d
�d
e�ZdZGdd
�d
e
�ZdS)z5
Tests for IRC portions of L{twisted.words.service}.
�)�checkers�portal)�
proto_helpers)�irc)�InMemoryWordsRealm�
IRCFactory�IRCUser)�IRCTestCasec@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�IRCUserTestsz'
    Isolated tests for L{IRCUser}
    cCsptd�|_t��|_t�|j|jg�|_|j�dd�t|j|j�|_	|j	�
d�|_t�
�|_|j�|j�dS)zm
        Sets up a Realm, Portal, Factory, IRCUser, Transport, and Connection
        for our tests.
        �example.com�john�passN)r�realmrZ'InMemoryUsernamePasswordDatabaseDontUseZcheckerrZPortalZaddUserr�factoryZ
buildProtocol�ircUserrZStringTransport�stringTransportZmakeConnection��self�r�E/usr/lib/python3/dist-packages/twisted/words/test/test_irc_service.py�setUps


zIRCUserTests.setUpcCs<|j�ddg�|j��|j�d�|�|j��d�dS)z�
        Sending a message to a user after they have sent NICK, but before they
        have authenticated, results in a message from "example.com".
        ��mynickZfooz:example.com foo mynick
N)r�irc_NICKr�clear�sendMessage�assertEqualBufferValue�valuerrrr�test_sendMessage"s
zIRCUserTests.test_sendMessagecCsRd�d�}|j�dd�d�g�|j��|j�d�d��|�|j��|�dS)z�
        When a UTF8 message is sent with sendMessage and the current IRCUser
        has a UTF8 nick and is set to UTF8 encoding, the message will be
        written to the transport.
        u:example.com тест ник
�utf-8ruникuтестN)�encoderrrrrrr)rZexpectedResultrrr�test_utf8Messages-s�
zIRCUserTests.test_utf8MessagescCs|j�ddg�|�t�dS)z�
        A NICK command sent with a nickname that cannot be decoded with the
        current IRCUser's encoding results in a PRIVMSG from NickServ
        indicating that the nickname could not be decoded.
        rs����N)rrZassertRaises�UnicodeErrorrrrr�test_invalidEncodingNick<sz%IRCUserTests.test_invalidEncodingNickcCsJ|jj��}|jj��ttkr4t|t�r4|�d�}|��}dd�|D�S)zC
        Grabs our responses and then clears the transport
        rcSsg|]}t�|��qSr)rZparsemsg)�.0�rrrr�
<listcomp>Osz)IRCUserTests.response.<locals>.<listcomp>)	r�	transportrr�bytes�str�
isinstance�decode�
splitlines�r�responserrrr.Fs
zIRCUserTests.responseccs,t|�D]\}}|d|kr||fVqdS)a8
        Gets messages out of a response

        @param response: The parsed IRC messages of the response, as returned
        by L{IRCUserTests.response}

        @param messageType: The string type of the desired messages.

        @return: An iterator which yields 2-tuples of C{(index, ircMessage)}
        �N)�	enumerate)rr.ZmessageType�n�messagerrr�scanResponseRszIRCUserTests.scanResponsecCsx|j�ddg�|��}t|�|tj��}t|�|tj��}|�|dddddgffg�|�|ddddd	gffg�d
S)z�
        Receiving NICK without authenticating sends the MOTD Start and MOTD End
        messages, which is required by certain popular IRC clients (such as
        Pidgin) before a connection is considered to be fully established.
        rrrr�375�#- example.com Message of the Day - r/�376�End of /MOTD command.N)	rrr.�listr3r�
RPL_MOTDSTARTZ
RPL_ENDOFMOTD�assertEqual)rr.�start�endrrr�test_sendNickSendsGreetingbs��z'IRCUserTests.test_sendNickSendsGreetingcCs�|j�ddg�|j�ddg�|j�ddg�d|jjdf}d|jjdf}|�|��d	d
ddgfd	ddd
gfd	dddgfd	dd|gfd	dd|gfd	ddd	|jjdddgfg�dS)zz
        Receiving USER, PASS, NICK will log in the user, and transmit the
        appropriate response messages.
        rzjohn doer
rz,Your host is example.com, running version %sZserviceVersionzThis server was created on %sZcreationDaterr4r5r6r7Z001zconnected to Twisted IRCZ002Z003Z004�wr1N)rZirc_USERZirc_PASSrrZ_serverInfor:r.)r�versionZcreationrrr�test_fullLoginrs2��
�����zIRCUserTests.test_fullLogincCs�|j�ddg�|��}|jj��|�|ddtj�|j�ddg�|��}|jj��|�|ddtj	�|j�
dddg�|��}|jj��|�|ddtj�|j�
dddg�|��}|jj��|�|ddtj�d	S)
z
        irc_PART
        �testuserrrr/�somechannelssomechannelsboogaZboogaN)rrr.r'rr:rr9�irc_JOIN�ERR_NOSUCHCHANNELZirc_PART�ERR_NOTONCHANNELr-rrr�	test_PART�s zIRCUserTests.test_PARTcCs^|j�ddg�|j�ddg�|jj��|j�ddg�|��}|�|ddtj	�dS)z
        irc_NAMES
        rrArBrr/N)
rrrCr'rZ	irc_NAMESr.r:rZRPL_ENDOFNAMESr-rrr�
test_NAMES�szIRCUserTests.test_NAMESN)�__name__�
__module__�__qualname__�__doc__rrr!r#r.r3r=r@rFrGrrrrr
s
r
c@seZdZdd�Zdd�ZdS)�
MocksyIRCUsercCstd�|_g|_dS)Nr)rr�mockedCodesrrrr�__init__�s
zMocksyIRCUser.__init__cOs|j�|�dS�N)rM�append)r�code�_�__rrrr�szMocksyIRCUser.sendMessageN)rHrIrJrNrrrrrrL�srL��c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�IRCUserBadEncodingTestszw
    Verifies that L{IRCUser} sends the correct error messages back to clients
    when given indecipherable bytes
    cCst�|_dSrO)rLrrrrrr�szIRCUserBadEncodingTests.setUpcCs.t|jd|�dtg�|�|jj|g�dS)ak
        Asserts that IRCUser sends the relevant error code when a given irc_x
        dispatch method is given undecodable bytes.

        @param irc_x: the name of the irc_FOO method to test.
        For example, irc_x = 'PRIVMSG' will check irc_PRIVMSG

        @param error: the error code irc_x should send. For example,
        irc.ERR_NOTONCHANNEL
        zirc_%sN)�getattrr�BADTEXTr:rM)rZirc_x�errorrrr�assertChokesOnBadBytes�sz.IRCUserBadEncodingTests.assertChokesOnBadBytescCs|�dtj�dS)zk
        Tests that irc_JOIN sends ERR_NOSUCHCHANNEL if the channel name can't
        be decoded.
        ZJOINN�rYrrDrrrr�	test_JOIN�sz!IRCUserBadEncodingTests.test_JOINcCs|�dtj�dS)zl
        Tests that irc_NAMES sends ERR_NOSUCHCHANNEL if the channel name can't
        be decoded.
        ZNAMESNrZrrrrrG�sz"IRCUserBadEncodingTests.test_NAMEScCs|�dtj�dS)zl
        Tests that irc_TOPIC sends ERR_NOSUCHCHANNEL if the channel name can't
        be decoded.
        ZTOPICNrZrrrr�
test_TOPIC�sz"IRCUserBadEncodingTests.test_TOPICcCs|�dtj�dS)zk
        Tests that irc_LIST sends ERR_NOSUCHCHANNEL if the channel name can't
        be decoded.
        ZLISTNrZrrrr�	test_LIST�sz!IRCUserBadEncodingTests.test_LISTcCs|�dtj�dS)zg
        Tests that irc_MODE sends ERR_NOSUCHNICK if the target name can't
        be decoded.
        ZMODEN�rYrZERR_NOSUCHNICKrrrr�	test_MODE�sz!IRCUserBadEncodingTests.test_MODEcCs|�dtj�dS)zj
        Tests that irc_PRIVMSG sends ERR_NOSUCHNICK if the target name can't
        be decoded.
        ZPRIVMSGNr^rrrr�test_PRIVMSGsz$IRCUserBadEncodingTests.test_PRIVMSGcCs|�dtj�dS)zh
        Tests that irc_WHOIS sends ERR_NOSUCHNICK if the target name can't
        be decoded.
        ZWHOISNr^rrrr�
test_WHOIS
sz"IRCUserBadEncodingTests.test_WHOIScCs|�dtj�dS)zi
        Tests that irc_PART sends ERR_NOTONCHANNEL if the target name can't
        be decoded.
        ZPARTN)rYrrErrrrrFsz!IRCUserBadEncodingTests.test_PARTcCs|�dtj�dS)zo
        Tests that irc_WHO immediately ends the WHO list if the target name
        can't be decoded.
        ZWHON)rYrZRPL_ENDOFWHOrrrr�test_WHOsz IRCUserBadEncodingTests.test_WHON)rHrIrJrKrrYr[rGr\r]r_r`rarFrbrrrrrU�s


rUN)rKZtwisted.credrrZtwisted.testrZtwisted.words.protocolsrZtwisted.words.servicerrrZtwisted.words.test.test_ircr	r
rLrWrUrrrr�<module>s#