
    h                         S r SSKrSSKJr  SSKJr  SSKJr   " S S5      r	S r
 " S	 S
5      r " S S5      r " S S5      r " S S5      rS r\" 5       rS rg)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                   *    \ rS rSrSrS rS rS rSrg)IOPump   zUtility to pump data between clients and servers for protocol testing.

Perhaps this is a utility worthy of being in protocol.py?
c                 4    Xl         X l        X0l        X@l        g )N)clientserverclientIOserverIO)selfr
   r   r   r   s        ]/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/testutils.py__init__IOPump.__init__   s          c                 `    U R                  5       (       a   U R                  5       (       a  M  gg)z,Pump until there is no more input or output.N)pump)r   s    r   flushIOPump.flush"   s    iikk iikkr   c                 Z   U R                   R                  S5        U R                  R                  S5        U R                   R                  5       nU R                  R                  5       nU R                   R                  S5        U R                  R                  S5        U R                   R	                  5         U R                  R	                  5         U H  nU R
                  R                  U5        M      U H  nU R                  R                  U5        M      U(       d  U(       a  gg)z?Move data back and forth.

Returns whether any data was moved.
r      )r   seekr   readtruncater   dataReceivedr
   )r   cDatasDatabytes       r   r   IOPump.pump'   s    
 	11""$""$11  DKK$$T* DKK$$T* Er   )r
   r   r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__ r   r   r   r      s    
!
r   r   c                     [        5       n[        5       nUR                  [        U5      5        U R                  [        U5      5        [        XX#5      nUR	                  5         UR	                  5         U$ )z-Take two Protocol instances and connect them.)r   makeConnectionr   r   r   )r   r
   ciosior   s        r   returnConnectedr,   >   sY    
)C
)C
+c*+
+c*+&#+DJJLJJLKr   c                       \ rS rSrSrS rSrg)XMLAssertionMixinL   z~
Test mixin defining a method for comparing serialized XML documents.

Must be mixed in to a L{test case<unittest.TestCase>}.
c                     U R                  [        R                  " U5      R                  5       [        R                  " U5      R                  5       5        g)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   assertXMLEqual XMLAssertionMixin.assertXMLEqualS   s;     	OOE"((*COOF,C,I,I,K	
r   r'   N)r!   r"   r#   r$   r%   r7   r&   r'   r   r   r.   r.   L   s    
r   r.   c                   *    \ rS rSrSrS\S\4S jrSrg)_Equalb   zF
A class the instances of which are equal to anything and everything.
otherreturnc                     g)NTr'   r   r<   s     r   __eq___Equal.__eq__g   s    r   r'   N	r!   r"   r#   r$   r%   objectboolr@   r&   r'   r   r   r:   r:   b   s    F t r   r:   c                   *    \ rS rSrSrS\S\4S jrSrg)	_NotEqualk   z6
A class the instances of which are equal to nothing.
r<   r=   c                     g)NFr'   r?   s     r   r@   _NotEqual.__eq__p   s    r   r'   NrB   r'   r   r   rF   rF   k   s    F t r   rF   c                       \ rS rSrSrS rSrg)ComparisonTestsMixint   a  
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                    U R                  X:H  5        U R                  X:H  5        U R                  X:H  5        U R                  X:g  5        U R                  X:g  5        U R                  X:g  5        U R                  U[        5       :H  5        U R                  U[        5       :g  5        U R                  U[        5       :H  5        U R                  U[        5       :g  5        g)a  
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assertFalser:   rF   )r   firstValueOnesecondValueOnevalueTwos       r   "assertNormalEqualityImplementation7ComparisonTestsMixin.assertNormalEqualityImplementation   s    . 	67782378891212&(23)+5645r   r'   N)r!   r"   r#   r$   r%   rS   r&   r'   r   r   rK   rK   t   s     6r   rK   c                      Sn Sn [         R                   " [         R                  5      n U R                  S5        SnU (       a  U R	                  5         U$ ! [         a     N%f = f)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_ipv6r]      s[    DH}}V__-		* 

O  s   7A 
A#"A#c                 *    [         (       d  SU l        U $ )Nz.Does not work on systems without IPv6 support.)HAS_IPV6skip)fs    r   skipWithoutIPv6rb      s    8AHr   )r%   rV   ior   xml.domr   r2   twisted.internet.protocolr   r   r,   r.   r:   rF   rK   r]   r_   rb   r'   r   r   <module>rf      sd   	   " 1% %P
 
,  .6 .6b" ;r   