%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/spread/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/spread/test/__pycache__/test_banana.cpython-312.pyc

�

Ϫ�f�7����ddlZddlmZddlmZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZd
ZGd�de�Zd
�Zd�ZGd�de�ZGd�de�ZGd�de�ZGd�de�Zy)�N)�partial)�BytesIO)�main�protocol)�StringTransport)�failure)�	iterbytes)�banana)�TestCasel����c��eZdZd�Zy)�	MathTestsc�^�ttdd��ttdd��zttdd��zdgz}|D]c}t�}tj||j
�|j
�}tj|�}|j||��ey)Nr�di�iLi@Bi�Bl)	�list�rangerr
�int2b128�write�getvalue�b1282int�assertEqual)�self�	funkylist�i�x�v�ys      �A/usr/lib/python3/dist-packages/twisted/spread/test/test_banana.py�
test_int2b128zMathTests.test_int2b128s�����q�#����5��t�$�%�
&��5��'�*�+�
,��j�
�	��	#�A��	�A��O�O�A�q�w�w�'��
�
��A�����"�A����Q��"�	#�N)�__name__�
__module__�__qualname__r�rrr
r
s��#rr
c�(�|j|�y)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���H���G�$rc��t�}|�}|j|�|j�|j|�|j	�S)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�encoder02sJ�� �!�I�
�_�F��F���)�$�
�O�O���F���s���?�?��rc�:�eZdZdZej
Zd�Zd�Zd�Z	y)�BananaTestBasezn
    The base for test classes. It defines commonly used things and sets up a
    connection for testing.
    c�\�t�|_|j�|_|jj	tj|j��t|jd�|j|j_	tt|j�|_y)Nsnone)r�io�encClass�encr)r�FileWrapperr'�	putResult�expressionReceivedrr0�rs r�setUpzBananaTestBase.setUpPsi���)����=�=�?��������� 4� 4�T�W�W� =�>��d�h�h��(�&*�n�n����#��f�d�m�m�4��rc��||_y)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)rr=s  rr8zBananaTestBase.putResultXs����rc��|jjtjtj
