
    VhJ                         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j                           Z	 ej$                   dZ G d	 d
      Z G d de      Z G d dee      Z G d dee      Z G d dee      Z G d dee      Z eed       G d de             Z eed       G d dee             Zy# e$ r dZY ~w xY w)    N)skipIf)HostnameAddressIPv4AddressIPv6AddressUNIXAddress)nativeString)platform)SynchronousTestCaseTestCaseFTc                   $    e Zd Zd Zd Zd Zd Zy)AddressTestCaseMixinc                     | j                  | j                         | j                         k(         | j                  | j                         | j                         k7         y)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selfs    R/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/test/test_address.pytest_addressComparisonz+AddressTestCaseMixin.test_addressComparison   sL     	))+t/@/@/BBC**,0A0A0CCD    c                 p    | j                         }|di}| j                  || j                                   y)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ds      r   	test_hashzAddressTestCaseMixin.test_hash)   5    
   "4L$++-./r   c                    | j                  | j                         | j                         k(         | j                  | j                         | j                         k(         | j                  | j                         | j                         k7         | j                  | j                         | j                         k7         y)z~
        Check that comparison operators work correctly on address objects
        when a different name is passed in
        N)r   r   buildDifferentAddressr   r   s    r   test_differentNamesComparisonz2AddressTestCaseMixin.test_differentNamesComparison2   s    
 	**,0J0J0LLM3359J9J9LLM))+t/I/I/KKL2248I8I8KKLr   c                     | j                  |g      }| j                  |d   d   t               | j                  |d   d   |       | j                  t        |      d       y)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#   warningss       r   assertDeprecationsz'AddressTestCaseMixin.assertDeprecations=   s]    
 %%zl3!Z02DE!Y/9X*r   N)__name__
__module____qualname__r   r   r    r+    r   r   r   r      s    	E0	M+r   r   c                       e Zd ZdZy)IPv4AddressTestCaseMixin)type%s)host%rportz%dN)r,   r-   r.   addressArgSpecr/   r   r   r1   r1   H   s    ENr   r1   c                        e Zd ZdZdZd Zd Zy)HostnameAddressTestsz+
    Test case for L{HostnameAddress}.
    ))hostnamer4   r7   c                     t        dd      S )zw
        Create an arbitrary new L{HostnameAddress} instance.

        @return: A L{HostnameAddress} instance.
        s   example.comr   r   r   s    r   r   z!HostnameAddressTests.buildAddressS        ~q11r   c                     t        dd      S )zw
        Like L{buildAddress}, but with a different hostname.

        @return: A L{HostnameAddress} instance.
        s   example.netr   r>   r   s    r   r   z*HostnameAddressTests.buildDifferentAddress[   r?   r   N)r,   r-   r.   __doc__r9   r   r   r/   r   r   r;   r;   L   s     :N22r   r;   c                       e Zd Zd Zd Zy)IPv4AddressTCPTestsc                     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   s    r   r   z IPv4AddressTCPTests.buildAddresse        5+q11r   c                     t        ddd      S )K
        Like L{buildAddress}, but with a different fixed address.
        rE   	127.0.0.2r   rG   r   s    r   r   z)IPv4AddressTCPTests.buildDifferentAddressm        5+q11r   Nr,   r-   r.   r   r   r/   r   r   rC   rC   d       22r   rC   c                       e Zd Zd Zd Zy)IPv4AddressUDPTestsc                     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.
        UDPrF   r   rG   r   s    r   r   z IPv4AddressUDPTests.buildAddressu   rH   r   c                     t        ddd      S )rJ   rR   rK   r   rG   r   s    r   r   z)IPv4AddressUDPTests.buildDifferentAddress}   rL   r   NrM   r/   r   r   rP   rP   t   rN   r   rP   c                       e Zd ZdZd Zd Zy)IPv6AddressTestsr2   c                     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.
        rE   z::1r   r   r   s    r   r   zIPv6AddressTests.buildAddress   s     5%++r   c                     t        ddd      S )rJ   rE   z::2r   rW   r   s    r   r   z&IPv6AddressTests.buildDifferentAddress   s     5%++r   N)r,   r-   r.   r9   r   r   r/   r   r   rU   rU      s    EN,,r   rU   z&Platform doesn't support UNIX sockets.c                   d    e Zd ZdZd Zd Zd Zd Z ee	d      d        Z
 ee	d      d        Zy	)
