%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�/��`�dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZGd	�d
e�Zd�Zd�Zd
ZdZdZdZdZdZdZdZd
Zd�Zdaed�dZGd�dej>ej@�Z!e!�Z"e"jG�e"jId�d�Z%d�Z&y)z�
Banana -- s-exp based protocol.

Future Plans: This module is almost entirely stable.  The same caveat applies
to it as applies to L{twisted.spread.jelly}, however.  Read its future plans
for more details.

@author: Glyph Lefkowitz
�N)�BytesIO)�protocol)�styles)�log)�	iterbytes)�fullyQualifiedNamec��eZdZy)�BananaErrorN)�__name__�
__module__�__qualname__���7/usr/lib/python3/dist-packages/twisted/spread/banana.pyr
r
s��rr
c�x�|dk(r	|d�y|dkDsJd��|r|t|dzf��|dz	}|r�yy)Nr�z!can only encode positive integers��)�bytes)�integer�streams  r�int2b128rsJ���!�|��u�
���Q�;�;�;�;�;�
��u�g��n�&�'�(��Q�,��rc�^�d}d}t|�D]}t|�}|||zz
}|dz}�|S)z�
    Convert an integer represented as a base 128 string into an L{int}.

    @param st: The integer encoded in a byte string.
    @type st: L{bytes}

    @return: The integer value extracted from the byte string.
    @rtype: L{int}
    �rr)r�ord)�st�e�i�char�ns     r�b1282intr!)sG��	
�A�	�A��"�
�����I��	�Q��U�
��	�a����
�Hr����������������c��|ay)ak
    Set the limit on the prefix length for all Banana connections
    established after this call.

    The prefix length limit determines how many bytes of prefix a banana
    decoder will allow before rejecting a potential object as too large.

    @type limit: L{int}
    @param limit: The number of bytes of prefix for banana to allow when
    decoding.
    N)�
_PREFIX_LIMIT)�limits r�setPrefixLimitr-Ks	���Mr�@i
c�2�eZdZdZddgZdZeZd�Zd�Z	d�Z
d�Zd	�Zd
�Z
dZd�Zd
�Zidd�dd�dd�dd�dd�dd�dd�dd�dd�d d!�d"d#�d$d%�d&d'�d(d)�d*d+�d,d-�d.d/�d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>��ZiZej'�D]
\ZZeee<�dBd?�Zd@�ZdA�Zy)C�Bananaz�
    L{Banana} implements the I{Banana} s-expression protocol, client and
    server.

    @ivar knownDialects: These are the profiles supported by this Banana
        implementation.
    @type knownDialects: L{list} of L{bytes}
    �pb�noneNc�p�||_d|dzzdz|_d|_d|_d|dzzdz
|_y)zt
        Set the prefix limit for decoding done by this protocol instance.

        @see: L{setPrefixLimit}
        �rri�i���N)�prefixLimit�_smallestLongInt�_smallestInt�_largestInt�_largestLongInt)�selfr,s  rr-zBanana.setPrefixLimitrsK��!���"#���	�"2� 3�a� 7���$���$��� �U�Q�Y�/�!�3��rc��y)zPSurrogate for connectionMade
        Called after protocol negotiation.
        Nr�r:s r�connectionReadyzBanana.connectionReady~s�rc�2�||_|j�y�N)�currentDialectr=)r:�dialects  r�_selectDialectzBanana._selectDialect�s��%������rc���|jr|j|�y|jri|D]4}||jvs�|j	|�|j|�yt
jd�|jj�y||jvr|j|�yt
jd�|jj�y)NzSThe client doesn't speak any of the protocols offered by the server: disconnecting.zYThe client selected a protocol the server didn't suggest and doesn't know: disconnecting.)
r@�expressionReceived�isClient�
knownDialects�sendEncodedrBr�msg�	transport�loseConnection)r:�obj�	serverVers   r�callExpressionReceivedzBanana.callExpressionReceived�s�������#�#�C�(��}�}�!$�4�I� �D�$6�$6�6��(�(��3��+�+�I�6��	4��G�G�@���N�N�1�1�3��$�,�,�,��'�'��,��G�G�C���N�N�1�1�3rc��|jt�d|_|js|j	|j
�yyr?)r-r+r@rErGrFr<s r�connectionMadezBanana.connectionMade�s8�����M�*�"����}�}����T�/�/�0�rc�r�|j}|r|ddj|�y|j|�y)N���r)�	listStack�appendrM)r:�item�ls   r�gotItemzBanana.gotItem�s0���N�N���
�b�E�!�H�O�O�D�!��'�'��-rrc��|j|z}|j}|j}|�r�|j|k7s3Jdjt	|j�t	|����||_d}t|�D]}|tk\rn0|dz}�||jkDrtd|jfz��y|d|}|||dz}||dzd}	t|�|jkDrtd|jfz��|tk(r6t|�}|tkDrtd��|j|gf�|	}�n`|tk(r@t|�}|tkDrtd��t|	�|k\r|	|d}||	d|��ny|tk(r|	}t|�}||�n�|t k(r|	}t|�}||�n�|t"k(r|	}t|�}||�n�|t$k(r|	}t|�}||�n�|t&k(rB|	}t|�}|j(|}
|j*dk(r	||
�n\t-d	|
����|t.k(r7t|	�d
k\r(|	d
d}|t1j2d|	dd
�d�nyt-d|����|rRt|d
d�|d
dk(r8|j5�d}
||
�|rt|d
d�|d
dk(r�8|r���d|_y)NzThis ain't right: {} {}rrz1Security precaution: more than %d bytes of prefixz9Security precaution: longer than %d bytes worth of prefixz#Security precaution: List too long.z%Security precaution: String too long.r1zInvalid item for pb protocol ��!dzInvalid Type Byte rQr)�bufferrRrV�format�reprr�HIGH_BIT_SETr5r
�len�LISTr!�
SIZE_LIMITrS�STRING�INT�LONGINT�LONGNEG�NEG�VOCAB�incomingVocabularyr@�NotImplementedError�FLOAT�struct�unpack�pop)r:�chunkrZrRrV�pos�ch�num�typebyte�restrTs           r�dataReceivedzBanana.dataReceived�s5�����u�$���N�N�	��,�,����;�;�&�(�
�*C�*J�*J��T�[�[�!��V��+�
�(�!�D�K��C���'�

����%���A�g��

�
��)�)�)�%�K��+�+�-�.������#�,�C��c�C�!�G�,�H��#��'�)�$�D��3�x�$�*�*�*�!�O��'�'�)�*����4���s�m����#�%�&K�L�L�� � �#�r��+����V�#��s�m����#�%�&M�N�N��t�9��#�!�#�$�Z�F��D��#�J�'���S�����s�m������W�$����s�m������W�$����s�m�����
��S������}�n������U�"����s�m���.�.�s�3���&�&�%�/��D�M�-�0M�d�X�.V�W�W��U�"��t�9��>�!�!�"�X�F��F�M�M�$��R�a��9�!�<�=��)�,>�x�l�*K�L�L���Y�r�]�1�%5�!6�)�B�-��:J�!J� �}�}��q�)����
���Y�r�]�1�%5�!6�)�B�-��:J�!J�U�Z��rc��t��)z=Called when an expression (list, string, or int) is received.)rh)r:�lsts  rrDzBanana.expressionReceiveds��!�#�#rsNonersclassr4sdereference�s	reference�s
dictionary�sfunction�sinstancerslistrXsmodule�	s
persistent�
stuple�s
unpersistable�scopy�
scache�scached�sremote�slocal���������������)slcachesversionsloginspasswords	challenges	logged_ins
not_logged_inscachemessagesmessagesanswerserrorsdecrefsdecachesuncachec�v�g|_tj|j�|_d|_||_y)Nr)rR�copy�outgoingVocabulary�outgoingSymbols�outgoingSymbolCountrE)r:rEs  r�__init__zBanana.__init__4s/�����#�y�y��)@�)@�A���#$�� � ��
rc��t�}|j||j�|j�}|jj|�y)a
        Send the encoded representation of the given object:

        @param obj: An object to encode and send.

        @raise BananaError: If the given object is not an instance of one of
            the types supported by Banana.

        @return: L{None}
        N)r�_encode�write�getvaluerI)r:rK�encodeStream�values    rrGzBanana.sendEncoded:s?���y�����S�,�,�,�-��%�%�'�������U�#rc	��t|ttf�ret|�tkDrtdt|�fz��t
