%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�$���dZddlZddlmZddlmZmZddlmZm	Z	ddl
mZddlm
Z
ddlmZmZmZdd	lmZdd
lmZddlmZGd�d
e�ZGd�dej2�ZGd�dej6�Zy)z-
Test cases for L{twisted.names.srvconnect}.
�N)�verifyObject)�defer�protocol)�DNSLookupError�ServiceNameUnknownError)�
IConnector)�
MemoryReactor)�client�dns�
srvconnect)�ResolverBase)�DNSNameError)�unittestc��eZdZdZdd�Zd�Zy)�FakeResolvera�
    Resolver that only gives out one given result.

    Either L{results} or L{failure} must be set and will be used for
    the return value of L{_lookup}

    @ivar results: List of L{dns.RRHeader} for the desired result.
    @type results: C{list}
    @ivar failure: Failure with an exception from L{twisted.names.error}.
    @type failure: L{Failure<twisted.python.failure.Failure>}
    Nc�.�||_||_g|_y�N)�results�failure�lookups)�selfrrs   �D/usr/lib/python3/dist-packages/twisted/names/test/test_srvconnect.py�__init__zFakeResolver.__init__$s�����������c���|jj||||f�|j�"tj|jggf�Stj
|j�S)z9
        Return the result or failure on lookup.
        )r�appendrr�succeed�failr)r�name�cls�qtype�timeouts     r�_lookupzFakeResolver._lookup)sV��	
�����T�3��w�7�8��<�<�#��=�=�$�,�,��B�!7�8�8��:�:�d�l�l�+�+r)NN)�__name__�
__module__�__qualname__�__doc__rr#�rrrrs��
��
,rrc��eZdZdZd�Zd�Zy)�DummyFactoryzL
    Dummy client factory that stores the reason of connection failure.
    c��d|_yr��reason�rs rrzDummyFactory.__init__9s	����rc��||_yrr,)r�	connectorr-s   r�clientConnectionFailedz#DummyFactory.clientConnectionFailed<s	����rN)r$r%r&r'rr1r(rrr*r*4s����rr*c�j�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zy)�SRVConnectorTestsz/
    Tests for L{srvconnect.SRVConnector}.
    c��|jtdt��t�|_t�|_tj|jdd|j�|_	g|_
g|_y)N�theResolver�xmpp-server�example.org)�patchr
rr	�reactorr*�factoryr�SRVConnectorr0�randIntArgs�randIntResultsr.s r�setUpzSRVConnectorTests.setUpEs[���
�
�6�=�,�.�9�$����#�~���#�0�0��L�L�-�����
������ ��rc�r�|jj||f�|jjd�S)a�
        Fake randint.

        Returns the first element of L{randIntResults} and records the
        arguments passed to it in L{randIntArgs}.

        @param min: Lower bound of the random number.
        @type min: L{int}

        @param max: Higher bound of the random number.
        @type max: L{int}

        @return: Fake random number from L{randIntResults}.
        @rtype: L{int}
        r)r<rr=�pop)r�min�maxs   r�_randintzSRVConnectorTests._randintOs3�� 	
������c�
�+��"�"�&�&�q�)�)rc�8�tt|j�y)zF
        L{srvconnect.SRVConnector} implements L{IConnector}.
        N)rrr0r.s r�test_interfacez SRVConnectorTests.test_interfacebs��	�Z����0rc��tjddd��}tjdtjtjd|��gt
j_|jj�|j|jj�|j|jjj!�ddd	�y)
zS
        Test connectTCP gets called with the address from the SRV record.
        �}�host.example.org�<��port�target�ttlr7�r�typer rM�payloadN�)rHrG)r�
Record_SRV�RRHeader�SRV�INr
r5rr0�connect�assertIsNoner:r-�assertEqualr9�
tcpClientsr@�rrPs  r�test_SRVPresentz!SRVConnectorTests.test_SRVPresenths����.�.�d�3E�2�N���L�L�"����c�f�f�"�g�
�&
����"�
	
����� ����$�,�,�-�-�.�������0�0�4�4�6�r��:�<V�Wrc�,�td�tj_|jj�|j
|jj�|j|jjj�ddd�y)zS
        Test connectTCP gets called with fallback parameters on NXDOMAIN.
        sexample.orgNrQ�r7r6)
rr
r5rr0rVrWr:r-rXr9rYr@r.s r�test_SRVNotPresentz$SRVConnectorTests.test_SRVNotPresentwsm��&2�.�%A����"������ ����$�,�,�-�-�.�����L�L�#�#�'�'�)�"�1�-�/M�	
rc��gtj_|jj	�|j|jj�|j|jjj�ddd�y)zW
        Test connectTCP gets called with fallback parameters on empty result.
        NrQr])r
r5rr0rVrWr:r-rXr9rYr@r.s r�test_SRVNoResultz"SRVConnectorTests.test_SRVNoResult�sh��&(����"������ ����$�,�,�-�-�.�����L�L�#�#�'�'�)�"�1�-�/M�	
rc��tj|jdd|jd��|_t�tj_|jj�|j|jj�|j|jjj�ddd�y)zY
        connectTCP gets called with default port if the service is not defined.
        �thisbetternotexistr7�f)�defaultPortNrQ)r7rc)rr;r9r:r0rr
r5rrVrWr-rXrYr@r.s r�)test_SRVNoResultUnknownServiceDefaultPortz;SRVConnectorTests.test_SRVNoResultUnknownServiceDefaultPort�s���$�0�0��L�L� ���L�L��
���&=�%>����"������ ����$�,�,�-�-�.�������0�0�4�4�6�r��:�<Q�Rrc�D�tj|jdd|j�|_t�tj_|jj�|j|jjjt
��y)zR
        Connect fails on no result, unknown service and no default port.
        rbr7N)
