+
    Dfj7                         ^ RI t ^ RIHt ^ RIHt ^ RIHtHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ R	IHt R
t ! R R]4      tR tR t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      tR# )    N)partial)BytesIO)mainprotocol)StringTransport)failure)	iterbytes)banana)TestCasel    c                   &   a  ] tR t^t o R tRtV tR# )	MathTestsc                |   \        \        ^ ^d4      4      \        \        RR4      4      ,           \        \        RR4      4      ,           R.,           pV Fd  p\        4       p\        P                  ! W#P
                  4       VP                  4       p\        P                  ! V4      pV P                  WR4       Kf  	  R# )r   i  iL  i@B iB Nl                )	listranger   r
   int2b128writegetvalueb1282intassertEqual)self	funkylistixvys   &     A/usr/lib/python3/dist-packages/twisted/spread/test/test_banana.pytest_int2b128MathTests.test_int2b128   s    q#5t$%&5'*+, j 	 A	AOOAww'

A"AQ"      N)__name__
__module____qualname____firstlineno__r   __static_attributes____classdictcell____classdict__s   @r   r   r      s     # #r   r   c                *    V P                   ! V4       R# )z
Dictate a Banana dialect to use.

@param protocol: A L{banana.Banana} instance which has not yet had a
    dialect negotiated.

@param dialect: A L{bytes} instance naming a Banana dialect to select.
N)_selectDialect)r   dialects   &&r   selectDialectr,   #   s     G$r   c                    \        4       pV ! 4       pVP                  ! V4       VP                  4        VP                  ! V4       VP	                  4       # )a  
Banana encode an object using L{banana.Banana.sendEncoded}.

@param bananaFactory: A no-argument callable which will return a new,
    unconnected protocol instance to use to do the encoding (this should
    most likely be a L{banana.Banana} instance).

@param obj: The object to encode.
@type obj: Any type supported by Banana.