t|�|�|t�|D]}|j||��yt|t�r�||jks||jkDrtd|fz��||jkrt
||�|t�y|dkrt
||�|t�y||jkrt
||�|t �yt
||�|t"�yt|t$�r)|t&�|t)j*d|��yt|t,�r�|j.dk(r6||j0vr(|j0|}t
||�|t2�yt|�tkDrtdt|�fz��t
t|�|�|t4�||�ytdj7t9t;|��|���)Nz#list/tuple is too long to send (%d)zint is too large to send (%d)rrYr1z$byte string is too long to send (%d)z#Banana cannot send {} objects: {!r})�
isinstance�list�tupler^r`r
rr_r��intr6r9r7rdrer8rbrc�floatrirj�packrr@r�rfrar[r�type)r:rKr��elem�symbolIDs     rr�zBanana._encodeJs����c�D�%�=�)��3�x�*�$�!�"G�3�s�8�+�"U�V�V��S��X�u�%��$�K��
*�����T�5�)�
*�
��S�
!��T�*�*�*�c�D�4H�4H�.H�!�"A�S�F�"J�K�K��T�&�&�&��#��u�%��g���q���#��u�%��c�
���(�(�(���e�$��c�
���e�$��g��
��U�
#��%�L��&�+�+�d�C�(�)�
��U�
#��"�"�e�+��t�7K�7K�0K��/�/��4����5�)��e���s�8�j�(�%�>�#�c�(��L�����S��5�)��f�
��c�
��5�<�<�&�t�C�y�1�3���
r)r)rrr
�__doc__rFr5r`�	sizeLimitr-r=rBrMrOrVrZrsrDr�rg�items�k�vr�rGr�rrrr0r0as�����G�$�M��K��I�
4��
�4�<1�.��F�Q�f$�#���#�	�!�#�	��	#�
	�a�#�	�q�
#�	�Q�#�	�Q�#�	��#�	�1�#�	�r�#�	�"�#�	�"�#�	��#� 	�"�!#�"	�2�##�$	�2�%#�&	�"�'#�(��������������E#��J��"�(�(�*�"���1� !��1��"�!�$� -rr0r2c�v�t�}|t_tj|�|j	�S)zEncode a list s-expression.)r�_irIrGr�)rur�s  r�encoder��s+���9�L��B�L��N�N�3��� � �"�"rc��g}|jt_	tj|�dt_t`|dS#dt_t`wxYw)z)
    Decode a banana-encoded string.
    rr)rSr�rDrsrZ)rrUs  r�decoder��sM��	�A��H�H�B��"�
�������	��!��Q�4�K����	��!�s�A�A)'r�r�rj�ior�twisted.internetr�twisted.persistedr�twisted.pythonr�twisted.python.compatr�twisted.python.reflectr�	Exceptionr
rr!r_rbrarerircrdrfr]r-r+r`�Protocol�	Ephemeralr0r�rOrBr�r�rrr�<module>r�s���
��
��%�$��+�5�	�)�	��
�(��
��	��
����
��
������
� �
��r��
�
�V�X�
�
�� 0� 0�V�t�X���������'��#�r

Zerion Mini Shell 1.0