%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/words/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/words/test/__pycache__/test_irc_service.cpython-312.pyc

�

Ϫ�f:'���dZddlmZmZddlmZddlmZddlm	Z	m
Z
mZddlm
Z
Gd�de
�ZGd	�d
e�ZdZGd�d
e
�Zy)z5
Tests for IRC portions of L{twisted.words.service}.
�)�checkers�portal)�
proto_helpers)�irc)�InMemoryWordsRealm�
IRCFactory�IRCUser)�IRCTestCasec�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�IRCUserTestsz'
    Isolated tests for L{IRCUser}
    c���td�|_tj�|_tj|j|jg�|_|jjdd�t|j|j
�|_	|jjd�|_tj�|_|jj|j�y)zm
        Sets up a Realm, Portal, Factory, IRCUser, Transport, and Connection
        for our tests.
        �example.com�john�passN)r�realmr�'InMemoryUsernamePasswordDatabaseDontUse�checkerr�Portal�addUserr�factory�
buildProtocol�ircUserr�StringTransport�stringTransport�makeConnection��selfs �E/usr/lib/python3/dist-packages/twisted/words/test/test_irc_service.py�setUpzIRCUserTests.setUps���
(�
�6��
��G�G�I����m�m�D�J�J�����?��������V�V�,�!�$�*�*�d�k�k�:����|�|�1�1�$�7���,�<�<�>������#�#�D�$8�$8�9�c��|jjddg�|jj�|jj	d�|j|jj
�d�y)z�
        Sending a message to a user after they have sent NICK, but before they
        have authenticated, results in a message from "example.com".
        ��mynick�fooz:example.com foo mynick
N)r�irc_NICKr�clear�sendMessage�assertEqualBufferValue�valuers r�test_sendMessagezIRCUserTests.test_sendMessage"sa��
	
�����b�8�*�-����"�"�$���� � ��'��#�#�� � �&�&�(�*G�	
r c�T�dj�}|jjddj�g�|jj	�|jjdj��|j
|jj�|�y)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 тест ник
r"uникuтестN)�encoderr%rr&r'r(r))r�expectedResults  r�test_utf8MessageszIRCUserTests.test_utf8Messages.s���<�B�B�D�������b�#7�#>�#>�#@�"A�B����"�"�$���� � �!;�!B�!B�!D�E��#�#�D�$8�$8�$>�$>�$@�.�Qr c�h�|jjddg�|jt�y)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.
        r"s����N)rr%�assertRaises�UnicodeErrorrs r�test_invalidEncodingNickz%IRCUserTests.test_invalidEncodingNick;s*��	
�����b�#6�"7�8����,�'r c�^�|jjj�}|jjj�tt
k7r!t
|t�r|jd�}|j�}|D�cgc]}tj|���c}Scc}w)zC
        Grabs our responses and then clears the transport
        zutf-8)r�	transportr)r&�bytes�str�
isinstance�decode�
splitlinesr�parsemsg)r�response�rs   rr;zIRCUserTests.responseDsz���<�<�)�)�/�/�1�������$�$�&��C�<�J�x��7����w�/�H��&�&�(��)1�2�A����Q��2�2��2s�B*c#�PK�t|�D]\}}|d|k(s�||f���y�w)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;�messageType�n�messages     r�scanResponsezIRCUserTests.scanResponseOs6����$�H�-�	!�J�A�w��q�z�[�(���j� �	!�s�&�	&c�j�|jjddg�|j�}t|j	|t
j��}t|j	|t
j��}|j|dddddgffg�|j|ddddd	gffg�y
)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.
        r"r#rr�375�#- example.com Message of the Day - r>�376�End of /MOTD command.N)	rr%r;�listrCr�
RPL_MOTDSTART�
RPL_ENDOFMOTD�assertEqual)rr;�start�ends    r�test_sendNickSendsGreetingz'IRCUserTests.test_sendNickSendsGreeting^s���	
�����b�8�*�-��=�=�?���T�&�&�x��1B�1B�C�D���4�$�$�X�s�/@�/@�A�B�������%��!�#H�I���	
�	
�	
����1�}�e�h�8O�-P�Q�R�S�	
r c��|jjddg�|jjddg�|jjddg�dj	|j
jd�}dj	|j
jd�}|j|j�d	d
ddgfd	ddd
gfd	dddgfd	dd|gfd	dd|gfd	ddd	|j
jdddgfg�y)zz
        Receiving USER, PASS, NICK will log in the user, and transmit the
        appropriate response messages.
        r"zjohn doerrz,Your host is example.com, running version {}�serviceVersionzThis server was created on {}�creationDaterrErFrGrH�001zconnected to Twisted IRC�002�003�004�wrAN)	r�irc_USER�irc_PASSr%�formatr�_serverInforLr;)r�version�creations   r�test_fullLoginzIRCUserTests.test_fullLoginys(��
	
�����b�:�,�/������b�6�(�+������b�6�(�+�@�G�G��L�L�$�$�%5�6�
��3�9�9��L�L�$�$�^�4�
��	
����M�M�O����0U�'V�W����0G�'H�I����0J�'K�L�����'8�9�����'9�:�!���%����0�0�1A�B����
�

�	
r c��|jjddg�|j�}|jjj	�|j|ddtj�|jjddg�|j�}|jjj	�|j|ddtj�|jjdddg�|j�}|jjj	�|j|ddtj�|jjdddg�|j�}|jjj	�|j|ddtj�y	)
z
        irc_PART
        �testuserr#rr>�somechannelssomechannelsbooga�boogaN)rr%r;r4r&rLrrJ�irc_JOIN�ERR_NOSUCHCHANNEL�irc_PART�ERR_NOTONCHANNEL�rr;s  r�	test_PARTzIRCUserTests.test_PART�s^��	