��|`y�N)r6�connectionLostr�Failurer�CONNECTION_DONEr:s r�tearDownzBananaTestBase.tearDownas(�����������0D�0D� E�F��HrN)
r r!r"�__doc__r
�Bananar5r;r8rCr#rrr2r2Hs!���
�}�}�H�5��rr2c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�BananaTestsz
    General banana tests.
    c���|jjd�|jj|jj	��|j
dk(sJ�y)Nshello)r6r+�dataReceivedr4rr=r:s r�test_stringzBananaTests.test_stringksE�������X�&������d�g�g�.�.�0�1��{�{�h�&�&�&rc�(�|jdd�y)z�
        Banana does not support unicode.  ``Banana.sendEncoded`` raises
        ``BananaError`` if called with an instance of ``unicode``.
        �hellozbuiltins.strN)�_unsupportedTypeTestr:s r�test_unsupportedUnicodez#BananaTests.test_unsupportedUnicodeps��
	
�!�!�'�>�:rc�0�|jtd�y)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)rM�typer:s r�test_unsupportedBuiltinTypez'BananaTests.test_unsupportedBuiltinTypews��	
�!�!�$��8rc�F�|jt�tdz�y)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)rMr
r r:s r�test_unsupportedUserTypez$BananaTests.test_unsupportedUserType�s��	
�!�!�)�+�x�,�/F�Grc��|jtj|jj|�}|jd|�d�t
|��y)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.
        zBanana cannot send z objectsN)�assertRaisesr
�BananaErrorr6r+�assertIn�str)rr.�name�excs    rrMz BananaTests._unsupportedTypeTest�sD������ 2� 2�D�H�H�4H�4H�#�N���
�
�+�D�6��:�C��H�Erc��|jjd�|jj|jj	��|j|jd�|j|jt�y)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)	r6r+rIr4rrr=�assertIsInstance�intr:s r�test_intzBananaTests.test_int�s]��	
�����U�#������d�g�g�.�.�0�1�������e�,����d�k�k�3�/rc�V�|jj}|dz}d|zdz
}|dz}|S)N���)r6�prefixLimit)r�bytes�bits�largest�smallests     r�_getSmallestzBananaTests._getSmallest�s7�����$�$���q�y���T�'�A�+���Q�;���rc��|j�}|jtj|jj
|�y)zz
        Test that a long above the implementation-specific limit is rejected
        as too large to be encoded.
        N)rhrUr
rVr6r+)rrgs  r�test_encodeTooLargeLongz#BananaTests.test_encodeTooLargeLong�s4��
�$�$�&�����&�,�,�d�h�h�.B�.B�H�Mrc��|j�}|jj|jjdz�|jj	|�|j
j
�}|j
jd�|jj|jjdz�|jtj|jj|�y)zz
        Test that a long above the implementation specific limit is rejected
        as too large to be decoded.
        rarN)rhr6�setPrefixLimitrcr+r4r�truncaterUr
rVrI)rrg�encodeds   r�test_decodeTooLargeLongz#BananaTests.test_decodeTooLargeLong�s���
�$�$�&���������� 4� 4�q� 8�9������X�&��'�'�"�"�$����������������� 4� 4�� 9�:����&�,�,�d�h�h�.C�.C�W�Mrc�$�|j�Sr?)rhr:s r�_getLargestzBananaTests._getLargest�s���!�!�#�#�#rc��|j�}|jtj|jj
|�y)z�
        Test that a negative long below the implementation-specific limit is
        rejected as too small to be encoded.
        N)rqrUr
rVr6r+)rrfs  r�test_encodeTooSmallLongz#BananaTests.test_encodeTooSmallLong�s4��
�"�"�$�����&�,�,�d�h�h�.B�.B�G�Lrc��|j�}|jj|jjdz�|jj	|�|j
j
�}|j
jd�|jj|jjdz�|jtj|jj|�y)z�
        Test that a negative long below the implementation specific limit is
        rejected as too small to be decoded.
        rarN)rqr6rlrcr+r4rrmrUr
rVrI)rrfrns   r�test_decodeTooSmallLongz#BananaTests.test_decodeTooSmallLong�s���
�"�"�$���������� 4� 4�q� 8�9������W�%��'�'�"�"�$����������������� 4� 4�� 9�:����&�,�,�d�h�h�.C�.C�W�Mrc���|jjd�|jj|jj	��|j|jd�y)Ni��r6r+rIr4rrr=r:s r�test_integerzBananaTests.test_integer�sG�������T�"������d�g�g�.�.�0�1�������d�+rc���|jjd�|jj|jj	��|j|jd�y)Ni	���rwr:s r�
test_negativezBananaTests.test_negative�sG�������U�#������d�g�g�.�.�0�1�������e�,rc���|jjd�|jj|jj	��|j|jd�y)Ng��@rwr:s r�
test_floatzBananaTests.test_float�sG�������V�$������d�g�g�.�.�0�1�������f�-rc	��ddddgddgddd	d
dggdggg}|jj|�|jj|jj	��|j|j|�y)
Nrbra����>@皙���D@��six�seven�eight�	�
rw�r�foos  r�	test_listzBananaTests.test_list�s}��
�
�
��F�
�4�L�
�
�X��!�}�-�
�D��	
��	
�����S�!������d�g�g�.�.�0�1�������c�*rc�V�ddddgddgddd	d
dggdgtjdztjdztjd
zg
}|jj|�|j	|j
j
��|j|j|�y)zj
        Test feeding the data byte per byte to the receiver. Normally
        data is not split.
        rbrar~rr�r�r�r�r�r�r�r����N)	�sys�maxsizer6r+�feedr4rrr=r�s  r�test_partialzBananaTests.test_partial�s���
�
�
��F�
�4�L�
�
�X��!�}�-�
�D��K�K�!�O��K�K�!�O��K�K�"��
��	
�����S�!��	�	�$�'�'�"�"�$�%�������c�*rc�Z�t|�D]}|jj|��y)z�
        Feed the data byte per byte to the receiver.

        @param data: The bytes to deliver.
        @type data: L{bytes}
        N)r	r6rI)r�data�bytes   rr�zBananaTests.feeds)���d�O�	(�D��H�H�!�!�$�'�	(rc�^�d}|jtj|j|�y)Ns��rUr
rVr��rr�s  r�test_oversizedListzBananaTests.test_oversizedList�#��*�����&�,�,�d�i�i��>rc�^�d}|jtj|j|�y)Ns�r�r�s  r�test_oversizedStringz BananaTests.test_oversizedString!r�rc�r�d}	|jj|�y#tj$rYywxYw)Ns�)r6rIr
rV)r�crashStrings  r�test_crashStringzBananaTests.test_crashString&s6��1��	��H�H�!�!�+�.���!�!�	��	�s� �6�6c���|jjd�|jj|jj	��|j|jd�y)N��rwr:s r�test_crashNegativeLongz"BananaTests.test_crashNegativeLong9sI��	
�����[�)������d�g�g�.�.�0�1�������k�2rc��d}d}d}|j|j|dz
�d|z�|j|j|dz
�d|z�|j|j|dz
�d	|z�d
}|j|j|dz�d|z�|j|j|dz�d|z�|j|j|d
z�d|z�d}|j|j|dz�d|z�|j|j|dz�d	|z�|j|j|dz�d�d}|j|j|dz
�d|z�|j|j|dz
�d|z�|j|j|d
z
�d|z�y)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���r�s�ra�}rb�~r�s���r~�s�s�s��N)rr0)r�	baseIntIn�	baseNegIn�
baseIntOut�baseLongIntOut�
baseNegOut�baseLongNegOuts       r�test_sizedIntegerTypesz"BananaTests.test_sizedIntegerTypesEs��� �	��	�,�
�������Y��]�3�W�z�5I�J�������Y��]�3�W�z�5I�J�������Y��]�3�W�z�5I�J�0��������Y��]�3�W�~�5M�N�������Y��]�3�W�~�5M�N�������Y��]�3�W�~�5M�N�,�
�������Y��]�3�W�z�5I�J�������Y��]�3�W�z�5I�J�������Y��]�3�5P�Q�0��������Y��]�3�W�~�5M�N�������Y��]�3�W�~�5M�N�������Y��]�3�W�~�5M�NrN)r r!r"rDrJrNrQrSrMr^rhrjrorqrsrurxrzr|r�r�r�r�r�r�r�r�r#rrrGrGfs����'�
;�9�H�F� 	0�
�N�N�$�M�N�,�
-�
.�

+�+�,(�?�
?�
�&
3�OrrGc��eZdZdZdZeejjef�ejzZ
ed�ejzZd�Zd�Z
d�Zd�Zy)	�DialectTestsz2
    Tests for Banana's handling of dialects.
    sremote)�zc�n�|jt|jj|j�y)z|
        If no dialect has been selected and a PB VOCAB item is received,
        L{NotImplementedError} is raised.
        N)rU�NotImplementedErrorr6rI�legalPbItemr:s r�test_dialectNotSetzDialectTests.test_dialectNotSetls'��
	
���-�t�x�x�/D�/D�d�FV�FV�Wrc���t|jd�|jj|j�|j	|j
|j�y)zS
        If the PB dialect has been selected, a PB VOCAB item is accepted.
        �pbN)r'r6rIr�rr=�vocabr:s r�test_receivePbzDialectTests.test_receivePbssB��	�d�h�h��&������d�.�.�/�������d�j�j�1rc��t|jd�|jt|jj|j
�y)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'r6rU�KeyErrorrI�
illegalPbItemr:s r�test_receiveIllegalPbz"DialectTests.test_receiveIllegalPb{s4��
	�d�h�h��&����(�D�H�H�$9�$9�4�;M�;M�Nrc���t|jd�|jj|j�|j	|j
|jj��y)zl
        if pb dialect is selected, the sender must be able to send things in
        that dialect.
        r�N)r'r6r+r�rr�r4rr:s r�test_sendPbzDialectTests.test_sendPb�sK��
	�d�h�h��&������T�Z�Z�(�����)�)�4�7�7�+;�+;�+=�>rN)r r!r"rDr�rdr
rE�outgoingVocabulary�VOCABr�r�r�r�r�r�r#rrr�r�cs[���
�E�����9�9�%�@�B�C�f�l�l�R�K��&�M�F�L�L�0�M�X�2�O�?rr�c��eZdZdZd�Zy)�GlobalCoderTestszM
    Tests for the free functions L{banana.encode} and L{banana.decode}.
    c��d}|jtjtj|�d}|j	tj|�d�y)zJ
        Calls to L{banana.decode} are independent of each other.
        sB�s�rbN)rUr
rV�decoder)r�undecodable�	decodables   r�test_statelessDecodez%GlobalCoderTests.test_statelessDecode�sE��
-�����&�,�,�f�m�m�[�I� �	�������y�1�1�5rN)r r!r"rDr�r#rrr�r��s���6rr�)r��	functoolsrr4r�twisted.internetrr�twisted.internet.testingr�twisted.pythonr�twisted.python.compatr	�twisted.spreadr
�twisted.trial.unittestr�_maxintr
r'r0r2rGr�r�r#rr�<module>r�ss��
���+�4�"�+�!�+�
��
#��
#� %��,�X��<zO�.�zO�z'?�>�'?�T6�x�6r

Zerion Mini Shell 1.0