
    YfJ                         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n# e$ r dZY nw xY w 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dS )    N)skipIf)HostnameAddressIPv4AddressIPv6AddressUNIXAddress)nativeString)platform)SynchronousTestCaseTestCaseFTc                   &    e Zd Zd Zd Zd Zd ZdS )AddressTestCaseMixinc                     |                      |                                 |                                 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selfs    T/var/www/html/env/lib/python3.11/site-packages/twisted/internet/test/test_address.pytest_addressComparisonz+AddressTestCaseMixin.test_addressComparison   sj     	))++t/@/@/B/BBCCC**,,0A0A0C0CCDDDDD    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ds      r   	test_hashzAddressTestCaseMixin.test_hash)   G    
   ""4L$++--./////r   c                    |                      |                                 |                                 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   s    r   test_differentNamesComparisonz2AddressTestCaseMixin.test_differentNamesComparison2   s    
 	**,,0J0J0L0LLMMM33559J9J9L9LLMMM))++t/I/I/K/KKLLL22448I8I8K8KKLLLLLr   c                 
   |                      |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#   warningss       r   assertDeprecationsz'AddressTestCaseMixin.assertDeprecations=   sz    
 %%zl33!Z02DEEE!Y/999X*****r   N)__name__
__module____qualname__r   r   r    r+    r   r   r   r      sV        	E 	E 	E0 0 0	M 	M 	M+ + + + +r   r   c                       e Zd ZdZdS )IPv4AddressTestCaseMixin)type%s)host%rportz%dN)r,   r-   r.   addressArgSpecr/   r   r   r1   r1   H   s        ENNNr   r1   c                   "    e Zd ZdZdZd Zd ZdS )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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   sC          :N2 2 22 2 2 2 2r   r;   c                       e Zd Zd Zd ZdS )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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11r   Nr,   r-   r.   r   r   r/   r   r   rC   rC   d   2        2 2 22 2 2 2 2r   rC   c                       e Zd Zd Zd ZdS )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dS )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      s7        EN, , ,, , , , ,r   rU   z&Platform doesn't support UNIX sockets.c                   ~    e Zd ZdZd Zd Zd Zd Z ee	d          d             Z
 ee	d          d             Zd	S )
UNIXAddressTests)namer6   c                 j    |                                  | _        |                                  | _        d S N)mktemp_socketAddress_otherAddressr   s    r   setUpzUNIXAddressTests.setUp   s(    "kkmm![[]]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                     |                      t          |                                           dt          | j                  z             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   s    r   	test_reprzUNIXAddressTests.test_repr   sP    
 	""$$%%<0C#D#DE	
 	
 	
 	
 	
r   "Platform does not support symlinksc                    |                                  }t          | j        d          5 | _        t	          j        t          j                            | j                  |           |                     t          | j                  t          |                     |                     t          |          t          | j                             ddd           dS # 1 swxY w Y   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   linkNames     r   test_comparisonOfLinkedFilesz-UNIXAddressTests.test_comparisonOfLinkedFiles   s   
 ;;==$%s++ 	VtwJrwt':;;XFFF[)<=={8?T?TUUU[22K@S4T4TUUU	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V   B'CC"%C"c           	         |                                  }t          | j        d          5 | _        t	          j        t          j                            | j                  |           |                     t          t          | j                            t          t          |                               ddd           dS # 1 swxY w Y   dS )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Jrwt':;;XFFF[!45566[=R=R8S8S  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BCC
CN)r,   r-   r.   r9   rb   r   r   rh   r   symlinkSkiprt   rx   r/   r   r   rZ   rZ      s        &N+ + +0 0 0/ / /
 
 
 VK=>>V V ?>V VK=>>	 	 ?>	 	 	r   rZ   z&platform doesn't support UNIX sockets.c                   X    e Zd ZdZdZd Zd Zd Z ee	d          d             Z
d Zd	S )
EmptyUNIXAddressTestszJ
    Tests for L{UNIXAddress} operations involving a L{None} address.
    r[   c                 8    |                                  | _        d S r^   )r_   r`   r   s    r   rb   zEmptyUNIXAddressTests.setUp   s    "kkmm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                    |                                  }t          | j        d          5 | _        t	          j        t          j                            | j                  |           |                     t          | j                  t          d                     |                     t          d          t          | j                             ddd           dS # 1 swxY w Y   dS )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Jrwt':;;XFFFD,? @ @+dBSBSTTTD 1 1;t?R3S3STTT	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	Uru   c                     |                                  }|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   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 0 0 VK=>>	U 	U ?>	U0 0 0 0 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 HH    HHH(+ (+ (+ (+ (+ (+ (+ (+VF F F F F3 F F F2 2 2 2 28%9 2 2 202 2 2 2 2-/G 2 2 2 2 2 2 2 2-/G 2 2 2 , , , , ,*,@ , , ,$ :;;3 3 3 3 3* 3 3 <;3l :;;+0 +0 +0 +0 +0/1E +0 +0 <;+0 +0 +0s    A
 
AA