o
    ¯bJ   ã                   @   s,  d dl Z d dlZd dlmZ d dlmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZmZ e ¡  Zzej W n eyC   dZY nw dZG d	d
„ d
ƒZG dd„ deƒZG dd„ deeƒZG dd„ deeƒZG dd„ deeƒZG dd„ deeƒZeedƒG dd„ deƒƒZeedƒG dd„ deeƒƒZdS )é    N)ÚskipIf)ÚHostnameAddressÚIPv4AddressÚIPv6AddressÚUNIXAddress)ÚnativeString)Úplatform)ÚSynchronousTestCaseÚTestCaseTFc                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚAddressTestCaseMixinc                 C   s0   |   |  ¡ |  ¡ k¡ |  |  ¡ |  ¡ k¡ dS )a  
        Two different address instances, sharing the same properties are
        considered equal by C{==} and not considered not equal by C{!=}.

        Note: When applied via UNIXAddress class, this uses the same
        filename for both objects being compared.
        N)Ú
assertTrueÚbuildAddressÚassertFalse©Úself© r   úD/usr/lib/python3/dist-packages/twisted/internet/test/test_address.pyÚtest_addressComparison   s   z+AddressTestCaseMixin.test_addressComparisonc                 C   ó&   |   ¡ }|di}|  ||   ¡  ¡ dS )z“
        C{__hash__} can be used to get a hash of an address, allowing
        addresses to be used as keys in dictionaries, for instance.
        TN©r   r   ©r   ÚaddrÚdr   r   r   Ú	test_hash)   ó   zAddressTestCaseMixin.test_hashc                 C   s\   |   |  ¡ |  ¡ k¡ |   |  ¡ |  ¡ k¡ |  |  ¡ |  ¡ k¡ |  |  ¡ |  ¡ k¡ dS )z~
        Check that comparison operators work correctly on address objects
        when a different name is passed in
        N)r   r   ÚbuildDifferentAddressr   r   r   r   r   Útest_differentNamesComparison2   s   z2AddressTestCaseMixin.test_differentNamesComparisonc                 C   sH   |   |g¡}|  |d d t¡ |  |d d |¡ |  t|ƒd¡ dS )z{
        Assert that the a DeprecationWarning with the given message was
        emitted against the given method.
        r   ÚcategoryÚmessageé   N)ÚflushWarningsÚassertEqualÚDeprecationWarningÚlen)r   Ú
testMethodr   Úwarningsr   r   r   ÚassertDeprecations=   s   z'AddressTestCaseMixin.assertDeprecationsN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r&   r   r   r   r   r      s
    	r   c                   @   s   e Zd ZdZdS )ÚIPv4AddressTestCaseMixin©)Útypeú%s)Úhostú%r©Úportz%dN)r'   r(   r)   ÚaddressArgSpecr   r   r   r   r*   H   s    r*   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚHostnameAddressTestsz+
    Test case for L{HostnameAddress}.
    ))Úhostnamer-   r0   c                 C   ó
   t ddƒS )zw
        Create an arbitrary new L{HostnameAddress} instance.

        @return: A L{HostnameAddress} instance.
        s   example.comr   ©r   r   r   r   r   r   S   ó   
z!HostnameAddressTests.buildAddressc                 C   r5   )zw
        Like L{buildAddress}, but with a different hostname.

        @return: A L{HostnameAddress} instance.
        s   example.netr   r6   r   r   r   r   r   [   r7   z*HostnameAddressTests.buildDifferentAddressN)r'   r(   r)   Ú__doc__r2   r   r   r   r   r   r   r3   L   s
    r3   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚIPv4AddressTCPTestsc                 C   ó   t dddƒS )z²
        Create an arbitrary new L{IPv4Address} instance with a C{"TCP"}
        type.  A new instance is created for each call, but always for the
        same address.
        ÚTCPú	127.0.0.1r   ©r   r   r   r   r   r   e   ó   z IPv4AddressTCPTests.buildAddressc                 C   r;   )úK
        Like L{buildAddress}, but with a different fixed address.
        r<   ú	127.0.0.2r   r>   r   r   r   r   r   m   ó   z)IPv4AddressTCPTests.buildDifferentAddressN©r'   r(   r)   r   r   r   r   r   r   r:   d   ó    r:   c                   @   r9   )ÚIPv4AddressUDPTestsc                 C   r;   )z²
        Create an arbitrary new L{IPv4Address} instance with a C{"UDP"}
        type.  A new instance is created for each call, but always for the
        same address.
        ÚUDPr=   r   r>   r   r   r   r   r   u   r?   z IPv4AddressUDPTests.buildAddressc                 C   r;   )r@   rF   rA   r   r>   r   r   r   r   r   }   rB   z)IPv4AddressUDPTests.buildDifferentAddressNrC   r   r   r   r   rE   t   rD   rE   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚIPv6AddressTestsr+   c                 C   r;   )z²
        Create an arbitrary new L{IPv6Address} instance with a C{"TCP"}
        type.  A new instance is created for each call, but always for the
        same address.
        r<   z::1r   ©r   r   r   r   r   r   ‡   r?   zIPv6AddressTests.buildAddressc                 C   r;   )r@   r<   z::2r   rH   r   r   r   r   r   �   rB   z&IPv6AddressTests.buildDifferentAddressN)r'   r(   r)   r2   r   r   r   r   r   r   rG   „   s    rG   z&Platform doesn't support UNIX sockets.c                   @   sT   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zee	d