@return: A L{bytes} instance giving the encoded form of C{obj}.
)r   makeConnectionclearsendEncodedvalue)bananaFactoryobj	transportr
   s   &&  r   encoder5   2   sF      !I_F
)$OO
s??r   c                   N   a  ] tR t^Ht o Rt]P                  tR tR t	R t
RtV tR# )BananaTestBasezb
The base for test classes. It defines commonly used things and sets up a
connection for testing.
c                `   \        4       V n        V P                  4       V n        V P                  P	                  \
        P                  ! V P                  4      4       \        V P                  R 4       V P                  V P                  n	        \        \        V P                  4      V n        R# )s   noneN)r   ioencClassencr.   r   FileWrapperr,   	putResultexpressionReceivedr   r5   r   s   &r   setUpBananaTestBase.setUpP   si    )==? 4 4TWW =>dhh(&*nn#fdmm4r   c                    Wn         R# )z
Store an expression received by C{self.enc}.

@param result: The object that was received.
@type result: Any type supported by Banana.
N)result)r   rC   s   &&r   r=   BananaTestBase.putResultX   s	     r   c                    V P                   P                  \        P                  ! \        P
                  4      4       V = R # N)r;   connectionLostr   Failurer   CONNECTION_DONEr?   s   &r   tearDownBananaTestBase.tearDowna   s(    0D0D EFHr   )r;   r5   r9   rC   N)r!   r"   r#   r$   __doc__r
   Bananar:   r@   r=   rJ   r%   r&   r'   s   @r   r7   r7   H   s)     
 }}H5 r   r7   c                      a  ] tR t^ft o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )BananaTestsz
General banana tests.
c                    V P                   P                  R 4       V P                   P                  V P                  P	                  4       4       V P
                  R 8X  g   Q hR# )s   helloN)r;   r0   dataReceivedr9   r   rC   r?   s   &r   test_stringBananaTests.test_stringk   sE    X&dgg..01{{h&&&r   c                *    V P                  RR4       R# )z|
Banana does not support unicode.  ``Banana.sendEncoded`` raises
``BananaError`` if called with an instance of ``unicode``.
hellozbuiltins.strN)_unsupportedTypeTestr?   s   &r   test_unsupportedUnicode#BananaTests.test_unsupportedUnicodep   s    
 	!!'>:r   c                2    V P                  \        R4       R# )z
Banana does not support arbitrary builtin types like L{type}.
L{banana.Banana.sendEncoded} raises L{banana.BananaError} if called
with an instance of L{type}.
zbuiltins.typeN)rV   typer?   s   &r   test_unsupportedBuiltinType'BananaTests.test_unsupportedBuiltinTypew   s     	!!$8r   c                P    V P                  \        4       \        R,           4       R# )z
Banana does not support arbitrary user-defined types (such as those
defined with the ``class`` statement).  ``Banana.sendEncoded`` raises
``BananaError`` if called with an instance of such a type.
z
.MathTestsN)rV   r   r!   r?   s   &r   test_unsupportedUserType$BananaTests.test_unsupportedUserType   s     	!!)+x,/FGr   c                    V P                  \        P                  V P                  P                  V4      pV P                  RV R2\        V4      4       R# )a  
Assert that L{banana.Banana.sendEncoded} raises L{banana.BananaError}
if called with the given object.

@param obj: Some object that Banana does not support.
@param name: The name of the type of the object.

@raise: The failure exception is raised if L{Banana.sendEncoded} does
    not raise L{banana.BananaError} or if the message associated with the
    exception is not formatted to include the type of the unsupported
    object.
zBanana cannot send z objectsN)assertRaisesr
   BananaErrorr;   r0   assertInstr)r   r3   nameexcs   &&& r   rV    BananaTests._unsupportedTypeTest   sD      2 2DHH4H4H#N+D6:CHEr   c                   V P                   P                  R4       V P                   P                  V P                  P	                  4       4       V P                  V P                  R4       V P                  V P                  \        4       R# )z
A positive integer less than 2 ** 32 should round-trip through
banana without changing value and should come out represented
as an C{int} (regardless of the type which was encoded).
i'  N)	r;   r0   rQ   r9   r   r   rC   assertIsInstanceintr?   s   &r   test_intBananaTests.test_int   s]     	U#dgg..01e,dkk3/r   c                v    V P                   P                  pV^,          p^V,          ^,
          pV^,           pV# )   )r;   prefixLimit)r   bytesbitslargestsmallests   &    r   _getSmallestBananaTests._getSmallest   s7    $$ qyT'A+Q;r   c                    V P                  4       pV P                  \        P                  V P                  P
                  V4       R# )zb
Test that a long above the implementation-specific limit is rejected
as too large to be encoded.
N)rt   ra   r
   rb   r;   r0   )r   rs   s   & r   test_encodeTooLargeLong#BananaTests.test_encodeTooLargeLong   s4    
 $$&&,,dhh.B.BHMr   c                   V P                  4       pV P                  P                  V P                  P                  ^,          4       V P                  P	                  V4       V P
                  P                  4       pV P
                  P                  ^ 4       V P                  P                  V P                  P                  ^,          4       V P                  \        P                  V P                  P                  V4       R# )zb
Test that a long above the implementation specific limit is rejected
as too large to be decoded.
N)rt   r;   setPrefixLimitro   r0   r9   r   truncatera   r
   rb   rQ   )r   rs   encodeds   &  r   test_decodeTooLargeLong#BananaTests.test_decodeTooLargeLong   s    
 $$& 4 4q 89X&''""$ 4 4 9:&,,dhh.C.CWMr   c                $    V P                  4       ) # rF   )rt   r?   s   &r   _getLargestBananaTests._getLargest   s    !!###r   c                    V P                  4       pV P                  \        P                  V P                  P
                  V4       R# )zk
Test that a negative long below the implementation-specific limit is
rejected as too small to be encoded.
N)r   ra   r
   rb   r;   r0   )r   rr   s   & r   test_encodeTooSmallLong#BananaTests.test_encodeTooSmallLong   s4    
 ""$&,,dhh.B.BGLr   c                   V P                  4       pV P                  P                  V P                  P                  ^,          4       V P                  P	                  V4       V P
                  P                  4       pV P
                  P                  ^ 4       V P                  P                  V P                  P                  ^,          4       V P                  \        P                  V P                  P                  V4       R# )zk
Test that a negative long below the implementation specific limit is
rejected as too small to be decoded.
N)r   r;   rz   ro   r0   r9   r   r{   ra   r
   rb   rQ   )r   rr   r|   s   &  r   test_decodeTooSmallLong#BananaTests.test_decodeTooSmallLong   s    
 ""$ 4 4q 89W%''""$ 4 4 9:&,,dhh.C.CWMr   c                    V P                   P                  R 4       V P                   P                  V P                  P	                  4       4       V P                  V P                  R 4       R# )  Nr;   r0   rQ   r9   r   r   rC   r?   s   &r   test_integerBananaTests.test_integer   sG    T"dgg..01d+r   c                    V P                   P                  R4       V P                   P                  V P                  P	                  4       4       V P                  V P                  R4       R# )r   Ni	r   r?   s   &r   test_negativeBananaTests.test_negative   sG    U#dgg..01e,r   c                    V P                   P                  R 4       V P                   P                  V P                  P	                  4       4       V P                  V P                  R 4       R# )g     @Nr   r?   s   &r   
test_floatBananaTests.test_float   sG    V$dgg..01f-r   c           	        ^^^^.RR.^RRR^	..^
.. .pV P                   P                  V4       V P                   P                  V P                  P	                  4       4       V P                  V P                  V4       R# )        >@皙D@   six   seven   eightNr   r   foos   & r   	test_listBananaTests.test_list   s}    F4LX!}-D	
 	S!dgg..01c*r   c                p   ^^^^.RR.^RRR^	..^
.\         P                  ^,          \         P                  ^,          \         P                  R,          .
pV P                  P                  V4       V P	                  V P
                  P                  4       4       V P                  V P                  V4       R# )zR
Test feeding the data byte per byte to the receiver. Normally
data is not split.
r   r   r   r   r   N)	sysmaxsizer;   r0   feedr9   r   r   rC   r   s   & r   test_partialBananaTests.test_partial   s     F4LX!}-DKK!OKK!OKK"
 	S!		$''""$%c*r   c                `    \        V4       F  pV P                  P                  V4       K   	  R# )zg
