o
    ¯b’  ã                   @   sˆ   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„ deƒZdS )z!
Tests for L{twisted.names.tap}.
é    )ÚThreadedResolver)ÚResolver)ÚPORT)ÚResolverChain)ÚSecondaryAuthorityService)ÚOptionsÚ_buildResolvers)Úplatform)Ú
UsageError)ÚSynchronousTestCasec                   @   s8   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.
    c                 C   sZ   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Úoptions© r   ú=/usr/lib/python3/dist-packages/twisted/names/test/test_tap.pyÚtest_malformedSecondary   s   ÿýz$OptionsTests.test_malformedSecondaryc                 C   s2   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   r   r   r   Útest_secondary+   s   zOptionsTests.test_secondaryc                 C   s.   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   r   r   r   Útest_secondaryExplicitPort5   s   z'OptionsTests.test_secondaryExplicitPortc                 C   sš   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   Ú	secondaryr   r   r   Útest_secondaryAuthorityServices>   s   ÿ

z,OptionsTests.test_secondaryAuthorityServicesc                 C   s¤   t ƒ }| g d¢¡ t|ƒ\}}|D ]}t|tƒr(|jd }t|tƒr(|j ¡  qt	 
¡ dkrHddlm} |jD ]}|  |jjtj¡ | ¡  q8|  |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.internetr*   Ú_newTimedCallsr   ÚfuncÚ__func__r   Ú_cleanupr#   )r   r   ÚcaÚclÚxÚrecurserr*   r   r   r   Útest_recursiveConfigurationV   s   



€

z(OptionsTests.test_recursiveConfigurationN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r'   r9   r   r   r   r   r      s    
	r   N)r=   Ú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   r   r   r   r   Ú<module>   s   