%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_server.cpython-312.pyc

�

Ϫ�fȢ��P�dZddlmZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Z
mZddlmZGd�d	e�Zd
�ZGd�dej(�ZGd
�dej(�ZGd�d�ZGd�d�ZGd�d�ZGd�d�Zd�ZGd�dej8�Zy)z)
Test cases for L{twisted.names.server}.
�)�verifyClass)�defer)�IProtocolFactory)�dns�error�resolve�server)�failure�log)�unittestc��eZdZdZd�Zy)�RaisedArgumentszD
    An exception containing the arguments raised by L{raiser}.
    c� �||_||_y�N��args�kwargs��selfrrs   �@/usr/lib/python3/dist-packages/twisted/names/test/test_server.py�__init__zRaisedArguments.__init__s����	����N)�__name__�
__module__�__qualname__�__doc__r�rrrrs���rrc��t||��)z�
    Raise a L{RaisedArguments} exception containing the supplied arguments.

    Used as a fake when testing the call signatures of  methods and functions.
    )rrs  r�raiserrs���$��
'�'rc��eZdZdZd�Zd�Zy)�NoResponseDNSServerFactorya
    A L{server.DNSServerFactory} subclass which does not attempt to reply to any
    received messages.

    Used for testing logged messages in C{messageReceived} without having to
    fake or patch the preceding code which attempts to deliver a response
    message.
    c��y)a
        Deny all queries.

        @param message: See L{server.DNSServerFactory.allowQuery}
        @param protocol: See L{server.DNSServerFactory.allowQuery}
        @param address: See L{server.DNSServerFactory.allowQuery}

        @return: L{False}
        @rtype: L{bool}
        Fr)r�message�protocol�addresss    r�
allowQueryz%NoResponseDNSServerFactory.allowQuery.s��rc��y)z�
        A noop send reply.

        @param protocol: See L{server.DNSServerFactory.sendReply}
        @param message: See L{server.DNSServerFactory.sendReply}
        @param address: See L{server.DNSServerFactory.sendReply}
        Nr)rr$r#r%s    r�	sendReplyz$NoResponseDNSServerFactory.sendReply;��rN)rrrrr&r(rrrr!r!$s����rr!c�,�eZdZdZGd�de�Zd�Zy)�RaisingDNSServerFactoryz�
    A L{server.DNSServerFactory} subclass whose methods raise an exception
    containing the supplied arguments.

    Used for stopping L{messageReceived} and testing the arguments supplied to
    L{allowQuery}.
    c��eZdZdZy)�+RaisingDNSServerFactory.AllowQueryArguments�G
        Contains positional and keyword arguments in C{args}.
        N�rrrrrrr�AllowQueryArgumentsr-N���	rr0c�&�|j||��)aC
        Raise the arguments supplied to L{allowQuery}.

        @param args: Positional arguments which will be recorded in the raised
            exception.
        @type args: L{tuple}

        @param kwargs: Keyword args which will be recorded in the raised
            exception.
        @type kwargs: L{dict}
        )r0rs   rr&z"RaisingDNSServerFactory.allowQuerySs���&�&�t�V�4�4rN)rrrr�	Exceptionr0r&rrrr+r+Es����i��
5rr+c�,�eZdZdZGd�de�Zd�Zy)�RaisingProtocolzm
    A partial fake L{IProtocol} whose methods raise an exception containing the
    supplied arguments.
    c��eZdZdZy)�%RaisingProtocol.WriteMessageArgumentsr.Nr/rrr�WriteMessageArgumentsr7hr1rr8c�&�|j||���z�
        Raises the supplied arguments.

        @param args: Positional arguments
        @type args: L{tuple}

        @param kwargs: Keyword args
        @type kwargs: L{dict}
        )r8rs   r�writeMessagezRaisingProtocol.writeMessagems���(�(��v�6�6rN)rrrrr3r8r;rrrr5r5bs���
�	��

7rr5c��eZdZdZd�Zy)�NoopProtocolzT
    A partial fake L{dns.DNSProtocolMixin} with a noop L{writeMessage} method.
    c��y)z�
        A noop version of L{dns.DNSProtocolMixin.writeMessage}.

        @param args: Positional arguments
        @type args: L{tuple}

        @param kwargs: Keyword args
        @type kwargs: L{dict}
        Nrrs   rr;zNoopProtocol.writeMessager)rN)rrrrr;rrrr=r=zs���	rr=c�,�eZdZdZGd�de�Zd�Zy)�RaisingResolverzm
    A partial fake L{IResolver} whose methods raise an exception containing the
    supplied arguments.
    c��eZdZdZy)�RaisingResolver.QueryArgumentsr.Nr/rrr�QueryArgumentsrB�r1rrCc�&�|j||��r:)rCrs   r�queryzRaisingResolver.query�s���!�!�$��/�/rN)rrrrr3rCrErrrr@r@�s���
���

0rr@c�,�eZdZdZGd�de�Zd�Zy)�RaisingCachez}
    A partial fake L{twisted.names.cache.Cache} whose methods raise an exception
    containing the supplied arguments.
    c��eZdZdZy)�!RaisingCache.CacheResultArgumentsr.Nr/rrr�CacheResultArgumentsrI�r1rrJc�&�|j||��r:)rJrs   r�cacheResultzRaisingCache.cacheResult�s���'�'��f�5�5rN)rrrrr3rJrLrrrrGrG�s���
�y��

6rrGc��g}tj|j�|jtj|j�||i|��|j|D�cgc]
}|dd��c}|�ycc}w)a
    Assert that the callable logs the expected messages when called.

    XXX: Put this somewhere where it can be re-used elsewhere. See #6677.

    @param testCase: The test case controlling the test which triggers the
        logged messages and on which assertions will be called.
    @type testCase: L{unittest.SynchronousTestCase}

    @param expectedMessages: A L{list} of the expected log messages
    @type expectedMessages: L{list}

    @param callable: The function which is expected to produce the
        C{expectedMessages} when called.
    @type callable: L{callable}

    @param args: Positional arguments to be passed to C{callable}.
    @type args: L{list}

    @param kwargs: Keyword arguments to be passed to C{callable}.
    @type kwargs: L{dict}
    r#rN)r�addObserver�append�
