
    Vh                         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y)z!
Tests for L{twisted.names.tap}.
    )ThreadedResolver)Resolver)PORT)ResolverChain)SecondaryAuthorityService)Options_buildResolvers)platform)
UsageError)SynchronousTestCasec                   8    e Zd ZdZddZddZddZddZddZy)	OptionsTestszf
    Tests for L{Options}, defining how command line arguments for the DNS server
    are parsed.
    Nc                 0   t               }| j                  t        |j                  ddg       | j                  t        |j                  ddg       | j                  t        |j                  ddg       | j                  t        |j                  ddg       y)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     K/home/dcms/DCMS/lib/python3.12/site-packages/twisted/names/test/test_tap.pytest_malformedSecondaryz$OptionsTests.test_malformedSecondary   s     )*g&:&:]B<OP*g&:&:]I<VW,,}o.N	
 	  78	
    c                     t               }|j                  ddg       | j                  dt        fdgfg|j                         y)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+   sD     )m-BCDIt,}o>?ATATUr   c                 ~    t               }|j                  ddg       | j                  ddgfg|j                         y)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   s@    
 )m-GHI,}o>?ATATUr   c                 0   t               }|j                  g d       | j                  t        |j                        d       |j                  d   }| j                  |j                  d   t               | j                  |j                  d       | j                  |j                  d       |j                  d   }| j                  |j                  d   t               | j                  |j                  d       | j                  |j                  d       y	)
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.LLO	gll1o/HI**I6$/LLO	gll1o/HI**I6$/r   c                    t               }|j                  g d       t        |      \  }}|D ]M  }t        |t              s|j
                  d   }t        |t              s4|j                  j                          O t        j                         dk7  r[ddlm} |j                  D ]F  }| j                  |j                  j                   t"        j$                         |j                          H | j'                  |d   t               y)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.internetr1   _newTimedCallsr   func__func__r   _cleanupr)   )r   r   caclxrecurserr1   s          r   test_recursiveConfigurationz(OptionsTests.test_recursiveConfigurationV   s     )IJ )B  	1A!]+;;r?h1''..0		1 ( 1++   2B2K2KL
 	bfm4r   )returnN)	__name__
__module____qualname____doc__r   r   r#   r-   r@    r   r   r   r      s"    

$VV00 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      s6    3 ) " / = 6 + + 6c5& c5r   