Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/spread/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/spread/__pycache__/banana.cpython-37.pyc

B

:��].0�@s6dZddlmZmZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZdd	lmZGd
d�de�Zdd
�Zdd�Zed�Zed�Zed�Zed�Zed�Zed�Zed�Zed�Z ed�Z!dd�Z"da#e"d�dZ$Gdd�de	j%ej&�Z'e'�Z(e(�)�e(�*d�dd �Z+d!d"�Z,dS)#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
�)�absolute_import�divisionN)�BytesIO)�protocol)�styles)�log)�	iterbytes�long�	_bytesChr)�fullyQualifiedNamec@seZdZdS)�BananaErrorN)�__name__�
__module__�__qualname__�rr�H/opt/alt/python37/lib64/python3.7/site-packages/twisted/spread/banana.pyrsrcCsN|dkr|td��dS|dks(td��x |rH|t|d@��|d?}q*WdS)Nrz!can only encode positive integers��)�chr�AssertionError)�integer�streamrrr�int2b128srcCs:d}d}x,t|�D] }t|�}|||7}|dK}qW|S)a
    Convert an integer represented as a base 128 string into an L{int} or
    L{long}.

    @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} or L{long}
    �rr)r�ord)�st�e�i�char�nrrr�b1282int'sr ��������cCs|adS)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)�limitrrr�setPrefixLimitIs
r+�@i
c @s�eZdZdZddgZdZeZdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dZdd�Zdd�Zddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5�ZiZxe��D]\ZZeee<q�Wd<d6d7�Zd8d9�Zd:d;�ZdS)=�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}
    spbsnoneNcCs<||_d|dd|_d|_d|_d|dd|_dS)zt
        Set the prefix limit for decoding done by this protocol instance.

        @see: L{setPrefixLimit}
        �rri�i���N)�prefixLimit�_smallestLongInt�_smallestInt�_largestInt�_largestLongInt)�selfr*rrrr+ns
zBanana.setPrefixLimitcCsdS)zPSurrogate for connectionMade
        Called after protocol negotiation.
        Nr)r4rrr�connectionReady{szBanana.connectionReadycCs||_|��dS)N)�currentDialectr5)r4Zdialectrrr�_selectDialect�szBanana._selectDialectcCs�|jr|�|�nt|jr\xl|D]$}||jkr|�|�|�|�PqWt�d�|j�	�n*||jkrr|�|�nt�d�|j�	�dS)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.)
r6�expressionReceived�isClient�
knownDialects�sendEncodedr7r�msg�	transportZloseConnection)r4�objZ	serverVerrrr�callExpressionReceived�s






zBanana.callExpressionReceivedcCs&|�t�d|_|js"|�|j�dS)N)r+r)r6r9r;r:)r4rrr�connectionMade�s
zBanana.connectionMadecCs,|j}|r|dd�|�n
|�|�dS)N���r)�	listStack�appendr?)r4�item�lrrr�gotItem�szBanana.gotItem�cCs�|j|}|j}|j}�x�|�r�|j|ksDtdt|j�t|�f��||_d}x@t|�D]}|tkrfP|d}qXW||jkr�td|jf��dS|d|�}|||d�}||dd�}	t	|�|jkr�td|jf��|t
k�rt|�}|tkr�td��|�
|gf�|	}�nz|tk�rjt|�}|tk�r6td��t	|	�|k�rb|	|d�}||	d|��ndS�n"|tk�r�|	}t|�}||��n|tk�r�|	}t|�}||�n�|tk�r�|	}t|�}||�n�|tk�r�|	}t|�}||�n�|tk�r6|	}t|�}|j|}
|jdk�r&||
�ntd	�|
���nV|tk�r~t	|	�d
k�rx|	d
d�}|t�d|	dd
��d�ndSntd|f��x>|�r�t	|d
d�|d
dk�r�|��d}
||
��q�WqWd|_dS)NzThis ain't right: %s %srrz1Security 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.spbz"Invalid item for pb protocol {0!r}�z!dzInvalid Type Byte %rrArG)�bufferrBrFr�reprr�HIGH_BIT_SETr/r�len�LISTr �
SIZE_LIMITrC�STRING�INT�LONGINT�LONGNEG�NEG�VOCAB�incomingVocabularyr6�NotImplementedError�format�FLOAT�struct�unpack�pop)r4�chunkrIrBrF�pos�ch�numZtypebyte�restrDrrr�dataReceived�s�

$














&zBanana.dataReceivedcCs
t��dS)zFCalled when an expression (list, string, or int) is received.
        N)rV)r4�lstrrrr8�szBanana.expressionReceivedrr.����rrH�	�
���
������������������)sNonesclasssdereferences	references
dictionarysfunctionsinstanceslistsmodules
persistentstuples
unpersistablescopyscachescachedsremoteslocalslcachesversionsloginspasswords	challenges	logged_ins
not_logged_inscachemessagesmessagesanswerserrorsdecrefsdecachesuncachecCs$g|_t�|j�|_d|_||_dS)Nr)rB�copy�outgoingVocabulary�outgoingSymbolsZoutgoingSymbolCountr9)r4r9rrr�__init__/szBanana.__init__cCs,t�}|�||j�|��}|j�|�dS)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�getvaluer=)r4r>�encodeStream�valuerrrr;6szBanana.sendEncodedcCs�t|ttf�r`t|�tkr,tdt|�f��tt|�|�|t�x|D]}|�||�qHW�nbt|t	t
f��r||jks�||jkr�td|f��||j
kr�t||�|t�nN|dkr�t||�|t�n0||jkr�t||�|t�nt||�|t�n�t|t��r(|t�|t�d|��n�t|t��r�|jdk�rj||jk�rj|j|}t||�|t�n>t|�tk�r�tdt|�f��tt|�|�|t�||�ntd�tt|��|���dS)Nz#list/tuple is too long to send (%d)z"int/long is too large to send (%d)rz!dspbz$byte string is too long to send (%d)z%Banana cannot send {0} objects: {1!r})�
isinstance�list�tuplerLrNrrrMr��intr	r0r3r1rRrSr2rPrQ�floatrXrY�pack�bytesr6r�rTrOrWr�type)r4r>r��elemZsymbolIDrrrr�GsN












zBanana._encode)r)r
rr�__doc__r:r/rNZ	sizeLimitr+r5r7r?r@rFrIrar8rrU�items�k�vr�r;r�rrrrr-]sd
L
r-snonecCst�}|t_t�|�|��S)zEncode a list s-expression.)r�_ir=r;r�)rbr�rrr�encode{s
r�cCs0g}|jt_zt�|�Wddt_t`X|dS)z)
    Decode a banana-encoded string.
    NrGr)rCr�r8rarI)rrErrr�decode�sr�)-r��
__future__rrr~rY�iorZtwisted.internetrZtwisted.persistedrZtwisted.pythonrZtwisted.python.compatrr	r
rZtwisted.python.reflectr�	Exceptionrrr rMrPrOrSrXrQrRrTrKr+r)rNZProtocolZ	Ephemeralr-r�r@r7r�r�rrrr�<module>
s@