addCleanup�removeObserver�assertEqual)�testCase�expectedMessages�callablerr�loggedMessages�ms       r�assertLogMessagerX�sk��.�N��O�O�N�)�)�*�����*�*�N�,A�,A�B��d��f�����>�B�a�!�I�,�q�/�B�DT�U��Bs�#A;c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+d*�Z,d+�Z-d,�Z.d-�Z/d.�Z0d/�Z1d0�Z2d1�Z3d2�Z4d3�Z5d4�Z6d5�Z7d6�Z8d7�Z9d8�Z:d9�Z;d:�Z<d;�Z=d<�Z>d=�Z?d>�Z@d?�ZAd@�ZBdA�ZCyB)C�DNSServerFactoryTestsz/
    Tests for L{server.DNSServerFactory}.
    c�|�|jtj�jtj
�y)zd
        L{server.DNSServerFactory.resolver} is a L{resolve.ResolverChain}
        instance
        N)�assertIsInstancer	�DNSServerFactory�resolverr�
ResolverChain�rs r�test_resolverTypez'DNSServerFactoryTests.test_resolverType�s)��
	
���f�5�5�7�@�@�'�BW�BW�Xrc�t�|jtj�jjg�y)zn
        L{server.DNSServerFactory.resolver} is an empty L{resolve.ResolverChain}
        by default.
        N�rRr	r]r^�	resolversr`s r�test_resolverDefaultEmptyz/DNSServerFactoryTests.test_resolverDefaultEmpty�s)��
	
����0�0�2�;�;�E�E�r�Jrc��t�}|jtj|g��jj
|g�y)z�
        L{server.DNSServerFactory.__init__} accepts an C{authorities}
        argument. The value of this argument is a list and is used to extend the
        C{resolver} L{resolve.ResolverChain}.
        )�authoritiesN��objectrRr	r]r^rd�r�
dummyResolvers  r�test_authoritiesz&DNSServerFactoryTests.test_authorities�s:����
�����#�#���@�I�I�S�S�
�O�	
rc��t�}|jtj|g��jj
|g�y)z�
        L{server.DNSServerFactory.__init__} accepts a C{caches} argument. The
        value of this argument is a list and is used to extend the C{resolver}
        L{resolve.ResolverChain}.
        ��cachesNrhrjs  r�test_cachesz!DNSServerFactoryTests.test_caches�s:����
�����#�#�M�?�;�D�D�N�N�
�O�	
rc��t�}|jtj|g��jj
|g�y)z�
        L{server.DNSServerFactory.__init__} accepts a C{clients} argument. The
        value of this argument is a list and is used to extend the C{resolver}
        L{resolve.ResolverChain}.
        ��clientsNrhrjs  r�test_clientsz"DNSServerFactoryTests.test_clientss:����
�����#�#�]�O�<�E�E�O�O�
�O�	
rc���Gd�d�}Gd�d�}Gd�d�}|jtj|g|g|g��jj|||g�y)	zz
        L{server.DNSServerFactory.resolver} contains an ordered list of
        authorities, caches and clients.
        c��eZdZy)�@DNSServerFactoryTests.test_resolverOrder.<locals>.DummyAuthorityN�rrrrrr�DummyAuthorityrw���rryc��eZdZy)�<DNSServerFactoryTests.test_resolverOrder.<locals>.DummyCacheNrxrrr�
DummyCacher|rzrr}c��eZdZy)�=DNSServerFactoryTests.test_resolverOrder.<locals>.DummyClientNrxrrr�DummyClientrrzrr�)rgrorsNrc)rryr}r�s    r�test_resolverOrderz(DNSServerFactoryTests.test_resolverOrders_��	�	�	�	�	�	�	
����#�#�+�,�j�\�K�=�
��h�y�y�
�Z��5�		
rc�^�|jtj�j�y)zI
        L{server.DNSServerFactory.cache} is L{None} by default.
        N)�assertIsNoner	r]�cacher`s r�test_cacheDefaultz'DNSServerFactoryTests.test_cacheDefault)s!��	
���&�1�1�3�9�9�:rc��t�}|jtjt�|g��j|�y)z�
        L{server.DNSServerFactory.__init__} assigns the last object in the
        C{caches} list to L{server.DNSServerFactory.cache}.
        rnN)rirRr	r]r�rjs  r�test_cacheOverridez(DNSServerFactoryTests.test_cacheOverride/s7��
��
�����#�#�F�H�m�+D�E�K�K��	
rc�^�|jtj�j�y)z�
        L{server.DNSServerFactory.canRecurse} is a flag indicating that this
        server is capable of performing recursive DNS lookups. It defaults to
        L{False}.
        N)�assertFalser	r]�
canRecurser`s r�test_canRecurseDefaultz,DNSServerFactoryTests.test_canRecurseDefault:s!��	
����0�0�2�=�=�>rc�f�|jtjdg��jd�y)z~
        L{server.DNSServerFactory.__init__} sets C{canRecurse} to L{True} if it
        is supplied with C{clients}.
        NrrT)rRr	r]r�r`s r�test_canRecurseOverridez-DNSServerFactoryTests.test_canRecurseOverrideBs'��
	
����0�0�$��@�K�K�T�Rrc�^�|jtj�j�y)zJ
        L{server.DNSServerFactory.verbose} defaults to L{False}.
        N)r�r	r]�verboser`s r�test_verboseDefaultz)DNSServerFactoryTests.test_verboseDefaultIs!��	
����0�0�2�:�:�;rc�b�|jtjd��j�y)z�
        L{server.DNSServerFactory.__init__} accepts a C{verbose} argument which
        overrides L{server.DNSServerFactory.verbose}.
        T�r�N)�
assertTruer	r]r�r`s r�test_verboseOverridez*DNSServerFactoryTests.test_verboseOverrideOs!��
	