rr;r9r:r0rr
r5rrV�
assertTruer-�checkr.s r�+test_SRVNoResultUnknownServiceNoDefaultPortz=SRVConnectorTests.test_SRVNoResultUnknownServiceNoDefaultPort�sm��$�0�0��L�L�.�
�t�|�|�
���&=�%>����"������ �������+�+�1�1�2I�J�Krc��tjdtjtjdd��gtj
_|jj�|j|jj�|j|jjj�ddd�y)zU
        Test connectTCP gets called with fallback parameters on bad result.
        r7rINrNrQr])rrS�CNAMErUr
r5rr0rVrWr:r-rXr9rYr@r.s r�test_SRVBadResultz#SRVConnectorTests.test_SRVBadResult�s���

�L�L�"�������B�PT�
�&
����"�
	
����� ����$�,�,�-�-�.�����L�L�#�#�'�'�)�"�1�-�/M�	
rc���tjddd��}tjdtjtjd|��gt
j_|jj�|j|jj�|jjjt�|j|j j"g�y)zH
        Test that connecting fails when no service is present.
        i��.rIrJr7rNN)rrRrSrTrUr
r5rr0rV�assertIsNotNoner:r-�traprrXr9rYrZs  r�test_SRVNoServicez#SRVConnectorTests.test_SRVNoService�s����.�.�d�4�R�@���L�L�"����c�f�f�"�g�
�&
����"�
	
����� ����T�\�\�0�0�1������ � ��0�������0�0�"�5rc���gtj_|jj	�tjj
dd}|j
d|�y)zW
        The lookup name is a native string from service, protocol and domain.
        ���rs_xmpp-server._tcp.example.orgN)r
r5rr0rVrrX)rrs  r�test_SRVLookupNamez$SRVConnectorTests.test_SRVLookupName�sN��&(����"������ ��!�!�)�)�"�-�a�0�����9�4�@rc��tj|jdd|j�|_|jd|jj�y)zq
        L{srvconnect.SRVConnector} automatically encodes unicode domain using
        C{idna} encoding.
        zxmpp-clientuéchec.example.orgsxn--chec-9oa.example.orgN)rr;r9r:r0rX�domainr.s r�test_unicodeDomainz$SRVConnectorTests.test_unicodeDomain�sE��
$�0�0��L�L�-�)A�4�<�<�
���	
���4�d�n�n�6K�6K�Lrc���tjdddd�}tjdddd�}||g|j_g|j_|jtd|j�ddg|_|jj�|j|jdd	�|jj�|j|jd
d�ddg|_|jj�|j|jdd	�|jj�|j|jd
d�y)a
        pickServer calculates running sum of weights and calls randint.

        This exercises the server selection algorithm specified in RFC 2782 by
        preparing fake L{random.randint} results and checking the values it was
        called with.
        �
rc�host1.example.org��host2.example.org�randint�r)r��)rryrQ�)rr{N)rrRr0�orderedServers�serversr8�randomrCr=�
pickServerrXr<�r�record1�record2s   r�test_pickServerWeightsz(SRVConnectorTests.test_pickServerWeights�s'���.�.��R��/B�C���.�.��R��/B�C��)0�'�(:����%�!#������
�
�6�9�d�m�m�4� "�1�g������!�!�#�����)�)�!�,�g�6����!�!�#�����)�)�!�,�g�6� "�1�g������!�!�#�����)�)�!�,�g�6����!�!�#�����)�)�!�,�g�6rc��tjdddd�}tjdddd�}||g|j_g|j_|jtd|j�ddg|_|jd|jj��|jd	|jj��y
)zR
        Two records with equal priorities compare on weight (ascending).
        ryrcrzr{r|r}r�rzrc�r|rcN�rrRr0r�r�r8r�rCr=rXr�r�s   r�test_pickServerSamePrioritiesz/SRVConnectorTests.test_pickServerSamePrioritiess����.�.��R��/B�C���.�.��R��/B�C��)0�'�(:����%�!#������
�
�6�9�d�m�m�4� �!�f������4�d�n�n�6O�6O�6Q�R����4�d�n�n�6O�6O�6Q�Rrc��tjdddd�}tjdddd�}||g|j_g|j_|jtd|j�ddg|_|jd|jj��|jd	|jj��y
)zX
        Two records with differing priorities compare on priority (ascending).
        ryrrcrzr{r|r}r�r�Nr�r�s   r�test_srvDifferentPrioritiesz-SRVConnectorTests.test_srvDifferentPrioritiess����.�.��Q��.A�B���.�.��Q��.A�B��)0�'�(:����%�!#������
�
�6�9�d�m�m�4� �!�f������4�d�n�n�6O�6O�6Q�R����4�d�n�n�6O�6O�6Q�RrN)r$r%r&r'r>rCrEr[r^r`rerirlrqrtrwr�r�r�r(rrr3r3@sZ���!�*�&1�
X�

�

�S�$L�
� 6� A�M�7�BS� Srr3)r'r��zope.interface.verifyr�twisted.internetrr�twisted.internet.errorrr�twisted.internet.interfacesr�twisted.internet.testingr	�
twisted.namesr
rr�twisted.names.commonr
�twisted.names.errorr�
twisted.trialrr�
ClientFactoryr*�TestCaser3r(rr�<module>r�sa���
�.�,�J�2�2�1�1�-�,�"�,�<�,�:	�8�)�)�	�aS��)�)�aSr

Zerion Mini Shell 1.0