�����j�8�*�5��=�=�?�������$�$�&�����!��Q���):�):�;������j�=�/�:��=�=�?�������$�$�&�����!��Q���)>�)>�?������j�>�8�*D�E��=�=�?�������$�$�&�����!��Q���)=�)=�>������j�=�'�*B�C��=�=�?�������$�$�&�����!��Q���)=�)=�>r c�f�|jjddg�|jjddg�|jjj	�|jjddg�|j
�}|j|ddtj�y)z
        irc_NAMES
        r"r`rarr>N)
rr%rcr4r&�	irc_NAMESr;rLr�RPL_ENDOFNAMESrgs  r�
test_NAMESzIRCUserTests.test_NAMES�s���	
�����b�:�,�/������b�=�/�2������$�$�&������r�M�?�3��=�=�?������!��Q���);�);�<r N)�__name__�
__module__�__qualname__�__doc__rr*r.r2r;rCrOr^rhrl�r rrrs;���:�

�R�(�	3�
!�
�6%
�N?�*	=r rc��eZdZd�Zd�Zy)�
MocksyIRCUserc�2�td�|_g|_y)Nr)rr�mockedCodesrs r�__init__zMocksyIRCUser.__init__�s��'�
�6��
���r c�:�|jj|�y�N)ru�append)r�code�_�__s    rr'zMocksyIRCUser.sendMessage�s��������%r N)rmrnrorvr'rqr rrsrs�s���&r rs��c�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�IRCUserBadEncodingTestszw
    Verifies that L{IRCUser} sends the correct error messages back to clients
    when given indecipherable bytes
    c�"�t�|_yrx)rsrrs rrzIRCUserBadEncodingTests.setUp�s��$���r c��t|jd|z�dtg�|j|jj|g�y)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�BADTEXTrLru)r�irc_x�errors   r�assertChokesOnBadBytesz.IRCUserBadEncodingTests.assertChokesOnBadBytes�s>��	0�����h��.�/��w�i�@�������1�1�E�7�;r c�D�|jdtj�y)zk
        Tests that irc_JOIN sends ERR_NOSUCHCHANNEL if the channel name can't
        be decoded.
        �JOINN�r�rrdrs r�	test_JOINz!IRCUserBadEncodingTests.test_JOIN����
	
�#�#�F�C�,A�,A�Br c�D�|jdtj�y)zl
        Tests that irc_NAMES sends ERR_NOSUCHCHANNEL if the channel name can't
        be decoded.
        �NAMESNr�rs rrlz"IRCUserBadEncodingTests.test_NAMES����
	
�#�#�G�S�-B�-B�Cr c�D�|jdtj�y)zl
        Tests that irc_TOPIC sends ERR_NOSUCHCHANNEL if the channel name can't
        be decoded.
        �TOPICNr�rs r�
test_TOPICz"IRCUserBadEncodingTests.test_TOPIC�r�r c�D�|jdtj�y)zk
        Tests that irc_LIST sends ERR_NOSUCHCHANNEL if the channel name can't
        be decoded.
        �LISTNr�rs r�	test_LISTz!IRCUserBadEncodingTests.test_LIST�r�r c�D�|jdtj�y)zg
        Tests that irc_MODE sends ERR_NOSUCHNICK if the target name can't
        be decoded.
        �MODEN�r�r�ERR_NOSUCHNICKrs r�	test_MODEz!IRCUserBadEncodingTests.test_MODEs��
	
�#�#�F�C�,>�,>�?r c�D�|jdtj�y)zj
        Tests that irc_PRIVMSG sends ERR_NOSUCHNICK if the target name can't
        be decoded.
        �PRIVMSGNr�rs r�test_PRIVMSGz$IRCUserBadEncodingTests.test_PRIVMSG
s��
	
�#�#�I�s�/A�/A�Br c�D�|jdtj�y)zh
        Tests that irc_WHOIS sends ERR_NOSUCHNICK if the target name can't
        be decoded.
        �WHOISNr�rs r�
test_WHOISz"IRCUserBadEncodingTests.test_WHOISs��
	
�#�#�G�S�-?�-?�@r c�D�|jdtj�y)zi
        Tests that irc_PART sends ERR_NOTONCHANNEL if the target name can't
        be decoded.
        �PARTN)r�rrfrs rrhz!IRCUserBadEncodingTests.test_PARTs��
	
�#�#�F�C�,@�,@�Ar c�D�|jdtj�y)zo
        Tests that irc_WHO immediately ends the WHO list if the target name
        can't be decoded.
        �WHON)r�r�RPL_ENDOFWHOrs r�test_WHOz IRCUserBadEncodingTests.test_WHO&s��
	
�#�#�E�3�+;�+;�<r N)rmrnrorprr�r�rlr�r�r�r�r�rhr�rqr rrr�sF���'�<� C�D�D�C�@�C�A�B�=r rN)rp�twisted.credrr�twisted.testr�twisted.words.protocolsr�twisted.words.servicerrr	�twisted.words.test.test_ircr
rrsr�rrqr r�<module>r�sN���*�&�'�I�I�3�o=�;�o=�d&�G�&���^=�k�^=r 

Zerion Mini Shell 1.0