����/�/��=�E�E�Frc�^�|jtttj��y)zL
        L{server.DNSServerFactory} implements L{IProtocolFactory}.
        N)r�rrr	r]r`s r�test_interfacez$DNSServerFactoryTests.test_interfaceVs��	
����$4�f�6M�6M�N�Orc�t�|jtjjtj
�y)zU
        L{server.DNSServerFactory.protocol} defaults to L{dns.DNSProtocol}.
        N)�assertIsr	r]r$r�DNSProtocolr`s r�test_defaultProtocolz*DNSServerFactoryTests.test_defaultProtocol\s"��	
�
�
�f�-�-�6�6����Hrc����Gd�d�}|���fd�}tj�}||_|jd��}|j	�|fif||j
|jf�y)z�
        L{server.DNSServerFactory.buildProtocol} builds a protocol by calling
        L{server.DNSServerFactory.protocol} with its self as a positional
        argument.
        c��eZdZdZdZdZy)�NDNSServerFactoryTests.test_buildProtocolProtocolOverride.<locals>.FakeProtocolN)rrr�factoryrrrrr�FakeProtocolr�is���G��D��Frr�c�$��|�_|�_�Srr)rr�stubProtocols  �r�fakeProtocolFactoryzUDNSServerFactoryTests.test_buildProtocolProtocolOverride.<locals>.fakeProtocolFactoryps��� $�L��"(�L���rN)�addr)r	r]r$�
buildProtocolrRrr)rr�r��f�pr�s     @r�"test_buildProtocolProtocolOverridez8DNSServerFactoryTests.test_buildProtocolProtocolOverridebsj���	�	�
$�~��	 �

�#�#�%��(��
�
�O�O��O�&�����,���b�1�A�q�v�v�q�x�x�3H�Irc�\�tj�}t|g|jd�y)zm
        L{server.DNSServerFactory._verboseLog} does not log messages unless
        C{verbose > 0}.
        �Foo BarN�r	r]rX�_verboseLog�rr�s  r�test_verboseLogQuietz*DNSServerFactoryTests.test_verboseLogQuiet{s$��

�#�#�%����r�1�=�=�)�<rc�b�tjd��}t|dg|jd�y)zZ
        L{server.DNSServerFactory._verboseLog} logs a message if C{verbose > 0}.
        �r�r�Nr�r�s  r�test_verboseLogVerbosez,DNSServerFactoryTests.test_verboseLogVerbose�s(��
�#�#�A�.����	�{�A�M�M�9�Erc�|�tj�}td��}t|dg|j|dd��y)z�
        L{server.DNSServerFactory.messageReceived} logs about an empty query if
        the message had no queries and C{verbose} is C{>0}.
        r�r�z$Empty query from ('192.0.2.100', 53)N�z192.0.2.100�5�r#�protor%)r�Messager!rX�messageReceived�rrWr�s   r�"test_messageReceivedLoggingNoQueryz8DNSServerFactoryTests.test_messageReceivedLoggingNoQuery�s<��

�K�K�M��&�q�1����
3�4�
�����'�
	
rc��tj�}|jdtj��|jdtj��td��}t
|dg|j|dd��y)	z�
        L{server.DNSServerFactory.messageReceived} logs the query types of all
        queries in the message if C{verbose} is set to C{1}.
        �example.com��name�typer�r�z&MX AAAA query from ('192.0.2.100', 53)Nr�r��rr��addQuery�MX�AAAAr!rXr�r�s   r�test_messageReceivedLogging1z2DNSServerFactoryTests.test_messageReceivedLogging1�sd��

�K�K�M��	�
�
�
�C�F�F�
�3�	�
�
�
�C�H�H�
�5�&�q�1����
5�6�
�����'�
	
rc��tj�}|jdtj��|jdtj��td��}t
|dg|j|dd��y)	z�
        L{server.DNSServerFactory.messageReceived} logs the repr of all queries
        in the message if C{verbose} is set to C{2}.
        r�r��r�zT<Query example.com MX IN> <Query example.com AAAA IN> query from ('192.0.2.100', 53)Nr�r�r�r�s   r�test_messageReceivedLogging2z2DNSServerFactoryTests.test_messageReceivedLogging2�sk��

�K�K�M��	�
�
�
�C�F�F�
�3�	�
�
�
�C�H�H�
�5�&�q�1����M�
�
�����'�
	
rc���tj�}t�}t��|j	t
jd�fd��|j|dd��|j|j��y)zv
        L{server.DNSServerFactory.messageReceived} assigns a unix timestamp to
        the received message.
        �timec����Srr)�ts�r�<lambda>zEDNSServerFactoryTests.test_messageReceivedTimestamp.<locals>.<lambda>�s����rNr�)
rr�r!ri�patchr	r�r�rR�timeReceived)rrWr�r�s   @r�test_messageReceivedTimestampz3DNSServerFactoryTests.test_messageReceivedTimestamp�s\���

�K�K�M��&�(���H���
�
�6�;�;��	�2�	���!�4���>��������+rc�0�tj�}t�}t�}t�}|j	tj
|j|||��}|j\}}|j||||f�|j|i�y)z�
        L{server.DNSServerFactory.messageReceived} passes all messages to
        L{server.DNSServerFactory.allowQuery} along with the receiving protocol
        and origin address.
        r�N)	rr�rir+�assertRaisesr0r�rrR)rr#�
dummyProtocol�dummyAddressr��errs        r�test_messageReceivedAllowQueryz4DNSServerFactoryTests.test_messageReceivedAllowQuery�s����+�+�-����
��x��#�%�����#�7�7�
����� �
�
���v�v���f��������E�F������$rc�F��Gd�dt��G�fd�dtj�}|�}|j�|jtj�dd��}|j\\}}}}|j|jt
j�y)z�
        If C{allowQuery} returns C{False},
        L{server.DNSServerFactory.messageReceived} calls L{server.sendReply}
        with a message whose C{rCode} is L{dns.EREFUSED}.
        c��eZdZy)�FDNSServerFactoryTests.test_allowQueryFalse.<locals>.SendReplyExceptionNrxrrr�SendReplyExceptionr��rzrr�c���eZdZd�Z�fd�Zy)�KDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactoryc��y)NFrrs   rr&zVDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactory.allowQuery�s��rc����||��rr)rrrr�s   �rr(zUDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactory.sendReply�s���(��v�6�6rN)rrrr&r()r�s�rr+r��s
���
�
7rr+Nr�)r3r	r]r�r�rr�rrR�rCode�EREFUSED)	rr+r�r�r�r#r%rr�s	        @r�test_allowQueryFalsez*DNSServerFactoryTests.test_allowQueryFalse�s����	��	�	7�f�&=�&=�	7�
$�%������
����K�K�M���
�
��-.�F�F�)�!����6����������5rc����dg|_g��fd�}t�}tjd�}t	|||�|j||�|j
�||dfg�y)a�
        Assert that the named method is called with the given message when it is
        passed to L{DNSServerFactory.messageReceived}.

        @param methodName: The name of the method which is expected to be
            called.
        @type methodName: L{str}

        @param message: The message which is expected to be passed to the
            C{methodName} method.
        @type message: L{dns.Message}
        Nc�.���j|||f�yr�rO)r#r$r%�receivedMessagess   �r�fakeHandlerz?DNSServerFactoryTests._messageReceivedTest.<locals>.fakeHandlers����#�#�W�h��$@�Ar)�queriesr=r	r]�setattrr�rR)r�
methodNamer#r�r$r�r�s      @r�_messageReceivedTestz*DNSServerFactoryTests._messageReceivedTestsj��� �&�����	B� �>���)�)�$�/�����[�1������2����)�W�h��,E�+F�Grc�l�|jdtjtj���y)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_QUERY} on to L{DNSServerFactory.handleQuery}.
        �handleQuery��opCodeN)r�rr��OP_QUERYr`s r�test_queryMessageReceivedz/DNSServerFactoryTests.test_queryMessageReceived s!��
	
�!�!�-����C�L�L�1Q�Rrc�l�|jdtjtj���y)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_INVERSE} on to L{DNSServerFactory.handleInverseQuery}.
        �handleInverseQueryr�N)r�rr��
OP_INVERSEr`s r� test_inverseQueryMessageReceivedz6DNSServerFactoryTests.test_inverseQueryMessageReceived's$��
	
