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