
    Ϫf:                         d 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y)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.
    )BytesIO)minidom)FileWrapperc                   "    e Zd ZdZd Zd Zd Zy)IOPumpzUtility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    c                 <    || _         || _        || _        || _        y )N)clientserverclientIOserverIO)selfr	   r
   r   r   s        8/usr/lib/python3/dist-packages/twisted/test/testutils.py__init__zIOPump.__init__   s          c                 J    | j                         r	 | j                         ryy)z,Pump until there is no more input or output.N)pump)r   s    r   flushzIOPump.flush!   s    iik iikr   c                 >   | j                   j                  d       | j                  j                  d       | j                   j                         }| j                  j                         }| j                   j                  d       | j                  j                  d       | j                   j	                          | j                  j	                          |D ]  }| j
                  j                  |        |D ]  }| j                  j                  |        |s|ryy)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KK$$T*	+ 	+DKK$$T*	+Er   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r      s    
!
r   r   c                     t               }t               }|j                  t        |             | j                  t        |             t        || ||      }|j	                          |j	                          |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JJLJJLKr   c                       e Zd ZdZd Zy)XMLAssertionMixinz
    Test mixin defining a method for comparing serialized XML documents.

    Must be mixed in to a L{test case<unittest.TestCase>}.
    c                     | j                  t        j                  |      j                         t        j                  |      j                                y)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.assertXMLEqualR   s;     	OOE"((*COOF,C,I,I,K	
r   N)r   r   r   r    r0   r!   r   r   r(   r(   K   s    
r   r(   c                        e Zd ZdZdedefdZy)_EqualzN
    A class the instances of which are equal to anything and everything.
    otherreturnc                      y)NTr!   r   r3   s     r   __eq__z_Equal.__eq__f   s    r   Nr   r   r   r    objectboolr7   r!   r   r   r2   r2   a   s    F t r   r2   c                        e Zd ZdZdedefdZy)	_NotEqualz>
    A class the instances of which are equal to nothing.
    r3   r4   c                      y)NFr!   r6   s     r   r7   z_NotEqual.__eq__o   s    r   Nr8   r!   r   r   r<   r<   j   s    F t r   r<   c                       e Zd ZdZd Zy)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                    | j                  ||k(         | j                  ||k(         | j                  ||k(         | j                  ||k7         | j                  ||k7         | j                  ||k7         | j                  |t               k(         | j                  |t               k7         | j                  |t               k(         | j                  |t               k7         y)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8(23-78.891212&(23)+5645r   N)r   r   r   r    rF   r!   r   r   r?   r?   s   s     6r   r?   N)r    ior   xml.domr   r+   twisted.internet.protocolr   r   r&   r(   r2   r<   r?   r!   r   r   <module>rJ      sM   	  " 1% %P
 
,  .6 .6r   