Feed the data byte per byte to the receiver.

@param data: The bytes to deliver.
@type data: L{bytes}
N)r	   r;   rQ   )r   databytes   && r   r   BananaTests.feed  s$     dODHH!!$' $r   c                `    R pV P                  \        P                  V P                  V4       R# )s   Nra   r
   rb   r   r   r   s   & r   test_oversizedListBananaTests.test_oversizedList  #    *&,,dii>r   c                `    R pV P                  \        P                  V P                  V4       R# )s   Nr   r   s   & r   test_oversizedString BananaTests.test_oversizedString!  r   r   c                z    R p V P                   P                  V4       R#   \        P                   d     R# i ; i)s       N)r;   rQ   r
   rb   )r   crashStrings   & r   test_crashStringBananaTests.test_crashString&  s6    1	HH!!+.!! 		s   ! ::c                    V P                   P                  R4       V P                   P                  V P                  P	                  4       4       V P                  V P                  R4       R# )l        N   r   r?   s   &r   test_crashNegativeLong"BananaTests.test_crashNegativeLong9  sI     	[)dgg..01k2r   c                x   RpRpRpV P                  V P                  V^,
          4      RV,           4       V P                  V P                  V^,
          4      RV,           4       V P                  V P                  V^ ,
          4      RV,           4       RpV P                  V P                  V^,           4      RV,           4       V P                  V P                  V^,           4      RV,           4       V P                  V P                  V^,           4      R	V,           4       R
pV P                  V P                  V^,           4      RV,           4       V P                  V P                  V^,           4      RV,           4       V P                  V P                  V^ ,           4      R4       RpV P                  V P                  V^,
          4      RV,           4       V P                  V P                  V^,
          4      R	V,           4       V P                  V P                  V^,
          4      RV,           4       R# )z
