U
    
W[–!  ã                   @   s8  d dl mZmZ d dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ e ¡ srdZndZz
ej W n ek
r˜   d	ZY nX dZG d
d„ deƒZG dd„ deƒZG dd„ dejeƒZG dd„ dejeƒZG dd„ dejeƒZG dd„ dejeƒZG dd„ dejƒZG dd„ dejeƒZdS )é    )ÚdivisionÚabsolute_importN)Úunittest)ÚIPv4AddressÚUNIXAddressÚIPv6Address©ÚHostnameAddress)ÚnativeString)Úplatformz"Platform does not support symlinksz&Platform doesn't support UNIX sockets.c                   @   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   s&   |   ¡ }|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   ZaddrÚdr   r   r   Ú	test_hash)   s    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_differentNamesComparison3   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)ZflushWarningsÚassertEqualÚDeprecationWarningÚlen)r   Z
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)Zhostú%r©Zportz%dN)r#   r$   r%   ÚaddressArgSpecr   r   r   r   r&   K   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}.
    ))Zhostnamer)   r+   c                 C   s
   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   V   s    z!HostnameAddressTests.buildAddressc                 C   s
   t ddƒS )zw
        Like L{buildAddress}, but with a different hostname.

        @return: A L{HostnameAddress} instance.
        s   example.netr   r   r   r   r   r   r   _   s    z*HostnameAddressTests.buildDifferentAddressN)r#   r$   r%   Ú__doc__r,   r   r   r   r   r   r   r-   P   s   	r-   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚIPv4AddressTCPTestsc                 C   s   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   k   s    z IPv4AddressTCPTests.buildAddressc                 C   s   t dddƒS )úK
        Like L{buildAddress}, but with a different fixed address.
        r0   ú	127.0.0.2r   r2   r   r   r   r   r   t   s    z)IPv4AddressTCPTests.buildDifferentAddressN©r#   r$   r%   r   r   r   r   r   r   r/   i   s   	r/   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚIPv4AddressUDPTestsc                 C   s   t dddƒS )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.
        ÚUDPr1   r   r2   r   r   r   r   r   ~   s    z IPv4AddressUDPTests.buildAddressc                 C   s   t dddƒS )r3   r7   r4   r   r2   r   r   r   r   r   ‡   s    z)IPv4AddressUDPTests.buildDifferentAddressNr5   r   r   r   r   r6   |   s   	r6   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚIPv6AddressTestsr'   c                 C   s   t dddƒS )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.
        r0   z::1r   ©r   r   r   r   r   r   ’   s    zIPv6AddressTests.buildAddressc                 C   s   t dddƒS )r3   r0   z::2r   r9   r   r   r   r   r   ›   s    z&IPv6AddressTests.buildDifferentAddressN)r#   r$   r%   r,   r   r   r   r   r   r   r8      s   	r8   c                   @   sX   e Zd ZeZdZdd„ Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
esBee
_dd„ ZesTee_dS )ÚUNIXAddressTests©)Únamer*   c                 C   s   |   ¡ | _|   ¡ | _d S ©N)ÚmktempÚ_socketAddressÚ_otherAddressr   r   r   r   ÚsetUp§   s    
zUNIXAddressTests.setUpc                 C   s
   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   r?   r   r   r   r   r   ¬   s    zUNIXAddressTests.buildAddressc                 C   s
   t | jƒS )r3   )r   r@   r   r   r   r   r   ´   s    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
   r?   r   r   r   r   Ú	test_repr»   s    ÿzUNIXAddressTests.test_reprc              	   C   sh   |   ¡ }t| jdƒJ| _t tj | j¡|¡ |  t	| jƒt	|ƒ¡ |  t	|ƒt	| jƒ¡ W 5 Q R X dS )zU
        UNIXAddress objects compare as equal if they link to the same file.
        ÚwN)
r>   Úopenr?   ÚfdÚosÚsymlinkÚpathÚabspathr   r   ©r   ZlinkNamer   r   r   Útest_comparisonOfLinkedFilesÄ   s    ÿ
ÿz-UNIXAddressTests.test_comparisonOfLinkedFilesc              	   C   sZ   |   ¡ }t| jdƒ<| _t tj | j¡|¡ |  t	t
| jƒƒt	t
|ƒƒ¡ W 5 Q R X dS )zU
        UNIXAddress Objects that compare as equal have the same hash value.
        rE   N)r>   rF   r?   rG   rH   rI   rJ   rK   r   Úhashr   rL   r   r   r   Útest_hashOfLinkedFilesÓ   s    
ÿz'UNIXAddressTests.test_hashOfLinkedFilesN)r#   r$   r%   ÚunixSkipÚskipr,   rA   r   r   rD   rM   ÚsymlinkSkiprO   r   r   r   r   r:   £   s   		r:   c                   @   sJ   e Zd ZdZeZdZdd„ Zdd„ Zdd„ Z	d	d
„ Z
es>ee
_dd„ ZdS )ÚEmptyUNIXAddressTestszJ
    Tests for L{UNIXAddress} operations involving a L{None} address.
    r;   c                 C   s   |   ¡ | _d S r=   )r>   r?   r   r   r   r   rA   é   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   s
   t | jƒS )zN
        Like L{buildAddress}, but with a random temporary directory.
        rB   r   r   r   r   r   ö   s    z+EmptyUNIXAddressTests.buildDifferentAddressc              	   C   sh   |   ¡ }t| jdƒJ| _t tj | j¡|¡ |  t	| jƒt	dƒ¡ |  t	dƒt	| jƒ¡ W 5 Q R X dS )z†
        A UNIXAddress referring to a L{None} address does not compare equal to a
        UNIXAddress referring to a symlink.
        rE   N)
r>   rF   r?   rG   rH   rI   rJ   rK   ZassertNotEqualr   rL   r   r   r   rM   ý   s    ÿ
ÿz2EmptyUNIXAddressTests.test_comparisonOfLinkedFilesc                 C   s&   |   ¡ }|di}|  ||   ¡  ¡ dS )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  s    z$EmptyUNIXAddressTests.test_emptyHashN)r#   r$   r%   r.   rP   rQ   r,   rA   r   r   rM   rR   rT   r   r   r   r   rS   á   s   	rS   ) Z
__future__r   r   rH   ZsocketZtwisted.trialr   Ztwisted.internet.addressr   r   r   r	   Ztwisted.python.compatr
   Ztwisted.python.runtimer   Z_supportsSymlinksrR   ZAF_UNIXÚAttributeErrorrP   Úobjectr   r&   ZTestCaser-   ZSynchronousTestCaser/   r6   r8   r:   rS   r   r   r   r   Ú<module>   s:   

/ÿÿ>ÿ