
    hA                        S r SSKrSSKrSSKrSSKrSSKJr  SSKJrJ	r	J
r
JrJrJrJrJrJrJrJrJr  SSKJr  SSKJr  SSKJrJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r\ " S S5      5       r " S S\5      r  " S S\5      r! " S S\5      r" " S S\5      r# " S S\5      r$ " S S\5      r% " S S\5      r& " S  S!\5      r'g)"z%
Tests for L{twisted.python.compat}.
    N)skipIf)_PYPYbytesEnvironcmp
comparableexecfile
intToBytesioType	iterbyteslazyByteSlicenativeStringnetworkStringreraise)FilePath)platform)SynchronousTestCaseTestCasec                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)IOTypeTests#   z7
Test cases for determining a file-like object's type.
c                 h    U R                  [        [        R                  " 5       5      [        5        g)z-
An L{io.StringIO} accepts and returns text.
N)assertEqualr
   ioStringIOstrselfs    _/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_compat.pytest_3StringIOIOTypeTests.test_3StringIO(   s     	.4    c                 h    U R                  [        [        R                  " 5       5      [        5        g)z-
An L{io.BytesIO} accepts and returns bytes.
N)r   r
   r   BytesIObytesr   s    r   test_3BytesIOIOTypeTests.test_3BytesIO.   s     	

-u5r!   c                     [        U R                  5       S5       nU R                  [        U5      [        5        SSS5        g! , (       d  f       g= f)zD
A file opened via 'io.open' in text mode accepts and returns text.
wN)openmktempr   r
   r   r   fs     r   test_3openTextModeIOTypeTests.test_3openTextMode4   s6     $++-%VAY, &%%    A
Ac                     [        U R                  5       S5       nU R                  [        U5      [        5        SSS5        g! , (       d  f       g= f)zG
A file opened via 'io.open' in binary mode accepts and returns bytes.
wbN)r)   r*   r   r
   r$   r+   s     r   test_3openBinaryMode IOTypeTests.test_3openBinaryMode;   s6     $++-&!VAY. '&&r/   c                     [         R                  " U R                  5       S5       nU R                  [	        U5      [
        5        SSS5        g! , (       d  f       g= f)zu
The L{codecs} module, oddly, returns a file-like object which returns
bytes when not passed an 'encoding' argument.
r1   N)codecsr)   r*   r   r
   r$   r+   s     r   test_codecsOpenBytes IOTypeTests.test_codecsOpenBytesB   s:    
 [[-VAY. .--s    A
Ac                     [         R                  " U R                  5       SSS9 nU R                  [	        U5      [
        5        SSS5        g! , (       d  f       g= f)zI
When passed an encoding, however, the L{codecs} module returns unicode.
r1   utf-8)encodingN)r5   r)   r*   r   r
   r   r+   s     r   test_codecsOpenTextIOTypeTests.test_codecsOpenTextJ   s=     [[w?1VAY, @??s    A
Ac                 R    U R                  [        [        5       5      [        5        g)za
When passed an object about which no sensible decision can be made, err
on the side of unicode.
N)r   r
   objectr   r   s    r   test_defaultToTextIOTypeTests.test_defaultToTextQ   s    
 	)3/r!    N)__name__
__module____qualname____firstlineno____doc__r   r%   r-   r2   r6   r;   r?   __static_attributes__rA   r!   r   r   r   #   s*    56-//-0r!   r   c                   $    \ rS rSrSrS rS rSrg)CompatTestsY   zm
Various utility functions in C{twisted.python.compat} provide same
functionality as modern Python variants.
c                    [        5       nUR                  S5        UR                  S5        UR                  S5        [        U5      nUR                  5         U R	                  U/ SQ5        UR                  S5        [        U5      nUR                  5         U R	                  USS/5        UR                  S5        SS1nUR                  U5      n[        U5      nUR                  5         U R	                  U/ SQ5        g	)
z7
L{set} should behave like the expected set interface.
bca)rN   rL   rM   drs)rN   rM   rP   rQ   N)setaddlistsortr   removediscardunionr   rN   rL   rO   s       r   test_setCompatTests.test_set_   s     E	c
	c
	c
G	O,	G	S#J'			##JGGAJG	01r!   c                 *   [        SS/5      nU R                  [        [        US5        U R	                  [        U5      SS/5        [        SS/5      nUR                  U5      n[        U5      nUR                  5         U R	                  U/ SQ5        g)zC
L{frozenset} should behave like the expected frozenset interface.
rN   rL   rS   rP   rQ   )rN   rL   rP   rQ   N)		frozensetassertRaisesAttributeErrorgetattrr   sortedrX   rT   rU   rY   s       r   test_frozensetCompatTests.test_frozensetw   s|     sCj!.'1e<S#J/sCj!GGAJG	01r!   rA   N)rB   rC   rD   rE   rF   rZ   rb   rG   rA   r!   r   rI   rI   Y   s    
202r!   rI   c                   0    \ rS rSrSrS rS rS rS rSr	g)	ExecfileCompatTests   z=
Tests for the Python 3-friendly L{execfile} implementation.
c                     U R                  5       n[        US5       nUR                  UR                  S5      5        SSS5        [	        UR                  S5      5      $ ! , (       d  f       N(= f)zW
Write L{content} to a new temporary file, returning the L{FilePath}
for the new file.
r1   asciiNr9   )r*   r)   writeencoder   )r   contentpathr,   s       r   writeScriptExecfileCompatTests.writeScript   sR    
 {{}$GGGNN7+, G,-- s   !A  
A.c                     U R                  S5      nSS0n[        UR                  U5        U R                  SUS   5        g)zH
L{execfile} executes the specified file in the given global namespace.
	foo += 1
foo      Nrm   r   rl   r   )r   scriptglobalNamespaces      r   test_execfileGlobals(ExecfileCompatTests.test_execfileGlobals   s@     !!,/ !*o.OE23r!   c                     U R                  S5      nSS0nSS0n[        UR                  X#5        U R                  SUS   5        U R                  SUS   5        g)zS
L{execfile} executes the specified file in the given global and local
namespaces.
rp   rq   
         Nrt   )r   ru   rv   localNamespaces       r   test_execfileGlobalsAndLocals1ExecfileCompatTests.test_execfileGlobalsAndLocals   s^    
 !!,/ "+o>_U34^E23r!   c                     S HF  nU R                  SU-   5      nSS0n[        UR                  U5        U R                  SUS   5        MH     g)z
L{execfile} reads in the specified file using universal newlines so
that scripts written on one platform will work on another.
)
z
zfoo = 'okay'rq   Nokayrt   )r   
lineEndingru   rv   s       r   test_execfileUniversalNewlines2ExecfileCompatTests.test_execfileUniversalNewlines   sO    
 -J%%nz&ABF$dmOV[[/2V_U%;<	 -r!   rA   N)
rB   rC   rD   rE   rF   rm   rw   r~   r   rG   rA   r!   r   re   re      s    .4
4	=r!   re   c                       \ rS rSrSrS rSrg)PYPYTest   z
Identification of PyPy.
c                     S[         R                  ;   a  U R                  [        5        gU R	                  [        5        g)z
On PyPy, L{_PYPY} is True.
PyPyN)sysversion
assertTruer   assertFalser   s    r   	test_PYPYPYPYTest.test_PYPY   s*     S[[ OOE"U#r!   rA   N)rB   rC   rD   rE   rF   r   rG   rA   r!   r   r   r      s    $r!   r   c                   $    \ rS rSrSrS rS rSrg)
Comparable   z=
Objects that can be compared to each other, but not others.
c                     Xl         g Nvalue)r   r   s     r   __init__Comparable.__init__   s    
r!   c                 x    [        U[        5      (       d  [        $ [        U R                  UR                  5      $ r   )
isinstancer   NotImplementedr   r   )r   others     r   __cmp__Comparable.__cmp__   s*    %,,!!4::u{{++r!   r   N)rB   rC   rD   rE   rF   r   r   rG   rA   r!   r   r   r      s    ,r!   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ComparableTests   zJ
L{comparable} decorated classes emulate Python 2's C{__cmp__} semantics.
c                     U R                  [        S5      [        S5      :H  5        U R                  [        S5      [        S5      :H  5        g)zW
Instances of a class that is decorated by C{comparable} support
equality comparisons.
rr   rs   Nr   r   r   r   s    r   test_equalityComparableTests.test_equality   s8     	
1A67A*Q-78r!   c                     U R                  [        S5      [        S5      :g  5        U R                  [        S5      [        S5      :g  5        g)zY
Instances of a class that is decorated by C{comparable} support
inequality comparisons.
rr   rs   N)r   r   r   r   s    r   test_nonEquality ComparableTests.test_nonEquality   s8     	A*Q-78
1A67r!   c                     U R                  [        S5      [        S5      :  5        U R                  [        S5      [        S5      :  5        g)z[
Instances of a class that is decorated by C{comparable} support
greater-than comparisons.
rs   rr   r      Nr   r   s    r   test_greaterThan ComparableTests.test_greaterThan   8    
 	
1
156AA67r!   c                     U R                  [        S5      [        S5      :  5        U R                  [        S5      [        S5      :  5        U R                  [        S5      [        S5      :  5        g)zd
Instances of a class that is decorated by C{comparable} support
greater-than-or-equal comparisons.
rr   rs   r   r   Nr   r   s    r   test_greaterThanOrEqual'ComparableTests.test_greaterThanOrEqual   Q    
 	
1A67
1A67A*Q-78r!   c                     U R                  [        S5      [        S5      :  5        U R                  [        S5      [        S5      :  5        g)zX
Instances of a class that is decorated by C{comparable} support
less-than comparisons.
r   r   rs   Nr   r   s    r   test_lessThanComparableTests.test_lessThan   r   r!   c                     U R                  [        S5      [        S5      :*  5        U R                  [        S5      [        S5      :*  5        U R                  [        S5      [        S5      :*  5        g)za
Instances of a class that is decorated by C{comparable} support
less-than-or-equal comparisons.
r   r   rs   Nr   r   s    r   test_lessThanOrEqual$ComparableTests.test_lessThanOrEqual  r   r!   rA   N)rB   rC   rD   rE   rF   r   r   r   r   r   r   rG   rA   r!   r   r   r      s%    988989r!   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)Python3ComparableTestsi  z3
Python 3-specific functionality of C{comparable}.
c                 p    U R                  [        S5      R                  [        5       5      [        5        g)z
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__eq__} if it is returned by the
underlying C{__cmp__} call.
rr   N)r   r   __eq__r>   r   r   s    r   test_notImplementedEquals0Python3ComparableTests.test_notImplementedEquals  %     	A--fh7Hr!   c                 p    U R                  [        S5      R                  [        5       5      [        5        g)z
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__ne__} if it is returned by the
underlying C{__cmp__} call.
rr   N)r   r   __ne__r>   r   r   s    r   test_notImplementedNotEquals3Python3ComparableTests.test_notImplementedNotEquals  r   r!   c                 p    U R                  [        S5      R                  [        5       5      [        5        g)z
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__gt__} if it is returned by the
underlying C{__cmp__} call.
rr   N)r   r   __gt__r>   r   r   s    r   test_notImplementedGreaterThan5Python3ComparableTests.test_notImplementedGreaterThan#  r   r!   c                 p    U R                  [        S5      R                  [        5       5      [        5        g)z
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__lt__} if it is returned by the
underlying C{__cmp__} call.
rr   N)r   r   __lt__r>   r   r   s    r   test_notImplementedLessThan2Python3ComparableTests.test_notImplementedLessThan+  r   r!   c                 p    U R                  [        S5      R                  [        5       5      [        5        g)z
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__ge__} if it is returned by the
underlying C{__cmp__} call.
rr   N)r   r   __ge__r>   r   r   s    r   $test_notImplementedGreaterThanEquals;Python3ComparableTests.test_notImplementedGreaterThanEquals3  r   r!   c                 p    U R                  [        S5      R                  [        5       5      [        5        g)z
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__le__} if it is returned by the
underlying C{__cmp__} call.
rr   N)r   r   __le__r>   r   r   s    r   !test_notImplementedLessThanEquals8Python3ComparableTests.test_notImplementedLessThanEquals;  r   r!   rA   N)rB   rC   rD   rE   rF   r   r   r   r   r   r   rG   rA   r!   r   r   r     s+    IIIIIIr!   r   c                   *    \ rS rSrSrS rS rS rSrg)CmpTestsiD  z9
L{cmp} should behave like the built-in Python 2 C{cmp}.
c                     U R                  [        SS5      S5        U R                  [        SS5      S5        U R                  [        S/S/5      S5        g)z%
L{cmp} returns 0 for equal objects.
rN   r   rr   Nr   r   r   s    r   test_equalsCmpTests.test_equalsI  sJ     	S#*QA&aS1#*r!   c                 t    U R                  [        SS5      S5        U R                  [        SS5      S5        g)zC
L{cmp} returns 1 if its first argument is bigger than its second.
   r   rr      z   aNr   r   s    r   r   CmpTests.test_greaterThanQ  s0     	QA&T4!,r!   c                 t    U R                  [        SS5      S5        U R                  [        SS5      S5        g)zE
L{cmp} returns -1 if its first argument is smaller than its second.
g?gffffff@r      dNr   r   s    r   r   CmpTests.test_lessThanX  s0     	S#+T4"-r!   rA   N)	rB   rC   rD   rE   rF   r   r   r   rG   rA   r!   r   r   r   D  s    +-.r!   r   c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)StringTestsi`  z0
Compatibility functions and types for strings.
c                 x    U R                  [        U5      U5        U R                  [        U5      [        5        g)z
Raise an exception indicating a failed test if the output of
C{nativeString(original)} is unequal to the expected string, or is not
a native string.
N)r   r   assertIsInstancer   )r   originalexpecteds      r   assertNativeStringStringTests.assertNativeStringe  s.     	h/:l84c:r!   c                 :    U R                  [        [        S5        g)zR
C{nativeString} raises a C{UnicodeError} if input bytes are not ASCII
decodable.
   Nr^   UnicodeErrorr   r   s    r   test_nonASCIIBytesToString&StringTests.test_nonASCIIBytesToStringn  s    
 	,g>r!   c                 :    U R                  [        [        S5        g)zS
C{nativeString} raises a C{UnicodeError} if input Unicode is not ASCII
encodable.
u   ሴNr   r   s    r   test_nonASCIIUnicodeToString(StringTests.test_nonASCIIUnicodeToStringu  s    
 	,h?r!   c                 (    U R                  SS5        g)zg
C{nativeString} converts bytes to the native string format, assuming
an ASCII encoding if applicable.
s   hellohelloNr   r   s    r   test_bytesToStringStringTests.test_bytesToString|  s    
 	'2r!   c                 (    U R                  SS5        g)zi
C{nativeString} converts unicode to the native string format, assuming
an ASCII encoding if applicable.
zGood dayNr   r   s    r   test_unicodeToString StringTests.test_unicodeToString  s    
 	
J7r!   c                 (    U R                  SS5        g)z:
C{nativeString} leaves native strings as native strings.
zHello!Nr   r   s    r   test_stringToStringStringTests.test_stringToString  s     	(3r!   c                 :    U R                  [        [        S5        g)z]
C{nativeString} raises a C{TypeError} if given an object that is not a
string of some sort.
rr   N)r^   	TypeErrorr   r   s    r   test_unexpectedTypeStringTests.test_unexpectedType  s    
 	)\15r!   rA   N)rB   rC   rD   rE   rF   r   r   r   r   r   r   r  rG   rA   r!   r   r   r   `  s+    ;?@3846r!   r   c                   *    \ rS rSrSrS rS rS rSrg)NetworkStringTestsi  z
Tests for L{networkString}.
c                 :    U R                  S[        S5      5        g)z]
L{networkString} returns a C{unicode} object passed to it encoded into
a C{bytes} instance.
s   foorq   N)r   r   r   s    r   test_strNetworkStringTests.test_str  s    
 	u!56r!   c                 :    U R                  [        [        S5        g)zw
L{networkString} raises L{UnicodeError} if passed a C{unicode} instance
containing characters not encodable in ASCII.
u   ☃N)r^   r   r   r   s    r   test_unicodeOutOfRange)NetworkStringTests.test_unicodeOutOfRange  s    
 	,}Er!   c                     U R                  [        [        [        5       5        U R                  [        [        S5        g)zh
L{networkString} raises L{TypeError} if passed a non-string object or
the wrong type of string object.
s   bytesN)r^   r  r   r>   r   s    r   test_nonString!NetworkStringTests.test_nonString  s*    
 	)]FH=)]H=r!   rA   N)	rB   rC   rD   rE   rF   r  r
  r  rG   rA   r!   r   r  r    s    7F>r!   r  c                   $    \ rS rSrSrS rS rSrg)ReraiseTestsi  z@
L{reraise} re-raises exceptions on both Python 2 and Python 3.
c                     SS-     [        WS5        U R	                  S5        g! [          a    [        R                  " 5       u  pn NCf = f! [          a    [        R                  " 5       u  pEnU R                  U[        5        U R                  WU5        U R                  [        R                  " W5      S   [        R                  " U5      S   5         gf = f)zm
Calling L{reraise} with an exception instance and a traceback of
L{None} re-raises it with a new traceback.
rr   r   NThe exception was not raised.r   )BaseExceptionr   exc_infor   failr   ZeroDivisionErrorassertIsassertNotEqual	traceback	format_tbr   typr   tbtyp2value2tb2s          r   test_reraiseWithNone!ReraiseTests.test_reraiseWithNone  s    
	,E
	7E4  II56  	, \\^NC	,  	 #D#T#45MM%(##B'+Y-@-@-Eb-I		!   & A "A
AB
CCc                     SS-     [        WW5        U R	                  S5        g! [          a    [        R                  " 5       u  pn NCf = f! [          a    [        R                  " 5       u  pEnU R                  U[        5        U R                  WU5        U R                  [        R                  " W5      S   [        R                  " U5      S   5         gf = f)zq
Calling L{reraise} with an exception instance and a traceback
re-raises the exception with the given traceback.
rr   r   r  r   N)
r  r   r  r   r  r   r  r  r  r  r  s          r   test_reraiseWithTraceback&ReraiseTests.test_reraiseWithTraceback  s    
	,E	7E2 II56  	, \\^NC	,  	X #D#T#45MM%(Y004R8):M:Mc:RSU:VW		Xr#  rA   N)rB   rC   rD   rE   rF   r!  r%  rG   rA   r!   r   r  r    s    7*7r!   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
Python3BytesTestsi  z:
Tests for L{iterbytes}, L{intToBytes}, L{lazyByteSlice}.
c                 X    Sn[        [        U5      5      nU R                  U/ SQ5        g)z
When L{iterbytes} is called with a bytestring, the returned object
can be iterated over, resulting in the individual bytes of the
bytestring.
s   abcd)r      b   cr   N)rT   r   r   )r   inputresults      r   test_iteration Python3BytesTests.test_iteration  s)     i&'!9:r!   c                 :    U R                  [        S5      S5        g)zs
When L{intToBytes} is called with an integer, the result is an
ASCII-encoded string representation of the number.
   s   213N)r   r	   r   s    r   test_intToBytes!Python3BytesTests.test_intToBytes  s    
 	C&1r!   c                 P    SnU R                  [        [        U5      5      U5        g)z^
L{lazyByteSlice} called with some bytes returns a semantically equal
version of these bytes.
   123XYZNr   r$   r   r   datas     r   test_lazyByteSliceNoOffset,Python3BytesTests.test_lazyByteSliceNoOffset  s#    
 }T23T:r!   c                 X    SnU R                  [        [        US5      5      USS 5        g)z
L{lazyByteSlice} called with some bytes and an offset returns a
semantically equal version of these bytes starting at the given offset.
r5  rs   Nr6  r7  s     r   test_lazyByteSliceOffset*Python3BytesTests.test_lazyByteSliceOffset   s+    
 }T156QRAr!   c           	      Z    SnU R                  [        [        USS5      5      USS 5        g)z
L{lazyByteSlice} called with some bytes, an offset and a length returns
a semantically equal version of these bytes starting at the given
offset, up to the given length.
r5  rs   r      Nr6  r7  s     r   !test_lazyByteSliceOffsetAndLength3Python3BytesTests.test_lazyByteSliceOffsetAndLength  s-     }T1a894!9Er!   rA   N)rB   rC   rD   rE   rF   r.  r2  r9  r<  r@  rG   rA   r!   r   r(  r(    s"    ;2;BFr!   r(  c                   T    \ rS rSrSr\" \R                  " 5       S5      S 5       rSr	g)BytesEnvironTestsi  z
Tests for L{BytesEnviron}.
z+Environment vars are always str on Windows.c                    [        5       n[        5       nUR                  5        H9  u  p4UR                  [	        U5      5        UR                  [	        U5      5        M;     U R                  [        U5      [        /5        g)zb
The output of L{BytesEnviron} should always be a L{dict} with L{bytes}
values and L{bytes} keys.
N)r   rR   itemsrS   typer   rT   r$   )r   r-  typeskeyvals        r   test_alwaysBytes"BytesEnvironTests.test_alwaysBytes  s\     HCIId3i IId3i  ' 	eug.r!   rA   N)
rB   rC   rD   rE   rF   r   r   	isWindowsrJ  rG   rA   r!   r   rC  rC    s-     H "OP/ Q/r!   rC  )(rF   r5   r   r   r  unittestr   twisted.python.compatr   r   r   r   r   r	   r
   r   r   r   r   r   twisted.python.filepathr   twisted.python.runtimer   twisted.trial.unittestr   r   r   rI   re   r   r   r   r   r   r   r  r  r(  rC  rA   r!   r   <module>rR     s   

  	 
      - + @30% 30l*2% *2Z-=- -=`$" $ , , ,79) 79t3I0 3Il." .856% 56p>, >8+7& +7\-F+ -F`/ /r!   