HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/spread/__pycache__/banana.cpython-38.pyc
U


W[.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�7/usr/lib/python3/dist-packages/twisted/spread/banana.pyrsrcCsJ|dkr|td��dS|dks(td��|rF|t|d@��|d?}q(dS)Nrz!can only encode positive integers��)�chr�AssertionError)Zinteger�streamrrr�int2b128srcCs6d}d}t|�D] }t|�}|||7}|dK}q|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�ZiZe��D]\ZZeee<q�d<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}
    �pb�noneNcCs<||_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�r5rrr�connectionReady{szBanana.connectionReadycCs||_|��dS�N)�currentDialectr7)r5Zdialectrrr�_selectDialect�szBanana._selectDialectcCs�|jr|�|�nr|jrZ|D]&}||jkr|�|�|�|�q�qt�d�|j�	�n*||jkrp|�|�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.)
r9�expressionReceived�isClient�
knownDialects�sendEncodedr:r�msg�	transportZloseConnection)r5�objZ	serverVerrrr�callExpressionReceived�s





zBanana.callExpressionReceivedcCs&|�t�d|_|js"|�|j�dSr8)r*r(r9r<r>r=r6rrr�connectionMade�s
zBanana.connectionMadecCs,|j}|r|dd�|�n
|�|�dS)N���r)�	listStack�appendrB)r5�item�lrrr�gotItem�szBanana.gotItem�cCs�|j|}|j}|j}|�r�|j|ks@tdt|j�t|�f��||_d}t|�D]}|tkrbq�|d}qR||jkr�td|jf��dS|d|�}|||d�}||dd�}	t	|�|jkr�td|jf��|t
k�rt|�}|tkr�td��|�
|gf�|	}�nz|tk�rdt|�}|tk�r0td��t	|	�|k�r\|	|d�}||	d|��ndS�n"|tk�r�|	}t|�}||��n|tk�r�|	}t|�}||�n�|tk�r�|	}t|�}||�n�|tk�r�|	}t|�}||�n�|tk�r0|	}t|�}|j|}
|jdk�r ||
�ntd	�|
���nV|tk�rxt	|	�d
k�rr|	d
d�}|t�d|	dd
��d�ndSntd|f��|rt	|d
d�|d
dkr|��d}
||
��q�qd|_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.r-z"Invalid item for pb protocol {0!r}��!dzInvalid Type Byte %rrDrJ)�bufferrErIr�reprr�HIGH_BIT_SETr0r�len�LISTr�
SIZE_LIMITrF�STRING�INT�LONGINT�LONGNEG�NEG�VOCAB�incomingVocabularyr9�NotImplementedError�format�FLOAT�structZunpack�pop)r5�chunkrMrErI�posZchZnumZtypebyte�restrGrrr�dataReceived�s�
$














�
 zBanana.dataReceivedcCs
t��dS)zFCalled when an expression (list, string, or int) is received.
        N)rZ)r5�lstrrrr;�szBanana.expressionReceivedrr/����rrK�	�
���
������������������)sNonesclasssdereferences	references
dictionarysfunctionsinstanceslistsmodules
persistentstuples
unpersistablescopyscachescachedsremoteslocalslcachesversionsloginspasswords	challenges	logged_ins
not_logged_inscachemessagesmessagesanswerserrorsdecrefsdecachesuncachecCs$g|_t�|j�|_d|_||_dS)Nr)rE�copy�outgoingVocabulary�outgoingSymbolsZoutgoingSymbolCountr<)r5r<rrr�__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@)r5rA�encodeStream�valuerrrr>6szBanana.sendEncodedcCs�t|ttf�r\t|�tkr,tdt|�f��tt|�|�|t�|D]}|�||�qF�n`t|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�rd||jk�rd|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)rrLr-z$byte string is too long to send (%d)z%Banana cannot send {0} objects: {1!r})�
isinstance�list�tuplerPrRrrrQr��intr	r1r4r2rVrWr3rTrU�floatr\r]Zpack�bytesr9r�rXrSr[r�type)r5rAr��elemZsymbolIDrrrr�GsX��










�

�zBanana._encode)r)r
rr�__doc__r=r0rRZ	sizeLimitr*r7r:rBrCrIrMrbr;r�rY�items�k�vr�r>r�rrrrr,]sf
L�'

r,r.cCst�}|t_t�|�|��S)zEncode a list s-expression.)r�_ir@r>r�)rcr�rrr�encode{s
r�cCs0g}|jt_zt�|�W5dt_t`X|dS)z)
    Decode a banana-encoded string.
    rJr)rFr�r;rMrb)rrHrrr�decode�sr�)-r�Z
__future__rrrr]�iorZtwisted.internetrZtwisted.persistedrZtwisted.pythonrZtwisted.python.compatrr	r
rZtwisted.python.reflectr�	ExceptionrrrrQrTrSrWr\rUrVrXrOr*r(rRZProtocolZ	Ephemeralr,r�rCr:r�r�rrrr�<module>s@