�!�!� �#�+�+�S�^�^�"D�	
rc�l�|jdtjtj���y)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_STATUS} on to L{DNSServerFactory.handleStatus}.
        �handleStatusr�N)r�rr��	OP_STATUSr`s r�test_statusMessageReceivedz0DNSServerFactoryTests.test_statusMessageReceived0�!��
	
�!�!�.�#�+�+�S�]�]�2S�Trc�l�|jdtjtj���y)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_NOTIFY} on to L{DNSServerFactory.handleNotify}.
        �handleNotifyr�N)r�rr��	OP_NOTIFYr`s r�test_notifyMessageReceivedz0DNSServerFactoryTests.test_notifyMessageReceived7r�rc�l�|jdtjtj���y)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_UPDATE} on to L{DNSServerFactory.handleOther}.

        This may change if the implementation ever covers update messages.
        �handleOtherr�N)r�rr��	OP_UPDATEr`s r�test_updateMessageReceivedz0DNSServerFactoryTests.test_updateMessageReceived>s!��	
�!�!�-����C�M�M�1R�Src���t�t�}}tj�}|j|�|j	|j
|g�|j|�|j	|j
||g�|j
|�|j	|j
|g�|j
|�|j	|j
g�y)z�
        The C{connectionMade} and C{connectionLost} methods of
        L{DNSServerFactory} cooperate to keep track of all L{DNSProtocol}
        objects created by a factory which are connected.
        N)rir	r]�connectionMaderR�connections�connectionLost)r�protoA�protoBr�s    r�test_connectionTrackingz-DNSServerFactoryTests.test_connectionTrackingGs��� ��6�8����)�)�+�����v�&�����,�,�v�h�7����v�&�����,�,�v�v�.>�?����v�&�����,�,�v�h�7����v�&�����,�,�b�1rc��tj�}|jd�|jd�tj�}t�|_|jt
j|j|t�d��}|j\\}}|j||jd�y)z�
        L{server.DNSServerFactory.handleQuery} takes the first query from the
        supplied message and dispatches it to
        L{server.DNSServerFactory.resolver.query}.
        �one.example.comstwo.example.comN�r#r$r%r)rr�r�r	r]r@r^r�rCr�r=rrRr�)rrWr�r�rErs      r�test_handleQueryz&DNSServerFactoryTests.test_handleQueryXs���
�K�K�M��	�
�
�%�&�	�
�
�%�&��#�#�%��$�&��
�����*�*�
�M�M��!�^��
�
���6�6����&������	�	�!��-rc���	�tj�}tj��G�fd�d�}|�|_g�	�	fd�}||_t
j�}|jd�t�}t�}|j|||��t�}�j|�|j�	||||fifg�y)aC
        L{server.DNSServerFactory.handleQuery} adds
        L{server.DNSServerFactory.resolver.gotResolverResponse} as a callback to
        the deferred returned by L{server.DNSServerFactory.resolver.query}. It
        is called with the query response, the original protocol, message and
        origin address.
        c���eZdZ�fd�Zy)�DDNSServerFactoryTests.test_handleQueryCallback.<locals>.FakeResolverc����Srr�rrr�ds   �rrEzJDNSServerFactoryTests.test_handleQueryCallback.<locals>.FakeResolver.query{�����rN�rrrrE�rs�r�FakeResolverr
z����
rrc�,���j||f�yrr�)rr�gotResolverResponseArgss  �r�fakeGotResolverResponsezODNSServerFactoryTests.test_handleQueryCallback.<locals>.fakeGotResolverResponse�s���#�*�*�D�&�>�:rrr	N)r	r]r�Deferredr^�gotResolverResponserr�r�r=rir��callbackrR)
rr�rrrWr�r��
dummyResponserrs
        @@r�test_handleQueryCallbackz.DNSServerFactoryTests.test_handleQueryCallbackns����
�#�#�%���N�N���	�	�"�^��
�"$��	;�!8����K�K�M��	�
�
�%�&�#�~���x��	�
�
�a�,��
�M���
�	�
�
�=�!����#��l�A�|�<�b�
A�B�	
rc����	�tj�}tj��G�fd�d�}|�|_g�	�	fd�}||_t
j�}|jd�t�}t�}|j|||��tjt��}�j|�|j!�	||||fifg�y)a?
        L{server.DNSServerFactory.handleQuery} adds
        L{server.DNSServerFactory.resolver.gotResolverError} as an errback to
        the deferred returned by L{server.DNSServerFactory.resolver.query}. It
        is called with the query failure, the original protocol, message and
        origin address.
        c���eZdZ�fd�Zy)�CDNSServerFactoryTests.test_handleQueryErrback.<locals>.FakeResolverc����Srrrs   �rrEzIDNSServerFactoryTests.test_handleQueryErrback.<locals>.FakeResolver.query�rrNrrs�rrr �rrrc�,���j||f�yrr�)rr�gotResolverErrorArgss  �r�fakeGotResolverErrorzKDNSServerFactoryTests.test_handleQueryErrback.<locals>.fakeGotResolverError�s��� �'�'��v��7rrr	N)r	r]rrr^�gotResolverErrorrr�r�r=rir�r
�Failurer3�errbackrR)
rr�rr$rWr�r��stubFailurerr#s
        @@r�test_handleQueryErrbackz-DNSServerFactoryTests.test_handleQueryErrback�s����
�#�#�%���N�N���	�	�"�^��
�!��	8�2����K�K�M��	�
�
�%�&�#�~���x��	�
�
�a�,��
�M��o�o�i�k�2��	�	�	�+����� �[�,��<�$P�RT�#U�"V�	
rc��tj�}g}g}g}|jtj|j
|||ft�t
j�d��}|j\\}}|j|j|�|j|j|�|j|j|�y)z�
        L{server.DNSServerFactory.gotResolverResponse} accepts a tuple of
        resource record lists and triggers a response message containing those
        resource record lists.
        N�r$r#r%)
r	r]r�r5r8rrr�rr��answers�	authority�
additional)rr�r,r-r.r�r#rs        r�test_gotResolverResponsez.DNSServerFactoryTests.test_gotResolverResponse�s���
�#�#�%�����	��
�����1�1�
�!�!�
�i��,�$�&��K�K�M��

�
���V�V��
��F��
�
�g�o�o�w�/��
�
�g�'�'��3��
�
�g�(�(�*�5rc
�@�t�}t|_tj�}d|_|j
t|jgggfd|d��}|jdt|tjggg��f|j|jf�y)z�
        L{server.DNSServerFactory.gotResolverResponse} calls
        L{server.DNSServerFactory._responseFromMessage} to generate a response.
        r�Nr+r)r#r�r,r-r.)r!r�_responseFromMessagerr�r�r�rrrR�dict�OKrr�rr��requestr�s    r�0test_gotResolverResponseCallsResponseFromMessagezFDNSServerFactoryTests.test_gotResolverResponseCallsResponseFromMessage�s���
-�.��'-��$��+�+�-�� ��������'�'�
��R�L����

�
��	
�����#��&�&�� �!��	
��V�V�Q�X�X��	
rc��tj�}tjdd��}|j	|��f}|j||�y)z�
        L{server.DNSServerFactory._responseFromMessage} generates a response
        message which is a copy of the request message.
        F)�answer�recAv�r#N)r	r]rr�r1�assertIsNot�rr�r5�responses    r�"test_responseFromMessageNewMessagez8DNSServerFactoryTests.test_responseFromMessageNewMessage�sH��
�)�)�+���+�+�U�%�8���0�0��0�A�C������(�+rc�0�tj�}d|_|jt	j
d����}d|_|jt	j
d����}|j
d|j|jf�y)z�
        L{server.DNSServerFactory._responseFromMessage} generates a response
        message whose C{recAV} attribute is L{True} if
        L{server.DNSServerFactory.canRecurse} is L{True}.
        TF)r9r:�TFN)r	r]r�r1rr�rRr9�rr��	response1�	response2s    r�*test_responseFromMessageRecursionAvailablez@DNSServerFactoryTests.test_responseFromMessageRecursionAvailablesw���)�)�+��!����0�0����5�9Q�0�R�	�"����0�0����4�9P�0�Q�	��������)�/�/�(J�Krc���tj�}tj�}d|_|j|��}|j
|j|j�y)z�
        L{server.DNSServerFactory._responseFromMessage} generates a response
        message whose C{timeReceived} attribute has the same value as that found
        on the request.
        i�r:N)r	r]rr�r�r1rRr<s    r�$test_responseFromMessageTimeReceivedz:DNSServerFactoryTests.test_responseFromMessageTimeReceivedsT���)�)�+���+�+�-��#����/�/��/�@������-�-�x�/D�/D�Erc���tj�}tj�}d|_|j|��}|j
|j|j�y)z�
        L{server.DNSServerFactory._responseFromMessage} generates a response
        message whose C{maxSize} attribute has the same value as that found
        on the request.
        rr:N)r	r]rr��maxSizer1rRr<s    r�test_responseFromMessageMaxSizez5DNSServerFactoryTests.test_responseFromMessageMaxSizesQ���)�)�+���+�+�-������/�/��/�@��������(�*:�*:�;rc�t�|jtjtjj
�y)z{
        L{server.DNSServerFactory} has a C{_messageFactory} attribute which is
        L{dns.Message} by default.
        N)r�rr�r	r]�_messageFactoryr`s r�test_messageFactoryz)DNSServerFactoryTests.test_messageFactory(s"��
	
�
�
�c�k�k�6�#:�#:�#J�#J�Krc
��tj�}|jtdt�tj
�}|j
t|j|tj��}|jdt|j|tj|jd��f|j|jf�y)a4
        L{server.DNSServerFactory._responseFromMessage} calls
        C{dns._responseFromMessage} to generate a response
        message from the request message. It supplies the request message and
        other keyword arguments which should be passed to the response message
        initialiser.
        r1�r#r�rF)�responseConstructorr#r�r9�authN)r	r]r�rrr�r�rr1r3rRr2rKr�rrr4s    r�+test_responseFromMessageCallsMessageFactoryzADNSServerFactoryTests.test_responseFromMessageCallsMessageFactory/s����)�)�+���
�
�3�.��7��+�+�-������W�9�9�7�RU�RX�RX�
�
��	
�����(/�(?�(?�#��&�&�!�,�,���	
��V�V�Q�X�X��	
rc�d�tj�}|jtj�tj
d��g��}|jtj�tj
d��g��}|j
d|j|jf�y)z�
        L{server.DNSServerFactory._responseFromMessage} marks the response
        message as authoritative if any of the answer records are authoritative.
        T)rP)r#r,Fr@N)r	r]r1rr��RRHeaderrRrPrAs    r�,test_responseFromMessageAuthoritativeMessagezBDNSServerFactoryTests.test_responseFromMessageAuthoritativeMessageLs���
�)�)�+���0�0��K�K�M�C�L�L�d�,C�+D�1�
�	��0�0��K�K�M�C�L�L�e�,D�+E�1�
�	�	
����
�^�^�Y�^�^�,�	
rc	��td��}tj�g}tj�g}tj�g}t|dg|j|||ft�tj�d��y)z�
        L{server.DNSServerFactory.gotResolverResponse} logs the total number of
        records in the response if C{verbose > 0}.
        r�r�zLookup found 3 recordsNr+)r!rrSrXrr=r�)rr�r,r-r.s     r�test_gotResolverResponseLoggingz5DNSServerFactoryTests.test_gotResolverResponseLogging]sm��

'�q�1���<�<�>�"���\�\�^�$�	��l�l�n�%�
���
%�&�
�!�!�
�i��,�!�^��K�K�M��	
rc��tt�g��}tj�}|j	d�tj
�g}g}g}|j
tj|j|||ft�|d��}|j\\}\}}	}
}|j|jjd�|j||�|j|	|�|j|
|�y)z�
        L{server.DNSServerFactory.gotResolverResponse} caches the response if at
        least one cache was provided in the constructor.
        rnsexample.comNr+)r!rGrr�r�rSr�rJrr=rrRr�r�)rr�rW�expectedAnswers�expectedAuthority�expectedAdditionalr�rEr,r-r.rs            r�test_gotResolverResponseCachingz5DNSServerFactoryTests.test_gotResolverResponseCachingqs���

'�|�~�.>�?���K�K�M��	�
�
�>�"��<�<�>�*����������-�-�
�!�!�
�/�1C�D�!�^���

�
��=>�F�F�9�1��0��)�Z�6���������.�9��
�
�g��/��
�
�i�!2�3��
�
�j�"4�5rc�~�t�}t|_tj�}d|_|j
t|jtjtj��d|d��}|jdt|tj��f|j |j"f�y)z�
        L{server.DNSServerFactory.gotResolverError} calls
        L{server.DNSServerFactory._responseFromMessage} to generate a response.
        r�Nr+rrN)r!rr1rr�r�r�rr%r
r&r�DomainErrorrRr2�ENAMErrr4s    r�-test_gotResolverErrorCallsResponseFromMessagezCDNSServerFactoryTests.test_gotResolverErrorCallsResponseFromMessage�s���
-�.��'-��$��+�+�-�� ��������$�$��O�O�E�-�-�/�0����

�
��	
���
��g�S�Y�Y�7�8�1�6�6�1�8�8�:L�	
rc�>�tj�}|jtj|j
t
j|�t�tj�d��}|j\\}}|j|j|�y)a{
        L{server.DNSServerFactory.gotResolver} accepts a L{failure.Failure} and
        triggers a response message whose rCode corresponds to the DNS error
        contained in the C{Failure}.

        @param responseError: The L{Exception} instance which is expected to
            trigger C{expectedMessageCode} when it is supplied to
            C{gotResolverError}
        @type responseError: L{Exception}

        @param expectedMessageCode: The C{rCode} which is expected in the
            message returned by C{gotResolverError} in response to
            C{responseError}.
        @type expectedMessageCode: L{int}
        Nr+)
r	r]r�r5r8r%r
r&rr�rrRr�)r�
responseError�expectedMessageCoder�r�r#rs       r�_assertMessageRcodeForErrorz1DNSServerFactoryTests._assertMessageRcodeForError�s~�� 
�#�#�%������1�1�
����O�O�M�*�$�&��K�K�M��

�
���V�V��
��F�������(;�<rc�h�|jtj�tj�y)z�
        L{server.DNSServerFactory.gotResolver} triggers a response message with
        an C{rCode} of L{dns.ENAME} if supplied with a L{error.DomainError}.
        N)rcrr]rr^r`s r� test_gotResolverErrorDomainErrorz6DNSServerFactoryTests.test_gotResolverErrorDomainError�s!��
	
�(�(��):�):�)<�c�i�i�Hrc�h�|jtj�tj�y)z�
        L{server.DNSServerFactory.gotResolver} triggers a response message with
        an C{rCode} of L{dns.ENAME} if supplied with a
        L{error.AuthoritativeDomainError}.
        N)rcr�AuthoritativeDomainErrorrr^r`s r�-test_gotResolverErrorAuthoritativeDomainErrorzCDNSServerFactoryTests.test_gotResolverErrorAuthoritativeDomainError�s!��	
�(�(��)G�)G�)I�3�9�9�Urc��|jt�tj�|j	t�}|jt
|�d�y)z�
        L{server.DNSServerFactory.gotResolver} triggers a response message with
        an C{rCode} of L{dns.ESERVER} if supplied with another type of error and
        logs the error.
        r�N)rc�KeyErrorr�ESERVER�flushLoggedErrorsrR�len)rr�s  r�test_gotResolverErrorOtherErrorz5DNSServerFactoryTests.test_gotResolverErrorOtherError�s>��	
�(�(���S�[�[�A��"�"�8�,������Q���#rc	���td��}t|dg|jtjtj��t�tj�d��y)zZ
        L{server.DNSServerFactory.gotResolver} logs a message if C{verbose > 0}.
        r�r�z
Lookup failedNr+)
r!rXr%r
r&rr]r=rr�r�s  r�test_gotResolverErrorLoggingz2DNSServerFactoryTests.test_gotResolverErrorLogging�sN��
'�q�1����
��
����O�O�E�-�-�/�0�!�^��K�K�M��	
rc����tj�}g��fd�|_tjdd��}t�t�g|_t�t�g|_t�t�g|_|jtjtj��d|d��|jtjdd��g��y)z�
        L{server.DNSServerFactory.gotResolverError} does not allow request
        attributes to leak into the response ie it sends a response with AD, CD
        set to 0 and empty response record sections.
        c�&���j|�Srr��r$r=r%�	responsess   �rr�zUDNSServerFactoryTests.test_gotResolverErrorResetsResponseAttributes.<locals>.<lambda>�����	�@P�@P��A
�rT��
authenticData�checkingDisabledNr+��r�r8)r	r]r(rr�rir,r-r.r%r
r&rr]rR�rr�r5rts   @r�-test_gotResolverErrorResetsResponseAttributeszCDNSServerFactoryTests.test_gotResolverErrorResetsResponseAttributes�s�����)�)�+���	�
����+�+�D�4�H��!�8�V�X�.���#�X�v�x�0���$�h���1���� � ��O�O�E�-�-�/�0����		!�	
�	
���#�+�+�A�d�;�<�i�Hrc���tj�}g��fd�|_tjdd��}t�t�g|_t�t�g|_t�t�g|_|jgggfd|d��|jtjdd��g��y)a
        L{server.DNSServerFactory.gotResolverResponse} does not allow request
        attributes to leak into the response ie it sends a response with AD, CD
        set to 0 and none of the records in the request answer sections are
        copied to the response.
        c�&���j|�Srr�rss   �rr�zXDNSServerFactoryTests.test_gotResolverResponseResetsResponseAttributes.<locals>.<lambda>
rurTrvNr+rrz)r	r]r(rr�rir,r-r.rrRr{s   @r�0test_gotResolverResponseResetsResponseAttributeszFDNSServerFactoryTests.test_gotResolverResponseResetsResponseAttributess�����)�)�+���	�
����+�+�D�4�H��!�8�V�X�.���#�X�v�x�0���$�h���1����#�#�
��R�L�4��$�	$�	
�	
���#�+�+�A�d�;�<�i�Hrc�>�tj�}t�}tj�}|jtj|jt
�||��}|j\}}|j|||f�|j|i�y)z�
        If L{server.DNSServerFactory.sendReply} is supplied with a protocol
        *and* an address tuple it will supply that address to
        C{protocol.writeMessage}.
        r+N)rr�rir	r]r�r5r8r(rrR)rrWr�r�r�rrs       r�test_sendReplyWithAddressz/DNSServerFactoryTests.test_sendReplyWithAddresss���
�K�K�M���x���#�#�%������1�1�
�K�K�$�&�� �
�
���v�v���f������<�0�1������$rc�(�tj�}tj�}|j	t
j|jt�|d��}|j\}}|j||f�|j|i�y)z�
        If L{server.DNSServerFactory.sendReply} is supplied with a protocol but
        no address tuple it will supply only a message to
        C{protocol.writeMessage}.
        Nr+)
rr�r	r]r�r5r8r(rrR)rrWr�r�rrs      r�test_sendReplyWithoutAddressz2DNSServerFactoryTests.test_sendReplyWithoutAddress,s��
�K�K�M���#�#�%������1�1�
�K�K�$�&���
�
���v�v���f������t�$������$rc���|jtjdd��tj�}d|_tjd��}t|ddg|jt�|d�	�y)
z�
        If L{server.DNSServerFactory.sendReply} logs a "no answers" message if
        the supplied message has no answers.
        r�c��y�Ni�Qrrrrr�zFDNSServerFactoryTests.test_sendReplyLoggingNoAnswers.<locals>.<lambda>Dr)r�Qr�r�zReplying with no answers� Processed query in 1.000 secondsNr+)
