o
    Òó·iJ   ã                   @   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   úhC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-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)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)Ú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+   r.   c                 C   ó
   t ddƒS )zw
        Create an arbitrary new L{HostnameAddress} instance.

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

        @return: A L{HostnameAddress} instance.
        s   example.netr   Nr4   r   r   r   r   r   [   r5   z*HostnameAddressTests.buildDifferentAddressN)r%   r&   r'   Ú__doc__r0   r   r   r   r   r   r   r1   L   s
    r1   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   N©r   r   r   r   r   r   e   ó   z IPv4AddressTCPTests.buildAddressc                 C   r9   )úK
        Like L{buildAddress}, but with a different fixed address.
        r:   ú	127.0.0.2r   Nr<   r   r   r   r   r   m   ó   z)IPv4AddressTCPTests.buildDifferentAddressN©r%   r&   r'   r   r   r   r   r   r   r8   d   ó    r8   c                   @   r7   )ÚIPv4AddressUDPTestsc                 C   r9   )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   Nr<   r   r   r   r   r   u   r=   z IPv4AddressUDPTests.buildAddressc                 C   r9   )r>   rD   r?   r   Nr<   r   r   r   r   r   }   r@   z)IPv4AddressUDPTests.buildDifferentAddressNrA   r   r   r   r   rC   t   rB   rC   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚIPv6AddressTestsr)   c                 C   r9   )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   N©r   r   r   r   r   r   ‡   r=   zIPv6AddressTests.buildAddressc                 C   r9   )r>   r:   z::2r   NrF   r   r   r   r   r   �   r@   z&IPv6AddressTests.buildDifferentAddressN)r%   r&   r'   r0   r   r   r   r   r   r   rE   „   s    rE   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.
        N©r   rL   r   r   r   r   r   ž   s   
zUNIXAddressTests.buildAddressc                 C   rO   )r>   N)r   rM   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   rL   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)
rK   ÚopenrL   ÚfdÚosÚsymlinkÚpathÚabspathr    r   ©r   Z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.
        rU   N)rK   rV   rL   rW   rX   rY   rZ   r[   r    Úhashr   r\   r   r   r   Útest_hashOfLinkedFilesÀ   s   ÿ"þz'UNIXAddressTests.test_hashOfLinkedFilesN)r%   r&   r'   r0   rN   r   r   rS   r   ÚsymlinkSkipr]   r_   r   r   r   r   rG   –   s    


rG   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.
    rH   c                 C   s   |   ¡ | _d S rJ   )rK   rL   r   r   r   r   rN   Õ   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   rO   )zN
        Like L{buildAddress}, but with a random temporary directory.
        NrP   r   r   r   r   r   à   rQ   z+EmptyUNIXAddressTests.buildDifferentAddressrT   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.
        rU   N)
rK   rV   rL   rW   rX   rY   rZ   r[   Z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'   r6   r0   rN   r   r   r   r`   r]   rb   r   r   r   r   ra   Í   s    
ra   )rX   ÚsocketZunittestr   Ztwisted.internet.addressr   r   r   r   Ztwisted.python.compatr   Ztwisted.python.runtimer   Ztwisted.trial.unittestr	   r
   Z_supportsSymlinksr`   ÚAF_UNIXÚAttributeErrorZunixSkipr   r(   r1   r8   rC   rE   rG   ra   r   r   r   r   Ú<module>   s0   

ÿ+6