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/pb.pyc


*Nc(@sjdZddlZddlZddlmZmZddlmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZmZdd	lmZdd
lmZmZddlmZmZddlmZdd
lmZddlmZm Z ddl!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(ddl'm)Z)m*Z*ddl'm+Z+m,Z,ddl'm-Z-ddl'm.Z.ddl'm/Z/ddl'm0Z0ddl'm1Z1ddl'm2Z2ddl'm3Z3ddl'm4Z4ddl'm5Z5ddl'm6Z6ddl'm7Z7ddl'm8Z8dd l'm9Z9dd!l'm:Z:dd"l'm;Z;d#Z<d$Z=d%e>fd&YZ?d'e?fd(YZ@d)e>fd*YZAd+e>fd,YZBd-fd.YZCd/ZDe
ed0d1d2d3eDZDd4e>fd5YZEd6ZFe
ed0d1d2d3eFZFd7efd8YZGd9fd:YZHd;e)fd<YZId=e(ejJfd>YZKe6d?eKd@fdAYZLdBejMe/fdCYZNdDe2ejMfdEYZOe6eNeOd3dFZPdGe&jQfdHYZRdIZSdJZTdKejUfdLYZVdMejWfdNYZXdOefdPYZYdQfdRYZZeeZee,dSfdTYZ[dUe)e[fdVYZ\dWe)e[fdXYZ]dYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdnd%d'd)d4d-d7d9d;d=dBdDdodGdpdqdKdMdOg(Z^dS(rs
Perspective Broker

"This isn't a professional opinion, but it's probably got enough
internet to kill you." --glyph

Introduction
============

This is a broker for proxies for and copies of objects.  It provides a
translucent interface layer to those proxies.

The protocol is not opaque, because it provides objects which represent the
remote proxies and require no context (server references, IDs) to operate on.

It is not transparent because it does I{not} attempt to make remote objects
behave identically, or even similiarly, to local objects.  Method calls are
invoked asynchronously, and specific rules are applied when serializing
arguments.

To get started, begin with L{PBClientFactory} and L{PBServerFactory}.

@author: Glyph Lefkowitz
iN(t
implementst	Interface(tlogtfailuretreflect(tVersion(t
deprecated(tmd5(tdefertprotocol(tPortal(t
IAnonymoustICredentials(tIUsernameHashedPasswordt	Anonymous(tstyles(tregisterAdapter(t
IJellyabletIUnjellyable(tjellytunjellytglobalSecurity(tbanana(tSerializable(t
ReferenceabletNoSuchMethod(tRoottIPBRoot(t	ViewPoint(tViewable(tCopyable(t	Jellyable(t	Cacheable(t
RemoteCopy(tRemoteCache(tRemoteCacheObserver(tcopyTags(tsetUnjellyableForClass(tsetUnjellyableFactoryForClass(tsetUnjellyableForClassTree(tsetCopierForClass(tsetFactoryForClass(tsetCopierForClassTreeiiS"t
ProtocolErrorcBseZdZRS(sN
    This error is raised when an invalid protocol statement is received.
    (t__name__t
__module__t__doc__(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR+PstDeadReferenceErrorcBseZdZRS(sx
    This error is raised when a method is called on a dead reference (one whose
    broker has been disconnected).
    (R,R-R.(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR/WstErrorcBseZdZRS(s 
    This error can be raised to generate known error conditions.

    When a PB callable method (perspective_, remote_, view_) raises
    this error, it indicates that a traceback should not be printed,
    but instead, the string representation of the exception should be
    sent.
    (R,R-R.(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR0_stRemoteErrorcBseZdZdZRS(s
    This class is used to wrap a string-ified exception from the remote side to
    be able to reraise it. (Raising string exceptions is no longer possible in
    Python 2.6+)

    The value of this exception will be a str() representation of the remote
    value.

    @ivar remoteType: The full import path of the exception class which was
        raised on the remote end.
    @type remoteType: C{str}

    @ivar remoteTraceback: The remote traceback.
    @type remoteTraceback: C{str}

    @note: It's not possible to include the remoteTraceback if this exception is
        thrown into a generator. It must be accessed as an attribute.
    cCs&tj||||_||_dS(N(t	Exceptiont__init__t
remoteTypetremoteTraceback(tselfR4tvalueR5((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3~s	(R,R-R.R3(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR1kstRemoteMethodcBs2eZdZdZdZdZdZRS(s9This is a translucent reference to a remote message.
    cCs||_||_dS(sKInitialize with a L{RemoteReference} and the name of this message.
        N(tobjtname(R6R9R:((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3s	cCst|j|jf|S(N(tcmpR9R:(R6tother((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt__cmp__scCst|j|jfS(N(thashR9R:(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt__hash__scOs1|jjjd|jj|jj|j||S(s/Asynchronously invoke a remote method.
        t(R9tbrokert_sendMessagetperspectivetluidR:(R6targstkw((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt__call__s(R,R-R.R3R=R?RG(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR8s
			cOsdS(s}
    Do nothing.

    Neque porro quisquam est qui dolorem ipsum quia dolor sit amet,
    consectetur, adipisci velit...
    N((RERF((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytnoOperationsttwistediiitPBConnectionLostcBseZRS((R,R-(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRJscCstjdtj|dS(s9
    Print a traceback (string) to the standard log.
    sPerspective Broker Traceback:N(Rtmsg(ttb((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytprintTracebacks
tIPerspectivecBseZdZdZRS(s
    per*spec*tive, n. : The relationship of aspects of a subject to each
    other and to a whole: 'a perspective of history'; 'a need to view
    the problem in the proper perspective'.

    This is a Perspective Broker-specific wrapper for an avatar. That
    is to say, a PB-published view on to the business logic for the
    system's concept of a 'user'.

    The concept of attached/detached is no longer implemented by the
    framework. The realm is expected to implement such semantics if
    needed.
    cCsdS(s
        This method is called when a network message is received.

        @arg broker: The Perspective Broker.

        @type message: str
        @arg message: The name of the method called by the other end.

        @type args: list in jelly format
        @arg args: The arguments that were passed by the other end. It
                   is recommend that you use the `unserialize' method of the
                   broker to decode this.

        @type kwargs: dict in jelly format
        @arg kwargs: The keyword arguments that were passed by the
                     other end.  It is recommended that you use the
                     `unserialize' method of the broker to decode this.

        @rtype: A jelly list.
        @return: It is recommended that you use the `serialize' method
                 of the broker on whatever object you need to return to
                 generate the return value.
        N((RAtmessageREtkwargs((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytperspectiveMessageReceiveds(R,R-R.RQ(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRNs
tAvatarcBs!eZdZeedZRS(s
    A default IPerspective implementor.

    This class is intended to be subclassed, and a realm should return
    an instance of such a subclass when IPerspective is requested of
    it.

    A peer requesting a perspective will receive only a
    L{RemoteReference} to a pb.Avatar.  When a method is called on
    that L{RemoteReference}, it will translate to a method on the
    remote perspective named 'perspective_methodname'.  (For more
    information on invoking methods on other objects, see
    L{flavors.ViewPoint}.)
    cCs|j||}|j||}t|d|}y|||}Wn.tk
rztjd|||fnX|j|||||S(si
        This method is called when a network message is received.

        This will call::

            self.perspective_%(message)s(*broker.unserialize(args),
                                         **broker.unserialize(kw))

        to handle the method; subclasses of Avatar are expected to
        implement methods using this naming convention.
        sperspective_%ss%s didn't accept %s and %s(tunserializetgetattrt	TypeErrorRRKt	serialize(R6RARORERFtmethodtstate((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRQs

(R,R-R.RRNRQ(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRRs
tAsReferenceablecBseZdZddZRS(s6
    A reference directed towards another object.
    tremotecCst||d|_dS(NtMessageReceived(RTtremoteMessageReceived(R6tobjecttmessageType((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3s(R,R-R.R3(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRY
stRemoteReferencecBs{eZdZeedZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZRS(s]
    A translucent reference to a remote object.

    I may be a reference to a L{flavors.ViewPoint}, a
    L{flavors.Referenceable}, or an L{IPerspective} implementor (e.g.,
    pb.Avatar).  From the client's perspective, it is not possible to
    tell which except by convention.

    I am a "translucent" reference because although no additional
    bookkeeping overhead is given to the application programmer for
    manipulating a reference, return values are asynchronous.

    See also L{twisted.internet.defer}.

    @ivar broker: The broker I am obtained through.
    @type broker: L{Broker}
    cCs1||_||_||_||_g|_dS(s(internal) Initialize me with a broker and a locally-unique ID.

        The ID is unique only to the particular Perspective Broker
        instance.
        N(RDRAt
doRefCountRCtdisconnectCallbacks(R6RCRARDR`((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3-s
				cCsQt|st|jj|t|jdkrM|jj|jndS(sRegister a callback to be called if our broker gets disconnected.

        This callback will be called with one argument, this instance.
        iN(tcallabletAssertionErrorRatappendtlenRAtnotifyOnDisconnectt
_disconnected(R6tcallback((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRf9scCs3|jj||js/|jj|jndS(s>Remove a callback that was registered with notifyOnDisconnect.N(RatremoveRAtdontNotifyOnDisconnectRg(R6Rh((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRjCs	cCs+x|jD]}||q
Wd|_dS(s<Called if we are disconnected and have callbacks registered.N(RatNone(R6Rh((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRgIscCs<|jr4|j|jks'tdd|jfSdSdS(sZIf I am being sent back to where I came from, serialize as a local backreference.
        s6Can't send references to brokers other than their own.tlocalt
unpersistablesReferences cannot be serializedN(RmsReferences cannot be serialized(tinvokerRARcRD(R6tjellier((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytjellyForOs	
cCs'|j|jj|j|dd|S(Ni(R3RntunserializingPerspective(R6t	unjelliertunjellyList((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
unjellyForXs#cOs%|jjd|j|j|||S(sAsynchronously invoke a remote method.

        @type _name: C{str}
        @param _name:  the name of the remote method to invoke
        @param args: arguments to serialize for the remote function
        @param kw:  keyword arguments to serialize for the remote function.
        @rtype:   L{twisted.internet.defer.Deferred}
        @returns: a Deferred which will be fired when the result of
                  this remote call is received.
        R@(RARBRCRD(R6t_nameRERF((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
callRemote\scCs
t||S(s,Get a L{RemoteMethod} for this key.
        (R8(R6tkey((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytremoteMethodnscCsGt|tr7|j|jkr7t|j|jSnt|j|S(s4Compare me [to another L{RemoteReference}].
        (t
isinstanceR_RAR;RD(R6R<((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR=sscCs|jS(sHash me.
        (RD(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR?{scCs#|jr|jj|jndS(s;Do distributed reference counting on finalization.
        N(R`RAt
sendDecRefRD(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt__del__s	(R,R-R.RRR3RfRjRgRpRtRvRxR=R?R{(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR_s
		
									RZtLocalcBs5eZdZddZdZdZdZRS(s.(internal) A reference to a local object.
    cCs||_||_d|_dS(sInitialize.
        iN(R]RCtrefcount(R6R]RC((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3s		cCsd|j|jfS(Ns<pb.Local %r ref:%s>(R]R}(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt__repr__scCs|jd|_|jS(s1Increment and return my reference count.
        i(R}(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytincrefscCs|jd|_|jS(s1Decrement and return my reference count.
        i(R}(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytdecrefsN(R,R-R.RkR3R~RR(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR|s
		tCopyableFailurecBseZdZdZdZRS(s}
    A L{flavors.RemoteCopy} and L{flavors.Copyable} version of
    L{twisted.python.failure.Failure} for serialization.
    icCs|jj}d|d<g|d<g|d<t|j|d<t|jtrb|j|d<ntj|j|d<|j	r|j
|d<n
d|d<|S(	s
        Collect state related to the exception which occurred, discarding
        state which cannot reasonably be serialized.
        RLtframeststackR7ttypet	tracebacksTraceback unavailable
N(t__dict__tcopyRktstrR7RyRRtqualtunsafeTracebackstgetTraceback(R6RX((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytgetStateToCopys


	
(R,R-R.RR(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRst
CopiedFailurecBs5eZdZddddZdZeZeZRS(s
    A L{CopiedFailure} is a L{pb.RemoteCopy} of a L{failure.Failure}
    transfered via PB.

    @ivar type: The full import path of the exception class which was raised on
        the remote end.
    @type type: C{str}

    @ivar value: A str() representation of the remote value.
    @type value: L{CopiedFailure} or C{str}

    @ivar traceback: The remote traceback.
    @type traceback: C{str}
    itdefaultcCsa|dkrtj}n|jd|j|j|j|jd|j|jddS(NsTraceback from remote host -- s: s
(RkRtlogfiletwriteRRR7(R6tfiletelideFrameworkCodetdetail((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRMs
cCs"|jt|j|j|jS(s
        Throw the original exception into the given generator, preserving
        traceback information if available. In the case of a L{CopiedFailure}
        where the exception type is a string, a L{pb.RemoteError} is thrown
        instead.

        @return: The next value yielded from the generator.
        @raise StopIteration: If there are no more values in the generator.
        @raise RemoteError: The wrapped remote exception.
        (tthrowR1RR7R(R6tg((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytthrowExceptionIntoGeneratorsN(R,R-R.RkRMRtprintBriefTracebacktprintDetailedTraceback(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRs
		
cCs"tjt|j}||_|S(N(ttypestInstanceTypeRRR(tfailRtf((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytfailure2Copyables	tBrokercBseZdZdZd0Zd0ZdedZdZ	dZ
dZdZdZ
d	Zd
ZdZdZd
Zd0ZdZdZdZdZdZdZdZdZdZdZddZdZdZ dZ!dZ"d0d0d0d0dZ#d0dZ$dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3d.Z4d/Z5RS(1sI am a broker for objects.
    iicCstjj||d|_g|_g|_g|_i|_||_g|_	d|_
d|_d|_
i|_i|_i|_i|_i|_i|_dS(Ni(RtBananaR3tdisconnectedtdisconnectstfailurestconnectstlocalObjectstsecurityt
pageProducerstcurrentRequestIDtcurrentLocalIDRkRqtluidstremotelyCachedObjectstremotelyCachedLUIDstlocallyCachedObjectstwaitingForAnswerst
_localCleanup(R6tisClientR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3s"															cCswxWtt|jdddD]6}|j|}|j|js |j|=q q W|jss|jjndS(sDCalled when the consumer attached to me runs out of buffer.
        iiN(txrangeReRtsendNextPagetstillPagingt	transporttunregisterProducer(R6tpageridxtpager((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytresumeProducing(s&

	cCsdS(N((R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytpauseProducing5scCsdS(N((R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
stopProducing8scCs?|jj|t|jdkr;|jj|dndS(Nii(RRdReRtregisterProducer(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytregisterPageProducer;scCsrt|tjrb|d}d|}t||d}|rO||dqn|jd|ntddS(s1Evaluate an expression as it's received.
        isproto_%sitdidNotUnderstandsNon-list expression received.N(RyRtListTypeRTRktsendCallR+(R6tsexptcommandt
methodNameRW((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytexpressionReceived@s

cCs/||jkr+td|j|fndS(sProtocol message: (version version-number)

        Check to make sure that both ends of the protocol are speaking
        the same version dialect.
        sVersion Incompatibility: %s %sN(tversionR+(R6tvnum((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
proto_versionOscGs|j|dS(sRUtility method to send an expression to the other side of the connection.
        N(tsendEncoded(R6texp((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRZscCstjd|dS(sRespond to stock 'C{didNotUnderstand}' message.

        Log the command that was not understood and continue. (Note:
        this will probably be changed to close the connection or raise
        an exception in the future.)
        sDidn't understand command: %rN(RRK(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytproto_didNotUnderstand_scCso|jd|jx0|jD]%}y|WqtjqXqWd|_|jrk|jj|ndS(s=Initialize. Called after Banana negotiation is done.
        RN(RRRRtdeferrRktfactorytclientConnectionMade(R6tnotifier((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytconnectionReadyhs		cCs@x0|jD]%}y|Wq
tjq
Xq
Wd|_dS(N(RRRRk(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytconnectionFaileduscCsLd|_d|_|jrlxN|jjD]:}y |jtjt|Wq+t	j
q+Xq+Wnx]|jjD]L}|j}|j
}y |j|t|||Wq|t	j
q|Xq|Wx1|jD]%}y|Wqt	j
qXqWd|_d|_d|_d|_d|_d|_d|_d|_dS(s!The connection was lost.
        iN(RRkRRtvaluesterrbackRtFailureRJRRRR]RCtstoppedObservingR#Rt
localSecuritytremoteSecurityRRR(R6treasontdtlobjt	cacheableRCR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytconnectionLosts8			 		 							cCs&t|st|jj|dS(s4Call the given callback when the Broker disconnects.N(RbRcRRd(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRfscCs&t|st|jj|dS(s7Call the given callback if the Broker fails to connect.N(RbRcRRd(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytnotifyOnFailscCsWt|st|jdkrCy|WqStjqSXn|jj|dS(s1Call the given callback when the Broker connects.N(RbRcRRkRterrRd(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytnotifyOnConnectscCs,y|jj|Wntk
r'nXdS(s4Remove a callback from list of disconnect callbacks.N(RRit
ValueError(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRjs
cCs)|jj|}|dkr"dS|jS(s
        Get a local object for a locally unique ID.

        @return: An object previously stored with L{registerReference} or
            C{None} if there is no object which corresponds to the given
            identifier.
        N(RtgetRkR](R6RDtlob((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytlocalObjectForIDsicCs|dk	st|j}|jj|}|dkrt|jtkr|jd|_|jdkr|j	j
tdntdn|j}t
||j|<||j|<n|j|j|S(sGet an ID for a local object.

        Store a persistent reference to a local object and map its id()
        to a generated, session-unique ID and return that ID.
        iis.Maximum PB reference count exceeded.  Goodbye.s$Maximum PB reference count exceeded.N(RkRctprocessUniqueIDRRReRtMAX_BROKER_REFStmaxBrokerRefsViolationsRtloseConnectionR0t
newLocalIDR|R(R6R]tpuidRD((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytregisterReferences
cCs)|dk	stt||j|<dS(sStore a special (string) ID for this object.

        This is how you specify a 'base' set of objects that the remote
        protocol can connect to.
        N(RkRcR|R(R6R:R]((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytsetNameForLocalscCstd||dS(sReturns an object from the remote name mapping.

        Note that this does not check the validity of the name, only
        creates a translucent reference for it.
        iN(R_Rk(R6R:((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
remoteForNamescCsH|j}|jj|}|dk	rD|rD|j|jn|S(sbReturns an ID that says what this instance is cached as remotely, or C{None} if it's not.
        N(RRRRkRR(R6tinstanceRRRD((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytcachedRemotelyAss
cCs|j|jS(sFReturns an instance which is cached remotely, with this LUID.
        (RR](R6RD((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytremotelyCachedForLUIDscCs|j}|j}t|jtkrw|jd|_|jdkrh|jjtdntdn||j	|<t
||j|j|<|S(s
        XXXiis*Maximum PB cache count exceeded.  Goodbye.s Maximum PB cache count exceeded.(RRReRRRRRR0RR|tserializingPerspective(R6RRRD((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
cacheRemotely	s

cCs||j|<dS(sL(internal)

        Store a non-filled-out cached instance locally.
        N(R(R6tcidR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytcacheLocallyscCs|j|}|S(N(R(R6RR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytcachedLocallyAs#s
cCst|tjrN|j|jddi|d6|d6|d6|d6|S||_||_||_||_zt	||j
d|SWdd|_d|_d|_d|_XdS(sPJelly an object according to the remote security rules for this broker.
        cSs|S(N((tx((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt<lambda>,stcallbackKeywordsRCRWRERFN(RyRtDeferredtaddCallbacksRVRtjellyMethodt	jellyArgstjellyKwRRRk(R6R]RCRWRERF((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRV's$								cCs4||_zt||jd|SWdd|_XdS(sOUnjelly an sexp according to the local security rules for this broker.
        N(RqRRRk(R6RRC((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRSHs	cCs|jd|_|jS(sGenerate a new LUID.
        i(R(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRRscCs|jd|_|jS(s#Generate a new request ID.
        i(R(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytnewRequestIDXsc
Csd}d}d}	|jdr5|d}|d=n|jdrX|d}|d=n|jdr|ru|std|d}	|d=n|jrtdny:|j|d|d|}
|j|d|d|}Wntjtj	SX|j
}|	r[tj}
|
|j|<|s8|rat
jd	|
j||qand}
|j|d
||||	|
||
S(Nit
pbcallbackt	pberrbacktpbanswers*You can't specify a no-answer requirement.sCalling Stale BrokerRCRWs&warning! using deprecated "pbcallback"RO(Rkthas_keyRcRR/RVRRRRRRRRRKRR(R6tprefixRCtobjectIDRORERFtpbctpbetanswerRequiredtnetArgstnetKwt	requestIDtrval((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRB^s<





	

#cCs&|j|j||||||dS(N(t_recvMessageR(R6RRRORRR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
proto_messagescCs&|j|j||||||dS(N(RR(R6RRRORRR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytproto_cachemessagesc
CsQyC||}|dkr*tdn|j||||}	Wntk
r}
|rMt|
ts|jj|
jr|j|
|q|jt	|
|qMn|rt
jddtt	}|j||nt
j
nZX|rMt|	tjr:|f}|	j|j|jd|d|qM|j|	|ndS(sReceived a message-send.

        Look up message based on object, unserialize the arguments, and
        invoke it with args, and send an 'answer' or 'error' response.
        sInvalid Object IDs)Peer will receive following PB traceback:tisErrortcallbackArgsterrbackArgsN(RkR0R\RyRRtisClassAllowedt	__class__t
_sendErrorRRRKtTrueRRRRt_sendAnswert_sendFailureOrError(
R6t
findObjMethodRRRORRRR]t	netResultteRRE((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRs,$		cCs|jd||dS(s@(internal) Send an answer to a previously sent message.
        tanswerN(R(R6RR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRscCs1|j|}|j|=|j|j|dS(sv(internal) Got an answer to a previously sent message.

        Look up the appropriate callback and call it.
        N(RRhRS(R6RRR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytproto_answers

cCs<|jtdkr(|j||n|j||dS(s
        Call L{_sendError} or L{_sendFailure}, depending on whether C{fail}
        represents an L{Error} subclass or not.
        N(tcheckR0Rkt_sendFailureR(R6RR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRscCs.tjdtj||j||dS(sLog error and then send it.s)Peer will receive following PB traceback:N(RRKRR(R6RR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRs

cCst|tjrrt|jts<|jj|jjrH|j}qrt|tsrt	||j
j}qrnt|tr|j
j|_n|jd||j
|dS(s@(internal) Send an error for a previously sent message.
        terrorN(RyRRR7RRRRRRRRRRV(R6RR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRscCs1|j|}|j|=|j|j|dS(s'(internal) Deal with an error.
        N(RRRS(R6RRR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytproto_errors

cCs|jd|dS(s,(internal) Send a DECREF directive.
        RN(R(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRzscCsi|j|j}|dkre|j|jj}|j|=|j|=|jj|dndS(s(internal) Decrement the reference count of an object.

        If the reference count is zero, it will free the reference to this
        object.
        icSsdS(N(Rk(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRsN(RRR]RRRtpop(R6RtrefsR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytproto_decrefs

cCs|jd|dS(s-(internal) Send a DECACHE directive.
        tdecacheN(R(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytdecCacheRefscCs|j|j}|dkr|j|}|j}|j}y |j|t|||WntjnX|j}|j	|=|j|=|j
d|ndS(s(internal) Decrement the reference count of a cached object.

        If the reference count is zero, free the reference, then send an
        'uncached' directive.
        ituncacheN(RRR]RCRR#RRRRR(R6RRRRRCR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
proto_decaches
		 

cCs$|j|}d|_|j|=dS(sF(internal) Tell the client it is now OK to uncache an object.
        N(RRkRA(R6RR9((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
proto_uncaches
	N(6R,R-R.RRktusernameRRR3RRRRRRRRRRRRRfRRRjRRRRRRRRRRRVRSRRRBR	R
RRRRRRRRzRR!R#R$(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRsd'	
									
			$					
				
				!
			!			*										cCsUt}|j||j}t}|j||j||j}|S(sWRespond to a challenge.

    This is useful for challenge/response authentication.
    (Rtupdatetdigest(t	challengetpasswordtmthashedPasswordtdoubleHashedPassword((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytrespond)s	
	

cCs[d}x<ttjddD]"}|ttjdd}qWt|j}|S(sI return some random data.R@iiiAiZ(trangetrandomt	randrangetchrtrandintRR'(tcrapR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR(7s
 tPBClientFactorycBseZdZeZeZeedZdZ	dZ
dZdZddZ
dZd	Zd
ZdZdZd
ZddZRS(s
    Client factory for PB brokers.

    As with all client factories, use with reactor.connectTCP/SSL/etc..
    getPerspective and getRootObject can be called either before or
    after the connect.
    cCs ||_||_|jdS(sE
        @param unsafeTracebacks: if set, tracebacks for exceptions will be sent
            over the wire.
        @type unsafeTracebacks: C{bool}

        @param security: security options used by the broker, default to
            C{globalSecurity}.
        @type security: L{twisted.spread.jelly.SecurityOptions}
        N(RRt_reset(R6RR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3Ls
		cCs(|jdtd|j}||_|S(sP
        Build the broker instance, passing the security options to it.
        RR(R	RRR(R6taddrtp((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
buildProtocol[s	cCsg|_d|_d|_dS(N(trootObjectRequestsRkt_brokert_root(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR5ds		cCs5|j}|jx|D]}|j|qWdS(N(R9R5R(R6Rt	deferredsR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt_failAllis	

cCs|j|dS(N(R=(R6t	connectorR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytclientConnectionFailedosicCs,|rd|_d|_n
|j|dS(s8Reconnecting subclasses should call with reconnecting=1.N(RkR:R;R=(R6R>Rtreconnecting((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytclientConnectionLostrs	cCsR||_|jd|_|j}g|_x|D]}|j|jq4WdS(Ntroot(R:RR;R9Rh(R6RAtdsR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR|s			
cCsF|jr&|jjr&tj|jStj}|jj||S(s\Get root object of remote PB server.

        @return: Deferred of the root object.
        (R:RRtsucceedR;RR9Rd(R6R((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
getRootObjects
cCs |jr|jjjndS(sIf the factory is connected, close the connection.

        Note that if you set up the factory to reconnect, you will need to
        implement extra logic to prevent automatic reconnection after this
        is called.
        N(R:RR(R6((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
disconnects	cCs"|jd|j|j||S(Ntlogin(RvtaddCallbackt_cbResponse(R6RBR%R)tclient((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt_cbSendUsernamescCs(|\}}|jdt|||S(NR-(RvR-(R6t.1R)RJR(t
challenger((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRIs	cCs|jd|S(sb
        Attempt an anonymous login on the given remote root object.

        @type root: L{RemoteReference}
        @param root: The object on which to attempt the login, most likely
            returned by a call to L{PBClientFactory.getRootObject}.

        @param client: A jellyable object which will be used as the I{mind}
            parameter for the login attempt.

        @rtype: L{Deferred}
        @return: A L{Deferred} which will be called back with a
            L{RemoteReference} to an avatar when anonymous login succeeds, or
            which will errback if anonymous login fails.
        tloginAnonymous(Rv(R6RBRJ((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt_cbLoginAnonymousscCsT|j}tj|r1|j|j|n|j|j|j|j||S(s
        Login and get perspective from remote PB server.

        Currently the following credentials are supported::

            L{twisted.cred.credentials.IUsernamePassword}
            L{twisted.cred.credentials.IAnonymous}

        @rtype: L{Deferred}
        @return: A L{Deferred} which will be called back with a
            L{RemoteReference} for the avatar logged in to, or which will
            errback if login fails.
        (RERt
providedByRHRORKR%R)(R6tcredentialsRJR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRGs
N(R,R-R.RR	tFalseRRR3R8R5R=R?RARRERFRKRIRORkRG(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR4@s 					
			
			tPBServerFactorycBs;eZdZeZeZeedZdZ	dZ
RS(s
    Server factory for perspective broker.

    Login is done using a Portal object, whose realm is expected to return
    avatars implementing IPerspective. The credential checkers in the portal
    should accept IUsernameHashedPassword or IUsernameMD5Password.

    Alternatively, any object providing or adaptable to L{IPBRoot} can be
    used instead of a portal to provide the root object of the PB server.
    cCs%t||_||_||_dS(s
        @param root: factory providing the root Referenceable used by the broker.
        @type root: object providing or adaptable to L{IPBRoot}.

        @param unsafeTracebacks: if set, tracebacks for exceptions will be sent
            over the wire.
        @type unsafeTracebacks: C{bool}

        @param security: security options used by the broker, default to
            C{globalSecurity}.
        @type security: L{twisted.spread.jelly.SecurityOptions}
        N(RRBRR(R6RBRR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3s
	cCsD|jdtd|j}||_|jd|jj||S(sT
        Return a Broker attached to the factory (as the service provider).
        RRRB(R	RRRRRRBt
rootObject(R6R6tproto((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR8s	cCsdS(N((R6R	((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRs(R,R-R.RRRRR	RR3R8R(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRSs
		tIUsernameMD5PasswordcBs eZdZdZdZRS(sb
    I encapsulate a username and a hashed password.

    This credential is used for username/password over PB. CredentialCheckers
    which check this kind of credential must store the passwords in plaintext
    form or as a MD5 digest.

    @type username: C{str} or C{Deferred}
    @ivar username: The username associated with these credentials.
    cCsdS(s
        Validate these credentials against the correct password.

        @type password: C{str}
        @param password: The correct, plaintext password against which to
            check.

        @rtype: C{bool} or L{Deferred}
        @return: C{True} if the credentials represented by this object match the
            given password, C{False} if they do not, or a L{Deferred} which will
            be called back with one of these values.
        N((R)((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt
checkPasswordscCsdS(s
        Validate these credentials against the correct MD5 digest of the
        password.

        @type password: C{str}
        @param password: The correct MD5 digest of a password against which to
            check.

        @rtype: C{bool} or L{Deferred}
        @return: C{True} if the credentials represented by this object match the
            given digest, C{False} if they do not, or a L{Deferred} which will
            be called back with one of these values.
        N((R)((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytcheckMD5Passwords(R,R-R.RWRX(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRVs
	t_PortalRootcBs*eZdZeedZdZRS(s%Root object, used to login to portal.cCs
||_dS(N(tportal(R6RZ((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3.scCst|j|S(N(t_PortalWrapperRZ(R6RA((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRT1s(R,R-R.RRR3RT(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRY)s
	t_JellyableAvatarMixincBseZdZdZRS(sk
    Helper class for code which deals with avatars which PB must be capable of
    sending to a peer.
    csx|\}}tj|s0t|d}n|j}gfd}||jj|<|jj||S(s
        Ensure that the avatar to be returned to the client is jellyable and
        set up disconnection notification to call the realm's logout object.
        RCcs&s
dSd}d=|dS(Ni((tfn(tlogout(s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytmaybeLogoutKs

(RRPRYRRARRf(R6RLt	interfacetavatarR^RR_((R^s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt_cbLogin=s	(R,R-R.Rb(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR\8sR[cBs)eZdZdZdZdZRS(s=
    Root Referenceable object, used to login to portal.
    cCs||_||_dS(N(RZRA(R6RZRA((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3]s	cCs(t}|t|j|j||fS(s3
        Start of username/password login.
        (R(t_PortalAuthChallengerRZRA(R6R%tc((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytremote_loginbs	cCs/|jjt|t}|j|j|S(sU
        Attempt an anonymous login.

        @param mind: An object to use as the mind parameter to the portal login
            call (possibly None).

        @rtype: L{Deferred}
        @return: A Deferred which will be called back with an avatar when login
            succeeds or which will be errbacked if login fails somehow.
        (RZRGRRNRHRb(R6tmindR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytremote_loginAnonymousjs(R,R-R.R3ReRg(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR[Xs		RccBs?eZdZeeedZdZdZdZ	RS(s5
    Called with response to password challenge.
    cCs(||_||_||_||_dS(N(RZRAR%R((R6RZRAR%R(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyR3s			cCs5||_|jj||t}|j|j|S(N(tresponseRZRGRNRHRb(R6RhRfR((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pytremote_responds	cCs|jt|jS(N(RXRR'(R6R)((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRWscCs?t}|j||j|j|j}|j|kS(N(RR&R(R'Rh(R6tmd5Passwordtmdtcorrect((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRXs
	
(
R,R-R.RR
RVR3RiRWRX(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyRc{s
			RRRRRRRRRR R!R"R#R$R%R&R'R(R)R*RtportnoRR-R((_R.R/Rtzope.interfaceRRttwisted.pythonRRRttwisted.python.versionsRttwisted.python.deprecateRttwisted.python.hashlibRttwisted.internetRR	ttwisted.cred.portalR
ttwisted.cred.credentialsRRR
Rttwisted.persistedRttwisted.python.componentsRttwisted.spread.interfacesRRttwisted.spread.jellyRRRttwisted.spreadRttwisted.spread.flavorsRRRRRRRRRR R!R"R#R$R%R&R'R(R)R*RRmR2R+R/R0R1R8RHRJRMRNRRRYt	EphemeralR_R|RRRRRRR-R(t
ClientFactoryR4t
ServerFactoryRSRVRYR\R[Rct__all__(((s5/usr/lib/python2.7/dist-packages/twisted/spread/pb.pyt<module>s	!	!*+n
)
2			1* #$