o
    Óó·i  ã                   @   s˜   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ dƒZ	dd	„ Z
G d
d„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZdd„ Zeƒ Zd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                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚIOPumpzŠUtility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    c                 C   s   || _ || _|| _|| _d S )N)ÚclientÚserverÚclientIOÚserverIO)Úselfr   r   r   r	   © r   ú\C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/test/testutils.pyÚ__init__   s   
zIOPump.__init__c                 C   s   |   ¡ r	 |   ¡ sdS dS )z,Pump until there is no more input or output.N)Úpump)r
   r   r   r   Úflush"   s   ÿzIOPump.flushc                 C   s”   | j  d¡ | j d¡ | j  ¡ }| j ¡ }| j  d¡ | j d¡ | j  ¡  | j ¡  |D ]}| j |¡ q.|D ]}| j |¡ q9|sF|rHdS dS )zOMove data back and forth.

        Returns whether any data was moved.
        r   é   N)r   Úseekr	   ÚreadÚtruncater   ZdataReceivedr   )r
   ZcDataZsDataÚbyter   r   r   r   '   s   



zIOPump.pumpN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s
    r   c                 C   sJ   t ƒ }t ƒ }| t|ƒ¡ |  t|ƒ¡ t|| ||ƒ}| ¡  | ¡  |S )z-Take two Protocol instances and connect them.N)r   ZmakeConnectionr   r   r   )r   r   ZcioÚsior   r   r   r   ÚreturnConnected>   s   r   c                   @   ó   e Zd ZdZd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                 C   s$   |   t |¡ ¡ t |¡ ¡ ¡ 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ÚparseStringZtoxml)r
   ÚfirstÚsecondr   r   r   ÚassertXMLEqualS   s   
ÿz XMLAssertionMixin.assertXMLEqualN)r   r   r   r   r"   r   r   r   r   r   L   s    r   c                   @   ó"   e Zd ZdZdedefdd„ZdS )Ú_EqualzN
    A class the instances of which are equal to anything and everything.
    ÚotherÚreturnc                 C   ó   dS )NTr   ©r
   r%   r   r   r   Ú__eq__g   ó   z_Equal.__eq__N©r   r   r   r   ÚobjectÚboolr)   r   r   r   r   r$   b   ó    r$   c                   @   r#   )Ú	_NotEqualz>
    A class the instances of which are equal to nothing.
    r%   r&   c                 C   r'   )NFr   r(   r   r   r   r)   p   r*   z_NotEqual.__eq__Nr+   r   r   r   r   r/   k   r.   r/   c                   @   r   )Ú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                 C   s˜   |   ||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)Ú
assertTrueZassertFalser$   r/   )r
   ZfirstValueOneZsecondValueOneZvalueTwor   r   r   Ú"assertNormalEqualityImplementation‚   s   z7ComparisonTestsMixin.assertNormalEqualityImplementationN)r   r   r   r   r2   r   r   r   r   r0   t   s    r0   c                  C   sJ   d} d}zt   t j¡} |  d¡ d}W n	 ty   Y n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_ipv6r   r   r   Ú	_has_ipv6¥   s   
ÿr:   c                 C   s   t sd| _| S )Nz.Does not work on systems without IPv6 support.)ÚHAS_IPV6Úskip)Úfr   r   r   ÚskipWithoutIPv6¹   s   r>   )r   r3   Úior   Úxml.domr   r   Ztwisted.internet.protocolr   r   r   r   r$   r/   r0   r:   r;   r>   r   r   r   r   Ú<module>   s   (		1