r�r	r�rr�r�r]rXr(r=r�s   r�test_sendReplyLoggingNoAnswersz4DNSServerFactoryTests.test_sendReplyLoggingNoAnswers?s`��
	
�
�
�6�;�;��
�6��K�K�M������#�#�A�.����
'�)K�L�
�K�K�!�^���
	
rc��|jtjdd��tj�}|j
j
tjtjd����|jj
tjtjd����|jj
tjtjd����d|_tjd��}t|gd�|jt�|d	�
�y	)z�
        If L{server.DNSServerFactory.sendReply} logs a message for answers,
        authority, additional if the supplied a message has records in any of
        those sections.
        r�c��yr�rrrrr�zHDNSServerFactoryTests.test_sendReplyLoggingWithAnswers.<locals>.<lambda>Wr)rz	127.0.0.1)�payloadr�r�r�)z*Answers are <A address=127.0.0.1 ttl=None>z+Authority is <A address=127.0.0.1 ttl=None>z,Additional is <A address=127.0.0.1 ttl=None>r�Nr+)r�r	r�rr�r,rOrS�Record_Ar-r.r�r]rXr(r=r�s   r� test_sendReplyLoggingWithAnswersz6DNSServerFactoryTests.test_sendReplyLoggingWithAnswersQs���	
�
�
�6�;�;��
�6��K�K�M��	�	�	������c�l�l�;�.G�H�I�	�����3�<�<����[�0I�J�K�	�����C�L�L����k�1J�K�L�����#�#�A�.����
�
�K�K�!�^���	
rc�2�tj�}|jtj|j
t
j�t�d��}|j\\}}|j|jtj�y)z�
        L{server.DNSServerFactory.handleInverseQuery} triggers the sending of a
        response message with C{rCode} set to L{dns.ENOTIMP}.
        Nr	)r	r]r�r5r8r�rr�rrRr��ENOTIMP�rr�r�r#rs     r�test_handleInverseQueryz-DNSServerFactoryTests.test_handleInverseQuerylsu��

�#�#�%������1�1�
� � ��K�K�M�$�&��
�
���V�V��
��F����������4rc��td��}t|dg|jtj�t�d��y)zz
        L{server.DNSServerFactory.handleInverseQuery} logs the message origin
        address if C{verbose > 0}.
        r�r�zInverse query from ('::1', 53)�z::1r�r	N)r!rXr�rr�r=r�s  r�test_handleInverseQueryLoggingz4DNSServerFactoryTests.test_handleInverseQueryLogging}s9��

'�q�1����
-�.�
� � ��K�K�M�!�^��
	
rc�2�tj�}|jtj|j
t
j�t�d��}|j\\}}|j|jtj�y)z�
        L{server.DNSServerFactory.handleStatus} triggers the sending of a
        response message with C{rCode} set to L{dns.ENOTIMP}.
        Nr	)r	r]r�r5r8r�rr�rrRr�r�r�s     r�test_handleStatusz'DNSServerFactoryTests.test_handleStatus��s��

�#�#�%������1�1�
�N�N��K�K�M�$�&��
�
���V�V��
��F����������4rc��td��}t|dg|jtj�t�d��y)zt
        L{server.DNSServerFactory.handleStatus} logs the message origin address
        if C{verbose > 0}.
        r�r�zStatus request from ('::1', 53)r�r	N)r!rXr�rr�r=r�s  r�test_handleStatusLoggingz.DNSServerFactoryTests.test_handleStatusLogging��7��

'�q�1����
.�/�
�N�N��K�K�M�!�^��
	
rc�2�tj�}|jtj|j
t
j�t�d��}|j\\}}|j|jtj�y)z�
        L{server.DNSServerFactory.handleNotify} triggers the sending of a
        response message with C{rCode} set to L{dns.ENOTIMP}.
        Nr	)r	r]r�r5r8r�rr�rrRr�r�r�s     r�test_handleNotifyz'DNSServerFactoryTests.test_handleNotify�r�rc��td��}t|dg|jtj�t�d��y)zt
        L{server.DNSServerFactory.handleNotify} logs the message origin address
        if C{verbose > 0}.
        r�r�zNotify message from ('::1', 53)r�r	N)r!rXr�rr�r=r�s  r�test_handleNotifyLoggingz.DNSServerFactoryTests.test_handleNotifyLogging�r�rc�2�tj�}|jtj|j
t
j�t�d��}|j\\}}|j|jtj�y)z�
        L{server.DNSServerFactory.handleOther} triggers the sending of a
        response message with C{rCode} set to L{dns.ENOTIMP}.
        Nr	)r	r]r�r5r8r�rr�rrRr�r�r�s     r�test_handleOtherz&DNSServerFactoryTests.test_handleOther�ss��

�#�#�%������1�1�
�M�M��K�K�M�$�&��
�
���V�V��
��F����������4rc��td��}t|dg|jtj�t�d��y)zs
        L{server.DNSServerFactory.handleOther} logs the message origin address
        if C{verbose > 0}.
        r�r�z$Unknown op code (0) from ('::1', 53)r�r	N)r!rXr�rr�r=r�s  r�test_handleOtherLoggingz-DNSServerFactoryTests.test_handleOtherLogging�s7��

'�q�1����
3�4�
�M�M��K�K�M�!�^��
	
rN)Drrrrrarerlrprtr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rr)r/r6r>rDrFrIrLrQrTrVr[r_rcrerhrnrpr|rr�r�r�r�r�r�r�r�r�r�r�r�rrrrZrZ�s^���Y�K�

�

�

�
�.;�	
�?�S�<�G�P�I�J�2=�F�
�"
�&
�,,�%�,6�:H�8S�
�U�U�T�2�".�,&
�P%
�N6�0
�B	,�L�F�<�L�
�:
�"
�(6�8
�.=�:I�V�$�

�I�0I�.%�(%�&
�$
�65�"

�5�"

�5�"

�5�"

rrZN)r�zope.interface.verifyr�twisted.internetr�twisted.internet.interfacesr�
twisted.namesrrrr	�twisted.pythonr
r�
twisted.trialrr3rrr]r!r+r5r=r@rGrX�TestCaserZrrr�<module>r�s����.�"�8�5�5�'�"��i��(���!8�!8��B5�f�5�5�5�:7�7�0��"0�0�06�6�0V�@O
�H�-�-�O
r

Zerion Mini Shell 1.0