ƒdd„ ƒZ
ee	d
ƒdd„ ƒZdS )ÚUNIXAddressTests©)Únamer/   c                 C   s   |   ¡ | _|   ¡ | _d S ©N)ÚmktempÚ_socketAddressÚ_otherAddressr   r   r   r   ÚsetUpš   s   
zUNIXAddressTests.setUpc                 C   ó
   t | jƒS )z•
        Create an arbitrary new L{UNIXAddress} instance.  A new instance is
        created for each call, but always for the same address.
        ©r   rN   r   r   r   r   r   ž   s   
zUNIXAddressTests.buildAddressc                 C   rQ   )r@   )r   rO   r   r   r   r   r   ¥   ó   
z&UNIXAddressTests.buildDifferentAddressc                 C   s"   |   t|  ¡ ƒdt| jƒ ¡ dS )zn
        The repr of L{UNIXAddress} returns with the filename that the
        L{UNIXAddress} is for.
        zUNIXAddress('%s')N)r!   Úreprr   r   rN   r   r   r   r   Ú	test_repr«   s   
þzUNIXAddressTests.test_reprú"Platform does not support symlinksc                 C   s~   |   ¡ }t| jdƒ�+| _t tj | j¡|¡ |  t	| jƒt	|ƒ¡ |  t	|ƒt	| jƒ¡ W d  ƒ dS 1 s8w   Y  dS )zU
        UNIXAddress objects compare as equal if they link to the same file.
        ÚwN)
rM   ÚopenrN   ÚfdÚosÚsymlinkÚpathÚabspathr!   r   ©r   ÚlinkNamer   r   r   Útest_comparisonOfLinkedFilesµ   s   "ýz-UNIXAddressTests.test_comparisonOfLinkedFilesc                 C   sp   |   ¡ }t| jdƒ�$| _t tj | j¡|¡ |  t	t
| jƒƒt	t
|ƒƒ¡ W d  ƒ dS 1 s1w   Y  dS )zU
        UNIXAddress Objects that compare as equal have the same hash value.
        rW   N)rM   rX   rN   rY   rZ   r[   r\   r]   r!   Úhashr   r^   r   r   r   Útest_hashOfLinkedFilesÀ   s   ÿ"þz'UNIXAddressTests.test_hashOfLinkedFilesN)r'   r(   r)   r2   rP   r   r   rU   r   ÚsymlinkSkipr`   rb   r   r   r   r   rI   –   s    


rI   z&platform doesn't support UNIX sockets.c                   @   sF   e Zd ZdZdZdd„ Zdd„ Zdd„ Zee	d	ƒd
d„ ƒZ
dd„ ZdS )ÚEmptyUNIXAddressTestszJ
    Tests for L{UNIXAddress} operations involving a L{None} address.
    rJ   c                 C   s   |   ¡ | _d S rL   )rM   rN   r   r   r   r   rP   Õ   s   zEmptyUNIXAddressTests.setUpc                 C   s   t dƒS )zÍ
        Create an arbitrary new L{UNIXAddress} instance.  A new instance is
        created for each call, but always for the same address. This builds it
        with a fixed address of L{None}.
        N)r   r   r   r   r   r   Ø   s   z"EmptyUNIXAddressTests.buildAddressc                 C   rQ   )zN
        Like L{buildAddress}, but with a random temporary directory.
        rR   r   r   r   r   r   à   rS   z+EmptyUNIXAddressTests.buildDifferentAddressrV   c                 C   s~   |   ¡ }t| jdƒ�+| _t tj | j¡|¡ |  t	| jƒt	dƒ¡ |  t	dƒt	| jƒ¡ W d  ƒ dS 1 s8w   Y  dS )z†
        A UNIXAddress referring to a L{None} address does not
        compare equal to a UNIXAddress referring to a symlink.
        rW   N)
rM   rX   rN   rY   rZ   r[   r\   r]   ÚassertNotEqualr   r^   r   r   r   r`   æ   s   "ýz2EmptyUNIXAddressTests.test_comparisonOfLinkedFilesc                 C   r   )z…
        C{__hash__} can be used to get a hash of an address, even one referring
        to L{None} rather than a real path.
        TNr   r   r   r   r   Útest_emptyHashò   r   z$EmptyUNIXAddressTests.test_emptyHashN)r'   r(   r)   r8   r2   rP   r   r   r   rc   r`   rf   r   r   r   r   rd   Í   s    
rd   )rZ   ÚsocketÚunittestr   Útwisted.internet.addressr   r   r   r   Útwisted.python.compatr   Útwisted.python.runtimer   Útwisted.trial.unittestr	   r
   Ú_supportsSymlinksrc   ÚAF_UNIXÚAttributeErrorÚunixSkipr   r*   r3   r:   rE   rG   rI   rd   r   r   r   r   Ú<module>   s0   

ÿ+6