Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/spread/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/spread/banana.pyc


[XMc@s\dZddlZddlZddlZddlmZddlmZddlm	Z	de
fdYZdZd	Z
ed
ZedZedZed
ZedZedZedZedZed
ZdZeddZdejejfdYZeZejejddZ dZ!dS(s
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
iN(tprotocol(tstyles(tlogtBananaErrorcBseZRS((t__name__t
__module__(((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyRscCsg|dkr |tddS|dks8tdx(|rb|t|d@|d?}q;WdS(Nis!can only encode positive integersii(tchrtAssertionError(tintegertstream((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytint2b128s	cCsEd}d}x2|D]*}t|}|||7}|dK}qW|S(s
    Convert an integer represented as a base 128 string into an C{int} or
    C{long}.

    @param st: The integer encoded in a string.
    @type st: C{str}

    @return: The integer value extracted from the string.
    @rtype: C{int} or C{long}
    iii(tord(tsttetitchartn((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytb1282int"s
iiiiiiiicCs
|adS(sk
    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: C{int}
    @param limit: The number of bytes of prefix for banana to allow when
    decoding.
    N(t
_PREFIX_LIMIT(tlimit((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytsetPrefixLimitDs
i@iitBananacBseZddgZdLZeZdZdZdZ	dZ
dZdZdZ
d	Zd
Zidd6d
d6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6dGdH6ZiZx$ejD]\ZZeee<q^WddIZdJZdKZRS(MtpbtnonecCsJ||_d|dd|_d|_d	|_d|dd|_dS(
st
        Set the prefix limit for decoding done by this protocol instance.

        @see: L{setPrefixLimit}
        iiiiNIiIi(tprefixLimitt_smallestLongIntt_smallestIntt_largestIntt_largestLongInt(tselfR((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyR\s
			cCsdS(sPSurrogate for connectionMade
        Called after protocol negotiation.
        N((R((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytconnectionReadyiscCs||_|jdS(N(tcurrentDialectR(Rtdialect((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyt_selectDialectns	cCs|jr|j|n|jr}x|D]3}||jkr)|j||j|Pq)q)Wtjd|jj	n9||jkr|j|ntjd|jj	dS(NsSThe client doesn't speak any of the protocols offered by the server: disconnecting.sYThe client selected a protocol the server didn't suggest and doesn't know: disconnecting.(
RtexpressionReceivedtisClientt
knownDialectstsendEncodedR!Rtmsgt	transporttloseConnection(Rtobjt	serverVer((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytcallExpressionReceivedrs		




cCs6|jtd|_|js2|j|jndS(N(RRtNoneRR#R%R$(R((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytconnectionMades
		cCs8|j}|r'|ddj|n
|j|dS(Nii(t	listStacktappendR+(Rtitemtl((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytgotItems	tcCse|j|}|j}|j}x6|rW|j|ks\tdt|jt|f||_d}xT|D] }|tkrPn|d}qrW||jkrtd|jfndS|| }||}||d}	t||jkrtd|jfn|t	krat
|}|tkrEtdn|j|gf|	}n|t
krt
|}|tkrtdnt|	|kr|	|}||	| qdSnC|tkr|	}t
|}||n|tkr|	}t
|}||n|tkrJ|	}t
|}||n|tkrv|	}t
|}||n|tkr|	}t
|}||j|nc|tkrt|	dkr|	d}|tjd	|	d dqdSntd
|fxF|rSt|dd|ddkrS|jd}
||
qWq"Wd|_dS(
NsThis ain't right: %s %siis1Security precaution: more than %d bytes of prefixs9Security precaution: longer than %d bytes worth of prefixs#Security precaution: List too long.s%Security precaution: String too long.is!dsInvalid Type Byte %riR3(tbufferR.R2RtreprtHIGH_BIT_SETRRtlentLISTRt
SIZE_LIMITR/tSTRINGtINTtLONGINTtLONGNEGtNEGtVOCABtincomingVocabularytFLOATtstructtunpacktNotImplementedErrortpop(RtchunkR4R.R2tpostchtnumttypebytetrestR0((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytdataReceiveds~
			4	


	





!+cCs
tdS(sFCalled when an expression (list, string, or int) is received.
        N(RD(Rtlst((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyR"siR,itclassitdereferenceit	referenceit
dictionaryitfunctionitinstanceitlisti	tmodulei
t
persistentittupleit
unpersistablei
tcopyitcacheitcacheditremoteitlocalitlcacheitversionitloginitpasswordit	challengeit	logged_init
not_logged_initcachemessageitmessageitansweriterroritdecrefitdecacheituncachecCs4g|_tj|j|_d|_||_dS(Ni(R.RYtoutgoingVocabularytoutgoingSymbolstoutgoingSymbolCountR#(RR#((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyt__init__s		cCs?tj}|j||j|j}|jj|dS(N(t	cStringIOtStringIOt_encodetwritetgetvalueR'(RR)tiotvalue((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyR%scCsVt|ttfrt|tkrCtdt|fntt|||tx|D]}|j||qgWnt|t	t
fra||jks||jkrtd|fn||j
krt|||tqR|dkrt|||tqR||jkrGt|||tqRt|||tnt|tr|t|tjd|nt|tr?|jdkr||jkr|j|}t|||tqRt|tkrtdt|fntt|||t||ntd|fdS(Ns#list/tuple is too long to send (%d)s"int/long is too large to send (%d)is!dRsstring is too long to send (%d)scould not send object: %r(t
isinstanceRTRWR7R9RR
R8RrtinttlongRRRR=R>RR;R<tfloatRARBtpacktstrRRmR?R:(RR)RstelemtsymbolID((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyRr sL













N(RRR$R,RR9t	sizeLimitRRR!R+R-R2R4RLR"RlR@titemstktvRoR%Rr(((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyRVsd	
						F	
	RcCs,tj}|t_tj||jS(sEncode a list s-expression.(RpRqt_iR'R%Rt(RMRu((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytencodeSs	
cCs>g}|jt_ztj|Wddt_t`X|dS(s)
    Decode a banana-encoded string.
    NR3i(R/RR"RLR4(RR1((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pytdecode[s	i
("t__doc__RYRpRBttwisted.internetRttwisted.persistedRttwisted.pythonRt	ExceptionRR
RRR8R;R:R>RAR<R=R?R6RR9tProtocolt	EphemeralRRR-R!RR(((s9/usr/lib/python2.7/dist-packages/twisted/spread/banana.pyt<module>
s2$