Test that integers below the maximum C{INT} token size cutoff are
serialized as C{INT} or C{NEG} and that larger integers are
serialized as C{LONGINT} or C{LONGNEG}.
is      }   ~   s                s   s       s         Nr   )r   r5   )r   	baseIntIn	baseNegIn
baseIntOutbaseLongIntOut
baseNegOutbaseLongNegOuts   &      r   test_sizedIntegerTypes"BananaTests.test_sizedIntegerTypesE  s     		,
Y]3Wz5IJY]3Wz5IJY]3Wz5IJ0Y]3W~5MNY]3W~5MNY]3W~5MN,
Y]3Wz5IJY]3Wz5IJY]35PQ0Y]3W~5MNY]3W~5MNY]3W~5MNr   r    N)r!   r"   r#   r$   rL   rR   rW   r[   r^   rV   rk   rt   rw   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r%   r&   r'   s   @r   rO   rO   f   s     '
;9HF 	0
NN$MN,
-
.
++,(?
?
&
3O Or   rO   c                      a  ] tR tRt o RtRt]! ]P                  P                  ],          34      ]P                  ,           t]! R
4      ]P                  ,           tR tR tR tR tRtV tR	# )DialectTestsic  z*
Tests for Banana's handling of dialects.
s   remotec                p    V P                  \        V P                  P                  V P                  4       R# )zd
If no dialect has been selected and a PB VOCAB item is received,
L{NotImplementedError} is raised.
N)ra   NotImplementedErrorr;   rQ   legalPbItemr?   s   &r   test_dialectNotSetDialectTests.test_dialectNotSetl  s'    
 	-txx/D/DdFVFVWr   c                    \        V P                  R4       V P                  P                  V P                  4       V P	                  V P
                  V P                  4       R# )zC
If the PB dialect has been selected, a PB VOCAB item is accepted.
   pbN)r,   r;   rQ   r   r   rC   vocabr?   s   &r   test_receivePbDialectTests.test_receivePbs  sB     	dhh&d../djj1r   c                    \        V P                  R4       V P                  \        V P                  P                  V P
                  4       R# )z
If the PB dialect has been selected and an unrecognized PB VOCAB item
is received, L{banana.Banana.dataReceived} raises L{KeyError}.
r   N)r,   r;   ra   KeyErrorrQ   illegalPbItemr?   s   &r   test_receiveIllegalPb"DialectTests.test_receiveIllegalPb{  s4    
 	dhh&(DHH$9$94;M;MNr   c                    \        V P                  R4       V P                  P                  V P                  4       V P	                  V P
                  V P                  P                  4       4       R# )zT
if pb dialect is selected, the sender must be able to send things in
that dialect.
r   N)r,   r;   r0   r   r   r   r9   r   r?   s   &r   test_sendPbDialectTests.test_sendPb  sK    
 	dhh&TZZ())477+;+;+=>r   r    N)z   )r!   r"   r#   r$   rL   r   rp   r
   rM   outgoingVocabularyVOCABr   r   r   r   r   r   r%   r&   r'   s   @r   r   r   c  sc      E99%@BCfllRK&MFLL0MX2O? ?r   r   c                   *   a  ] tR tRt o RtR tRtV tR# )GlobalCoderTestsi  zE
Tests for the free functions L{banana.encode} and L{banana.decode}.
c                    RpV P                  \        P                  \        P                  V4       RpV P	                  \        P                  ! V4      ^4       R# )z:
Calls to L{banana.decode} are independent of each other.
s   NsB   )ra   r
   rb   decoder   )r   undecodable	decodables   &  r   test_statelessDecode%GlobalCoderTests.test_statelessDecode  sE    
 -&,,fmm[I  	y115r   r    N)r!   r"   r#   r$   rL   r   r%   r&   r'   s   @r   r   r     s     6 6r   r   )r   	functoolsr   r9   r   twisted.internetr   r   twisted.internet.testingr   twisted.pythonr   twisted.python.compatr	   twisted.spreadr
   twisted.trial.unittestr   _maxintr   r,   r5   r7   rO   r   r   r    r   r   <module>r      ss   
    + 4 " + ! +
# # %,X <zO. zOz'?> '?T6x 6r   