
    Yf                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ dd	lmZ dd
lmZ  G d de          ZdS )z!
Tests for L{twisted.names.tap}.
    )ThreadedResolver)Resolver)PORT)ResolverChain)SecondaryAuthorityService)Options_buildResolvers)platform)
UsageError)SynchronousTestCasec                   :    e Zd ZdZd	dZd	dZd	dZd	dZd	dZdS )
OptionsTestszf
    Tests for L{Options}, defining how command line arguments for the DNS server
    are parsed.
    returnNc                 :   t                      }|                     t          |j        ddg           |                     t          |j        ddg           |                     t          |j        ddg           |                     t          |j        ddg           dS )z
        If the value supplied for an I{--secondary} option does not provide a
        server IP address, optional port number, and domain name,
        L{Options.parseOptions} raises L{UsageError}.
        --secondary 1.2.3.4z1.2.3.4:helloz1.2.3.4:hello/example.comN)r   assertRaisesr   parseOptionsselfoptionss     M/var/www/html/env/lib/python3.11/site-packages/twisted/names/test/test_tap.pytest_malformedSecondaryz$OptionsTests.test_malformedSecondary   s     ))*g&:]B<OPPP*g&:]I<VWWW,}o.N	
 	
 	
 	 78	
 	
 	
 	
 	
    c                     t                      }|                    ddg           |                     dt          fdgfg|j                   dS )z
        An argument of the form C{"ip/domain"} is parsed by L{Options} for the
        I{--secondary} option and added to its list of secondaries, using the
        default DNS port number.
        r   z1.2.3.4/example.comr   example.comN)r   r   assertEqualr   secondariesr   s     r   test_secondaryzOptionsTests.test_secondary+   sU     ))m-BCDDDIt,}o>?ATUUUUUr   c                     t                      }|                    ddg           |                     ddgfg|j                   dS )z
        An argument of the form C{"ip:port/domain"} can be used to specify an
        alternate port number for which to act as a secondary.
        r   1.2.3.4:5353/example.com)r     r   N)r   r   r   r   r   s     r   test_secondaryExplicitPortz'OptionsTests.test_secondaryExplicitPort5   sQ    
 ))m-GHIII,}o>?ATUUUUUr   c                 D   t                      }|                    g d           |                     t          |j                  d           |j        d         }|                     |j        d         t                     |                     |j        d           |                     |j        d           |j        d         }|                     |j        d         t                     |                     |j        d           |                     |j        d           d	S )
z
        After parsing I{--secondary} options, L{Options} constructs a
        L{SecondaryAuthorityService} instance for each configured secondary.
        )r   r"   r   z1.2.3.5:5354/example.com   r   r   r#      z1.2.3.5i  N)	r   r   r   lensvcsassertIsInstancer   primary_port)r   r   	secondarys      r   test_secondaryAuthorityServicesz,OptionsTests.test_secondaryAuthorityServices>   s   
 ))  	
 	
 	
 	W\**A...LO	gl1o/HIII*I666$///LO	gl1o/HIII*I666$/////r   c                 *   t                      }|                    g d           t          |          \  }}|D ]R}t          |t                    r;|j        d         }t          |t                    r|j                                         St          j
                    dk    rNddlm} |j        D ]@}|                     |j        j        t"          j                   |                                 A|                     |d         t                     dS )z
        Recursive DNS lookups, if enabled, should be a last-resort option.
        Any other lookup method (cache, local lookup, etc.) should take
        precedence over recursive lookups
        )z--hosts-filez	hosts.txtz--recursiveposixr   )reactorN)r   r   r	   
isinstancer   	resolversr   
_parseCallcancelr
   getTypetwisted.internetr2   _newTimedCallsr   func__func__r   _cleanupr*   )r   r   caclxrecurserr2   s          r   test_recursiveConfigurationz(OptionsTests.test_recursiveConfigurationV   s    ))IIIJJJ ))B  	1 	1A!]++ 1;r?h11 1'..000 (( 100000+    2B2KLLL



bfm44444r   )r   N)	__name__
__module____qualname____doc__r   r    r$   r.   rA    r   r   r   r      s         

 
 
 
$V V V VV V V V0 0 0 00 5  5  5  5  5  5r   r   N)rE   twisted.internet.baser   twisted.names.clientr   twisted.names.dnsr   twisted.names.resolver   twisted.names.secondaryr   twisted.names.tapr   r	   twisted.python.runtimer
   twisted.python.usager   twisted.trial.unittestr   r   rF   r   r   <module>rP      s     3 2 2 2 2 2 ) ) ) ) ) ) " " " " " " / / / / / / = = = = = = 6 6 6 6 6 6 6 6 + + + + + + + + + + + + 6 6 6 6 6 6c5 c5 c5 c5 c5& c5 c5 c5 c5 c5r   