
    Yf                         d Z ddlZddlmZ ddlmZ ddlmZ  G d d          Z	d Z
 G d	 d
          Z G d d          Z G d d          Z G d d          Zd Z e            Zd ZdS )a  
I{Private} test utilities for use throughout Twisted's test suite.  Unlike
C{proto_helpers}, this is no exception to the
don't-use-it-outside-Twisted-we-won't-maintain-compatibility rule!

@note: Maintainers be aware: things in this module should be gradually promoted
    to more full-featured test helpers and exposed as public API as your
    maintenance time permits.  In order to be public API though, they need
    their own test cases.
    N)BytesIO)minidom)FileWrapperc                   $    e Zd ZdZd Zd Zd ZdS )IOPumpzUtility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    c                 >    || _         || _        || _        || _        d S )N)clientserverclientIOserverIO)selfr	   r
   r   r   s        H/var/www/html/env/lib/python3.11/site-packages/twisted/test/testutils.py__init__zIOPump.__init__   s"          c                 \    |                                  r	 |                                  dS dS )z,Pump until there is no more input or output.N)pump)r   s    r   flushzIOPump.flush"   s;    iikk 	 iikk 	 	 	 	 	r   c                 &   | j                             d           | j                            d           | j                                         }| j                                        }| j                             d           | j                            d           | j                                          | j                                         |D ]}| j                            |           |D ]}| j                            |           |s|rdS dS )zOMove data back and forth.

        Returns whether any data was moved.
        r      )r   seekr   readtruncater
   dataReceivedr	   )r   cDatasDatabytes       r   r   zIOPump.pump'   s   
 	11""$$""$$11       	+ 	+DK$$T**** 	+ 	+DK$$T**** 	E 	11r   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r      sK         
! ! !  
    r   r   c                 :   t                      }t                      }|                    t          |                     |                     t          |                     t          || ||          }|                                 |                                 |S )z-Take two Protocol instances and connect them.)r   makeConnectionr   r   r   )r
   r	   ciosior   s        r   returnConnectedr&   >   s~    
))C
))C
+c**+++
+c**+++&&#s++DJJLLLJJLLLKr   c                       e Zd ZdZd ZdS )XMLAssertionMixinz
    Test mixin defining a method for comparing serialized XML documents.

    Must be mixed in to a L{test case<unittest.TestCase>}.
    c                     |                      t          j        |                                          t          j        |                                                     dS )z
        Verify that two strings represent the same XML document.

        @param first: An XML string.
        @type first: L{bytes}

        @param second: An XML string that should match C{first}.
        @type second: L{bytes}
        N)assertEqualdomparseStringtoxml)r   firstseconds      r   assertXMLEqualz XMLAssertionMixin.assertXMLEqualS   sW     	OE""((**COF,C,C,I,I,K,K	
 	
 	
 	
 	
r   N)r   r   r   r    r0   r!   r   r   r(   r(   L   s-         
 
 
 
 
r   r(   c                   "    e Zd ZdZdedefdZdS )_EqualzN
    A class the instances of which are equal to anything and everything.
    otherreturnc                     dS )NTr!   r   r3   s     r   __eq__z_Equal.__eq__g   s    tr   Nr   r   r   r    objectboolr7   r!   r   r   r2   r2   b   s@         F t      r   r2   c                   "    e Zd ZdZdedefdZdS )	_NotEqualz>
    A class the instances of which are equal to nothing.
    r3   r4   c                     dS )NFr!   r6   s     r   r7   z_NotEqual.__eq__p   s    ur   Nr8   r!   r   r   r<   r<   k   s@         F t      r   r<   c                       e Zd ZdZd ZdS )ComparisonTestsMixina  
    A mixin which defines a method for making assertions about the correctness
    of an implementation of C{==} and C{!=}.

    Use this to unit test objects which follow the common convention for C{==}
    and C{!=}:

        - The object compares equal to itself
        - The object cooperates with unrecognized types to allow them to
          implement the comparison
        - The object implements not-equal as the opposite of equal
    c                 Z   |                      ||k               |                      ||k               |                     ||k               |                     ||k               |                     ||k               |                      ||k               |                      |t                      k               |                     |t                      k               |                     |t                      k               |                      |t                      k               dS )aU  
        Assert that C{firstValueOne} is equal to C{secondValueOne} but not
        equal to C{valueOne} and that it defines equality cooperatively with
        other types it doesn't know about.

        @param firstValueOne: An object which is expected to compare as equal
            to C{secondValueOne} and not equal to C{valueTwo}.

        @param secondValueOne: A different object than C{firstValueOne} but
            which is expected to compare equal to that object.

        @param valueTwo: An object which is expected to compare as not equal to
            C{firstValueOne}.
        N)
assertTrueassertFalser2   r<   )r   firstValueOnesecondValueOnevalueTwos       r   "assertNormalEqualityImplementationz7ComparisonTestsMixin.assertNormalEqualityImplementation   s
   . 	67777888(2333-7888.899912221222&((2333)++5666455555r   N)r   r   r   r    rF   r!   r   r   r?   r?   t   s-          6  6  6  6  6r   r?   c                      d} d}	 t          j         t           j                  } |                     d           d}n# t          $ r Y nw xY w| r|                                  |S )z4Returns True if the system can bind an IPv6 address.NF)z::1r   T)socketAF_INET6bindOSErrorclose)sockhas_ipv6s     r   	_has_ipv6rO      sw    DH}V_--		*     

Os   5< 
A	A	c                 "    t           sd| _        | S )Nz.Does not work on systems without IPv6 support.)HAS_IPV6skip)fs    r   skipWithoutIPv6rT      s     BAHr   )r    rH   ior   xml.domr   r+   twisted.internet.protocolr   r   r&   r(   r2   r<   r?   rO   rQ   rT   r!   r   r   <module>rX      s^  	 	        " " " " " " 1 1 1 1 1 1% % % % % % % %P  
 
 
 
 
 
 
 
,              .6 .6 .6 .6 .6 .6 .6 .6b  " 9;;    r   