UNIXAddressTests)namer6   c                 X    | j                         | _        | j                         | _        y N)mktemp_socketAddress_otherAddressr   s    r   setUpzUNIXAddressTests.setUp   s    "kkm![[]r   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   r`   r   s    r   r   zUNIXAddressTests.buildAddress   s    
 4..//r   c                 ,    t        | j                        S )rJ   )r   ra   r   s    r   r   z&UNIXAddressTests.buildDifferentAddress   s     4--..r   c                     | j                  t        | j                               dt        | j                        z         y)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   s    r   	test_reprzUNIXAddressTests.test_repr   s6    
 	""$%<0C0C#DE	
r   "Platform does not support symlinksc                    | j                         }t        | j                  d      5 | _        t	        j
                  t        j                  j                  | j                        |       | j                  t        | j                        t        |             | j                  t        |      t        | j                               ddd       y# 1 sw Y   yxY w)zU
        UNIXAddress objects compare as equal if they link to the same file.
        wN)
r_   openr`   fdossymlinkpathabspathr&   r   r   linkNames     r   test_comparisonOfLinkedFilesz-UNIXAddressTests.test_comparisonOfLinkedFiles   s    
 ;;=$%%s+ 	VtwJJrwwt':':;XF[)<)<={8?TU[2K@S@S4TU	V 	V 	V   BCCc           	      ~   | j                         }t        | j                  d      5 | _        t	        j
                  t        j                  j                  | j                        |       | j                  t        t        | j                              t        t        |                   ddd       y# 1 sw Y   yxY w)zU
        UNIXAddress Objects that compare as equal have the same hash value.
        rk   N)r_   rl   r`   rm   rn   ro   rp   rq   r&   hashr   rr   s     r   test_hashOfLinkedFilesz'UNIXAddressTests.test_hashOfLinkedFiles   s    
 ;;=$%%s+ 	twJJrwwt':':;XF[!4!456[=R8S	 	 	s   BB33B<N)r,   r-   r.   r9   rb   r   r   rh   r   symlinkSkiprt   rx   r/   r   r   rZ   rZ      sU    &N+0/
 K=>V ?V K=>	 ?	r   rZ   z&platform doesn't support UNIX sockets.c                   J    e Zd ZdZdZd Zd Zd Z ee	d      d        Z
d Zy	)
EmptyUNIXAddressTestszJ
    Tests for L{UNIXAddress} operations involving a L{None} address.
    r[   c                 .    | j                         | _        y r^   )r_   r`   r   s    r   rb   zEmptyUNIXAddressTests.setUp   s    "kkmr   c                     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   s    r   r   z"EmptyUNIXAddressTests.buildAddress   s     4  r   c                 ,    t        | j                        S )zN
        Like L{buildAddress}, but with a random temporary directory.
        rd   r   s    r   r   z+EmptyUNIXAddressTests.buildDifferentAddress   s     4..//r   ri   c                    | j                         }t        | j                  d      5 | _        t	        j
                  t        j                  j                  | j                        |       | j                  t        | j                        t        d             | j                  t        d      t        | j                               ddd       y# 1 sw Y   yxY w)z
        A UNIXAddress referring to a L{None} address does not
        compare equal to a UNIXAddress referring to a symlink.
        rk   N)
r_   rl   r`   rm   rn   ro   rp   rq   assertNotEqualr   rr   s     r   rt   z2EmptyUNIXAddressTests.test_comparisonOfLinkedFiles   s     ;;=$%%s+ 	UtwJJrwwt':':;XFD,?,? @+dBSTD 1;t?R?R3ST	U 	U 	Uru   c                 p    | j                         }|di}| j                  || j                                   y)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   s      r   test_emptyHashz$EmptyUNIXAddressTests.test_emptyHash   r   r   N)r,   r-   r.   rA   r9   rb   r   r   r   ry   rt   r   r/   r   r   r{   r{      s@     'N,!0 K=>	U ?	U0r   r{   )rn   socketunittestr   twisted.internet.addressr   r   r   r   twisted.python.compatr   twisted.python.runtimer	   twisted.trial.unittestr
   r   _supportsSymlinksry   AF_UNIXunixSkipAttributeErrorr   r1   r;   rC   rP   rU   rZ   r{   r/   r   r   <module>r      s  
 
    / + @,(,,..
NN H(+ (+VF3 F28%9 202-/G 2 2-/G 2 ,*,@ ,$ :;3* 3 <3l :;+0/1E +0 <+0o  Hs   C CC