
    hh                     :   S r SSKrSSKJr  SSKJrJr  SSKJrJ	r	J
r
Jr  SSKJr  SSKJrJr  SSKJr  SS	KJrJrJr  SS
KJrJr  SSKJr  SSKJr  SSKJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2  SSK3J4r4J5r5  SSK6J7r7J8r8J9r9J:r:  Sr;Sr< " S S\=5      r> " S S\>5      r? " S S\=5      r@ " S S\=5      rA\ " S S5      5       rB " S S\=5      rC " S S\5      rD\" \D5       " S  S!5      5       rE " S" S#\$5      rF\" \55      \ " S$ S%\)\R                  5      5       5       rH\1" S&\H5         " S' S(5      rI " S) S*\R                  \ 5      rK " S+ S,\'\R                  5      rL\1" \K\L5        SAS- jrM " S. S/\R                  5      rOS0 rPS1 rQ " S2 S3\R                  5      rS " S4 S5\R                  5      rU " S6 S7\
5      rV\" \!5       " S8 S95      5       rW\" \W\\!5         " S: S;5      rX " S< S=\$\X5      rY\" \\V5       " S> S?\$\X5      5       rZ/ S@Qr[g)Ba  
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 similarly, 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
    N)md5)	Interfaceimplementer)	Anonymous
IAnonymousICredentialsIUsernameHashedPassword)Portal)deferprotocol)styles)failurelogreflect)cmp
comparable)registerAdapter)banana)	CacheableCopyableIPBRoot	JellyableNoSuchMethodReferenceableRemoteCacheRemoteCacheObserver
RemoteCopyRootSerializableViewable	ViewPointcopyTagssetCopierForClasssetCopierForClassTreesetFactoryForClasssetUnjellyableFactoryForClasssetUnjellyableForClasssetUnjellyableForClassTree)
IJellyableIUnjellyable)_newInstanceglobalSecurityjellyunjellyi   iS"  c                       \ rS rSrSrSrg)ProtocolErrorT   zF
This error is raised when an invalid protocol statement is received.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r2       X/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/spread/pb.pyr0   r0   T   s    r:   r0   c                       \ rS rSrSrSrg)DeadReferenceErrorZ   zl
This error is raised when a method is called on a dead reference (one whose
broker has been disconnected).
r2   Nr3   r2   r:   r;   r=   r=   Z   s    r:   r=   c                       \ rS rSrSrSrg)Errora   a  
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.
r2   Nr3   r2   r:   r;   r@   r@   a   s    r:   r@   c                       \ rS rSrSrS rSrg)RemoteErrorl   aR  
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.
c                 F    [         R                  X5        Xl        X0l        g N)	Exception__init__
remoteTyperemoteTraceback)selfrI   valuerJ   s       r;   rH   RemoteError.__init__   s    4'$.r:   )rJ   rI   Nr4   r5   r6   r7   r8   rH   r9   r2   r:   r;   rC   rC   l   s    &/r:   rC   c                   0    \ rS rSrSrS rS rS rS rSr	g)	RemoteMethod   z6
This is a translucent reference to a remote message.
c                     Xl         X l        g)zD
Initialize with a L{RemoteReference} and the name of this message.
N)objname)rK   rS   rT   s      r;   rH   RemoteMethod.__init__   s     	r:   c                 F    [        U R                  U R                  4U5      $ rF   )r   rS   rT   rK   others     r;   __cmp__RemoteMethod.__cmp__   s    DHHdii(%00r:   c                 D    [        U R                  U R                  45      $ rF   )hashrS   rT   rK   s    r;   __hash__RemoteMethod.__hash__   s    TXXtyy)**r:   c                     U R                   R                  R                  SU R                   R                  U R                   R                  U R
                  R                  S5      UU5      $ )z(
Asynchronously invoke a remote method.
r:   utf-8)rS   broker_sendMessageperspectiveluidrT   encode)rK   argskws      r;   __call__RemoteMethod.__call__   sR     xx++HH  HHMMIIW%
 	
r:   )rT   rS   N)
r4   r5   r6   r7   r8   rH   rY   r^   ri   r9   r2   r:   r;   rP   rP      s    1+
r:   rP   c                       \ rS rSrSrg)PBConnectionLost   r2   N)r4   r5   r6   r7   r9   r2   r:   r;   rl   rl      s    r:   rl   c                       \ rS rSrSrS rSrg)IPerspective   a  
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.
c                     g)a  
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.
Nr2   )rb   messagerg   kwargss       r;   perspectiveMessageReceived'IPerspective.perspectiveMessageReceived       r:   r2   Nr4   r5   r6   r7   r8   rt   r9   r2   r:   r;   ro   ro      s    r:   ro   c                       \ rS rSrSrS rSrg)Avatar   a  
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}.)
c                     UR                  X05      nUR                  X@5      n[        U SU-  5      n U" U0 UD6nUR                  X`XSU5      $ ! [         a     [        R                  " U SU SU 35        e f = f)a1  
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.
zperspective_%sz didn't accept z and )unserializegetattr	TypeErrorr   msg	serialize)rK   rb   rr   rg   rh   methodstates          r;   rt   !Avatar.perspectiveMessageReceived   s     !!$-)/'9:	D'B'E V2>>  	GGvhodV5=>	s   A *A8r2   Nrw   r2   r:   r;   ry   ry      s    ?r:   ry   c                   "    \ rS rSrSrSS jrSrg)AsReferenceable   z.
A reference directed towards another object.
c                 *    [        XS-   5      U l        g )NMessageReceived)r}   remoteMessageReceived)rK   objectmessageTypes      r;   rH   AsReferenceable.__init__  s    %,VCT5T%U"r:   )r   N)remoterN   r2   r:   r;   r   r      s    Vr:   r   c                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)RemoteReferencei  a-  
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} implementer (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}
c                 B    X0l         X l        X@l        Xl        / U l        g)z(internal) Initialize me with a broker and a locally-unique ID.

The ID is unique only to the particular Perspective Broker
instance.
N)re   rb   
doRefCountrd   disconnectCallbacks)rK   rd   rb   re   r   s        r;   rH   RemoteReference.__init__  s!     	$&#% r:   c                     [        U5      (       d   eU R                  R                  U5        [        U R                  5      S:X  a&  U R                  R                  U R                  5        gg)z
Register a callback to be called if our broker gets disconnected.

@param callback: a callable which will be called with one
                 argument, this instance.
   N)callabler   appendlenrb   notifyOnDisconnect_disconnectedrK   callbacks     r;   r   "RemoteReference.notifyOnDisconnect'  sY     !!!!  ''1t''(A-KK**4+=+=> .r:   c                     U R                   R                  U5        U R                   (       d&  U R                  R                  U R                  5        gg)z]
Remove a callback that was registered with notifyOnDisconnect.

@param callback: a callable
N)r   removerb   dontNotifyOnDisconnectr   r   s     r;   r   &RemoteReference.dontNotifyOnDisconnect3  s>     	  ''1''KK..t/A/AB (r:   c                 H    U R                    H  nU" U 5        M     SU l         g)z>
Called if we are disconnected and have callbacks registered.
N)r   r   s     r;   r   RemoteReference._disconnected=  s#     00HTN 1#' r:   c                     UR                   (       a/  U R                  UR                   :X  d   S5       eSU R                  4$ g)zS
If I am being sent back to where I came from, serialize as a local backreference.
z6Can't send references to brokers other than their own.s   local)s   unpersistablezReferences cannot be serialized)invokerrb   re   )rK   jelliers     r;   jellyForRemoteReference.jellyForE  s?     ??w.HGH.TYY&&Fr:   c                 p    U R                  UR                  R                  UR                  US   S5        U $ )Nr   )rH   r   unserializingPerspective)rK   	unjellierunjellyLists      r;   
unjellyForRemoteReference.unjellyForQ  s7    66N		
 r:   c                     [        U[        5      (       d  UR                  S5      nU R                  R	                  SU R
                  U R                  XU5      $ )a  
Asynchronously invoke a remote method.

@type _name: L{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.
utf8r:   )
isinstancebytesrf   rb   rc   rd   re   )rK   _namerg   rh   s       r;   
callRemoteRemoteReference.callRemoteZ  sM     %''LL(E
 {{''!!499e2
 	
r:   c                     [        X5      $ )z@

@param key: The key.
@return: A L{RemoteMethod} for this key.
)rP   )rK   keys     r;   remoteMethodRemoteReference.remoteMethodp  s     D&&r:   c                     [        U[        5      (       a:  UR                  U R                  :X  a   [        U R                  UR                  5      $ [        U R                  U5      $ )z=

@param other: another L{RemoteReference} to compare me to.
)r   r   rb   r   re   rW   s     r;   rY   RemoteReference.__cmp__x  sG    
 e_--||t{{*499ejj114;;&&r:   c                     U R                   $ )z

Hash me.
)re   r]   s    r;   r^   RemoteReference.__hash__  s     yyr:   c                 r    U R                   (       a&  U R                  R                  U R                  5        gg)z4
Do distributed reference counting on finalization.
N)r   rb   
sendDecRefre   r]   s    r;   __del__RemoteReference.__del__  s&     ??KK""499- r:   )rb   r   r   re   rd   N)r4   r5   r6   r7   r8   rH   r   r   r   r   r   r   r   rY   r^   r   r9   r2   r:   r;   r   r     s@    $
&
?C(
G
,''.r:   r   r   c                   <    \ rS rSrSrS
S jrS\4S jrS rS r	S	r
g)Locali  z+
(internal) A reference to a local object.
Nc                 *    Xl         X l        SU l        g)z
Initialize.
r   Nr   rd   refcount)rK   r   rd   s      r;   rH   Local.__init__  s     &r:   returnc                 >    SU R                   < SU R                   S3$ )Nz
<pb.Local z ref:>)r   r   r]   s    r;   __repr__Local.__repr__  s    DKK?%a@@r:   c                 B    U R                   S-   U l         U R                   $ )zQ
Increment the reference count.

@return: the reference count after incrementing
r   r   r]   s    r;   increfLocal.incref       )}}r:   c                 B    U R                   S-
  U l         U R                   $ )zQ
Decrement the reference count.

@return: the reference count after decrementing
r   r   r]   s    r;   decrefLocal.decref  r   r:   r   rF   )r4   r5   r6   r7   r8   rH   strr   r   r   r9   r2   r:   r;   r   r     s$    A# Ar:   r   c                   "    \ rS rSrSrSrS rSrg)CopyableFailurei  zq
A L{flavors.RemoteCopy} and L{flavors.Copyable} version of
L{twisted.python.failure.Failure} for serialization.
r   c                    U R                   nU R                  R                  5       nUR                  S5      US'   SUS'   / US'   / US'   [	        U R
                  5      US'   [        U R                  [        5      (       a  U R                  US'   O2[        R                  " U R                  5      R                  S	5      US'   U R                  (       a  U R                  5       US
'   U$ SUS
'   U$ )zp
Collect state related to the exception which occurred, discarding
state which cannot reasonably be serialized.
_parentsparentsNtbframesstackrL   typera   	tracebackzTraceback unavailable
)r   __dict__copypopr   rL   r   r   r   r   qualrf   unsafeTracebacksgetTraceback)rK   _r   s      r;   getStateToCopyCopyableFailure.getStateToCopy  s     LL""$ 99Z0idhgTZZgdii'' IIE&M#LL3::7CE&M  !%!2!2!4E+  ";E+r:   r2   N)r4   r5   r6   r7   r8   r   r   r9   r2   r:   r;   r   r     s    
 r:   r   c                   D   ^  \ rS rSrSrU 4S jrSS jrS r\r\r	Sr
U =r$ )CopiedFailurei  al  
A L{CopiedFailure} is a L{pb.RemoteCopy} of a L{failure.Failure}
transferred 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}
c                 J   > UR                  S5      US'   [        TU ]	  U5      $ )Nr   r   )r   supersetCopyableState)rK   r   	__class__s     r;   r   CopiedFailure.setCopyableState  s&    !IIi0jw'..r:   c                    Uc  [         R                  nU R                  n[        U[        5      (       d  UR                  S5      nUR                  S5        UR                  US-   U R                  -   5        UR                  S5        g )Nra   zTraceback from remote host -- z: 
)r   logfiler   r   r   decodewriterL   )rK   fileelideFrameworkCodedetailfailureTypes        r;   printTracebackCopiedFailure.printTraceback  si    <;;Dii+s++%,,W5K

34

;%

23

4r:   c                 v    UR                  [        U R                  U R                  U R                  5      5      $ )a  
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.
)throwrC   r   rL   r   )rK   gs     r;   throwExceptionIntoGenerator)CopiedFailure.throwExceptionIntoGenerator  s(     ww{499djj$..IJJr:   r2   )Nr   default)r4   r5   r6   r7   r8   r   r   r   printBriefTracebackprintDetailedTracebackr9   __classcell__)r   s   @r;   r   r     s&    /K )+r:   r   c                 N    [        [        U R                  5       5      nXl        U$ rF   )r+   r   __getstate__r   )failr   fs      r;   failure2Copyabler  
  s"    _d&7&7&9:A)Hr:   c                   H   \ rS rSrSrSrSrSrS\4S jr	S r
S rS	 rS
 rS rS rS rS rS rS rSrS rS rS rS rS rS rSrS rS rS rS4S jrS r S r!S r"S r#S5S  jr$S6S! jr%S" r&S# r'S$ r(S% r)S& r*S' r+S( r,S) r-S* r.S+ r/S, r0S- r1S. r2S/ r3S0 r4S1 r5S2 r6S3r7g)7Brokeri  z
I am a broker for objects.
   Nr   c                     [         R                  R                  X5        SU l        / U l        / U l        / U l        0 U l        X l        / U l	        SU l
        SU l        S U l        0 U l        0 U l        0 U l        0 U l        0 U l        0 U l        g Nr   )r   BananarH   disconnecteddisconnectsfailuresconnectslocalObjectssecuritypageProducerscurrentRequestIDcurrentLocalIDr   luidsremotelyCachedObjectsremotelyCachedLUIDslocallyCachedObjectswaitingForAnswers_localCleanup)rK   isClientr  s      r;   rH   Broker.__init__  s    t.  !(,% 
 &("#% $&!!#
  r:   c                 6   [        [        U R                  5      S-
  SS5       HF  nU R                  U   nUR                  5         UR	                  5       (       a  M9  U R                  U	 MH     U R                  (       d  U R
                  R                  5         gg)z=
Called when the consumer attached to me runs out of buffer.
r   N)ranger   r  sendNextPagestillPaging	transportunregisterProducer)rK   pageridxpagers      r;   resumeProducingBroker.resumeProducing?  s    
 c$"4"4592rBH&&x0E $$&&&&x0	 C
 !!NN--/ "r:   c                     g rF   r2   r]   s    r;   pauseProducingBroker.pauseProducingL      r:   c                     g rF   r2   r]   s    r;   stopProducingBroker.stopProducingP  r.  r:   c                     U R                   R                  U5        [        U R                   5      S:X  a  U R                  R	                  U S5        g g )Nr   r   )r  r   r   r%  registerProducer)rK   r(  s     r;   registerPageProducerBroker.registerPageProducerT  sB    !!%(t!!"a'NN++D!4 (r:   c                     [        U[        5      (       a_  US   n[        U[        5      (       d  UR                  S5      nSU-  n[	        XS5      nU(       a	  U" USS 6   gU R                  SU5        g[        S5      e)z*
Evaluate an expression as it's received.
r   r   zproto_%sNr   s   didNotUnderstandzNon-list expression received.)r   listr   r   r}   sendCallr0   )rK   sexpcommand
methodNamer   s        r;   expressionReceivedBroker.expressionReceivedY  sw     dD!!1gGgs++!..0#g-JTt4FQR!17; ?@@r:   c                 X    XR                   :w  a  [        SU R                    SU 35      eg)z
Protocol message: (version version-number)

Check to make sure that both ends of the protocol are speaking
the same version dialect.

@param vnum: The version number.
zVersion Incompatibility:  N)versionr0   )rK   vnums     r;   proto_versionBroker.proto_versionm  s0     <<";DLL>4& QRR  r:   c                 &    U R                  U5        g)zh
Utility method to send an expression to the other side of the connection.

@param exp: The expression.
N)sendEncoded)rK   exps     r;   r8  Broker.sendCallz  s     	r:   c                 6    [         R                  " SU-  5        g)z
Respond 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.)

@param command: The command to log.
zDidn't understand command: %rN)r   r   )rK   r:  s     r;   proto_didNotUnderstandBroker.proto_didNotUnderstand  s     	/'9:r:   c                    U R                  SU R                  5        U R                   H  n U" 5         M     SU l        U R                  R                  U 5        g! [         a    [        R
                  " 5          MT  f = f)z6
Initialize. Called after Banana negotiation is done.
s   versionN)r8  r@  r  BaseExceptionr   deferrfactoryclientConnectionMaderK   notifiers     r;   connectionReadyBroker.connectionReady  sc     	j$,,/H
 &
 ))$/ ! 

s   AA>=A>c                     U R                    H  n U" 5         M     S U l         g ! [         a    [        R                  " 5          M9  f = frF   )r  rL  r   rM  rP  s     r;   connectionFailedBroker.connectionFailed  s=    H
 &
  ! 

s   $AAc           	          SU l         SU l        U R                  (       aP  U R                  R                  5        H2  n UR	                  [
        R                  " [        U5      5      5        M4     U R                  R                  5        H8  nUR                  nUR                  n UR                  U[        XU5      5        M:     U R                   SS  H  n U" 5         M     SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        g! [         a    [        R                  " 5          GM  f = f! [         a    [        R                  " 5          M  f = f! [         a    [        R                  " 5          M  f = f)zO
The connection was lost.

@param reason: message to put in L{failure.Failure}
r   N)r  r  r  valueserrbackr   Failurerl   rL  r   rM  r  r   rd   stoppedObservingr   r  localSecurityremoteSecurityr  r  r  )rK   reasondlobj	cacheablerd   rQ  s          r;   connectionLostBroker.connectionLost  sU    
!!++224!IIgoo.>v.FGH 5 ..557DI**K**!4Tk!R	 8 ((+H
 ,
  !%!"%)"#' $(! 5 % !JJLL! ! 

 ! 

s5   .D&EE*E EE'&E'*FFc                 ^    [        U5      (       d   eU R                  R                  U5        g)zA

@param notifier: callback to call when the Broker disconnects.
N)r   r  r   rP  s     r;   r   Broker.notifyOnDisconnect  s)    
 !!!!)r:   c                 ^    [        U5      (       d   eU R                  R                  U5        g)zD

@param notifier: callback to call if the Broker fails to connect.
N)r   r  r   rP  s     r;   notifyOnFailBroker.notifyOnFail  s'    
 !!!!X&r:   c                     [        U5      (       d   eU R                  c	   U" 5         gU R                  R                  U5        g! [         a    [        R                  " 5          gf = f)z>

@param notifier: callback to call when the Broker connects.
N)r   r  rL  r   errr   rP  s     r;   notifyOnConnectBroker.notifyOnConnect  sW    
 !!!!== 
 MM  * ! 	s   A A'&A'c                 \     U R                   R                  U5        g! [         a     gf = f)zI

@param notifier: callback to remove from list of disconnect callbacks.
N)r  r   
ValueErrorrP  s     r;   r   Broker.dontNotifyOnDisconnect  s-    
	##H- 		s    
++c                     [        U[        5      (       a  UR                  S5      nU R                  R	                  U5      nUc  gUR
                  $ )z
Get a local object for a locally unique ID.

@return: An object previously stored with L{registerReference} or
    L{None} if there is no object which corresponds to the given
    identifier.
r   N)r   r   rf   r  getr   )rK   re   lobs      r;   localObjectForIDBroker.localObjectForID  sG     dC  ;;v&D##D);zzr:   r   c                    Uc   eUR                  5       nU R                  R                  U5      nUc  [        U R                  5      [
        :  aT  U R                  S-   U l        U R                  S:  a%  U R                  R                  5         [        S5      e[        S5      eU R                  5       n[        U5      U R                  U'   X0R                  U'   U$ U R                  U   R                  5         U$ )z
Store a persistent reference to a local object and map its
id() to a generated, session-unique ID.

@param object: a local object
@return: the generated ID
r      z.Maximum PB reference count exceeded.  Goodbye.z$Maximum PB reference count exceeded.)processUniqueIDr  rq  r   r  MAX_BROKER_REFSmaxBrokerRefsViolationsr%  loseConnectionr@   
newLocalIDr   r   )rK   r   puidre   s       r;   registerReferenceBroker.registerReference	  s     !!!%%'zz~~d#<4$$%7/3/K/Ka/O,//!3NN113 STTBCC??$D&+FmDd##JJt  d#**,r:   c                     [        U[        5      (       a  UR                  S5      nUc   e[        U5      U R                  U'   g)z
Store a special (string) ID for this object.

This is how you specify a 'base' set of objects that the remote
protocol can connect to.

@param name: An ID.
@param object: The object.
r   N)r   r   rf   r   r  )rK   rT   r   s      r;   setNameForLocalBroker.setNameForLocal$  s?     dC  ;;v&D!!!"'-$r:   c                 h    [        U[        5      (       a  UR                  S5      n[        SXS5      $ )z
Returns 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.

@param name: The name to look up.
@return: An object which maps to the name.
r   Nr   )r   r   rf   r   )rK   rT   s     r;   remoteForNameBroker.remoteForName4  s.     dC  ;;v&DtT33r:   c                     UR                  5       nU R                  R                  U5      nUb$  U(       a  U R                  U   R	                  5         U$ )z

@param instance: The instance to look up.
@param incref: Flag to specify whether to increment the
               reference.
@return: An ID that says what this instance is cached as
         remotely, or L{None} if it's not.
)rw  r  rq  r  r   )rK   instancer   r|  re   s        r;   cachedRemotelyAsBroker.cachedRemotelyAsC  sL     '')''++D16&&t,335r:   c                 4    U R                   U   R                  $ )zS

@param luid: The LUID to look up.
@return: An instance which is cached remotely.
)r  r   )rK   re   s     r;   remotelyCachedForLUIDBroker.remotelyCachedForLUIDS  s     ))$/666r:   c                    UR                  5       nU R                  5       n[        U R                  5      [        :  aT  U R
                  S-   U l        U R
                  S:  a%  U R                  R                  5         [        S5      e[        S5      eX0R                  U'   [        XR                  5      U R                  U'   U$ )z
XXX

@return: A new LUID.
r   rv  z*Maximum PB cache count exceeded.  Goodbye.z Maximum PB cache count exceeded.)rw  r{  r   r  rx  ry  r%  rz  r@   r  r   serializingPerspective)rK   r  r|  re   s       r;   cacheRemotelyBroker.cacheRemotely[  s     '') t))*_<+/+G+G!+KD(++a/--/KLL:;;)-  & ,1;V;V+W""4(r:   c                      X R                   U'   g)z<(internal)

Store a non-filled-out cached instance locally.
Nr  rK   cidr  s      r;   cacheLocallyBroker.cacheLocallyp  s    
 *2!!#&r:   c                 $    U R                   U   nU$ rF   r  r  s      r;   cachedLocallyAsBroker.cachedLocallyAsw  s    ,,S1r:   c           	      `   [        U[        R                  5      (       a#  UR                  U R                  S UUUUS.S9  U$ X l        X0l        X@l        XPl         [        XR                  SU 5      SU l        SU l        SU l        SU l        $ ! SU l        SU l        SU l        SU l        f = f)z
Jelly an object according to the remote security rules for this broker.

@param object: The object to jelly.
@param perspective: The perspective.
@param method: The method.
@param args: Arguments.
@param kw: Keyword arguments.
c                     U $ rF   r2   )xs    r;   <lambda>"Broker.serialize.<locals>.<lambda>  s    !r:   )rd   r   rg   rh   )callbackKeywordsN)r   r   DeferredaddCallbacksr   r  jellyMethod	jellyArgsjellyKwr-   r  )rK   r   rd   r   rg   rh   s         r;   r   Broker.serialize{  s     fenn--#.$ 	"   	 M '2#!	 d;*.D'#D!DNDL +/D'#D!DNDLs   B B-c                 d    X l          [        XR                  SU 5      SU l         $ ! SU l         f = f)z
Unjelly an sexp according to the local security rules for this broker.

@param sexp: The object to unjelly.
@param perspective: The perspective.
N)r   r.   r  )rK   r9  rd   s      r;   r|   Broker.unserialize  s0     )4%	14d;,0D)DD)s   & 	/c                 B    U R                   S-   U l         U R                   $ )z#

@return: A newly generated LUID.
r   )r  r]   s    r;   r{  Broker.newLocalID  s#    
 #11A5"""r:   c                 B    U R                   S-   U l         U R                   $ )z)

@return: A newly generated request ID.
r   )r  r]   s    r;   newRequestIDBroker.newRequestID  s#    
 !% 5 5 9$$$r:   c           	         S nS nSn	SU;   a  US   nUS	 SU;   a  US   nUS	 SU;   a  U(       d  U(       a   S5       eUS   n	US	 U R                   (       a  [        S5      e U R                  XRUS9n
U R                  XbUS9nU R                  5       nU	(       aY  [        R                  " 5       nXR                  U'   U(       d  U(       a'  [        R                  " S5        UR                  Xx5        OS nU R                  US	-   UUUU	U
U5        U$ ! [         a,    [        R
                  " [        R                  " 5       5      s $ f = f)
Nr   
pbcallback	pberrbackpbanswerz*You can't specify a no-answer requirement.zCalling Stale Broker)rd   r   z&warning! using deprecated "pbcallback"s   message)r  r=   r   rL  r   r  r   rZ  r  r  r  r   r   r  r8  )rK   prefixrd   objectIDrr   rg   rh   pbcpbeanswerRequirednetArgsnetKw	requestIDrvals                 r;   rc   Broker._sendMessage  sQ   2\"C< "[/C;cX,XX*
^N:$%;<<	1nnT7nSGNN2wNOE %%'	>>#D04""9-c@A!!#+DZ	
 )  	1::goo/00	1s   # D 3EEc           	      F    U R                  U R                  UUUUUU5        g rF   )_recvMessagers  rK   r  r  rr   r  r  r  s          r;   proto_messageBroker.proto_message  s-     	!!	
r:   c           	      F    U R                  U R                  UUUUUU5        g rF   )r  r  r  s          r;   proto_cachemessageBroker.proto_cachemessage  s-     	  	
r:   c                 :   [        U[        5      (       d  UR                  S5      n U" U5      nUc  [        S5      eUR	                  XXg5      n	U(       a[  [        U	[
        R                  5      (       a*  U4n
U	R                  U R                  U R                  U
U
S9  gU R                  X5        gg! [         a  nU(       au  [        U[        5      (       d*  U R                  R                  UR                  5      (       a  U R                  X5         SnAgU R                  [        U5      U5         SnAg SnAgSnAf[          aO    U(       a0  ["        R$                  " SSS9  [        5       nU R                  X5        ["        R&                  " 5          gf = f)a  
Received a message-send.

Look up message based on object, unserialize the arguments, and
invoke it with args, and send an 'answer' or 'error' response.

@param findObjMethod: A callable which takes C{objectID} as argument.
@param requestID: The requiest ID.
@param objectID: The object ID.
@param message: The message.
@param answerRequired:
@param netArgs: Arguments.
@param netKw: Keyword arguments.
r   NzInvalid Object ID)callbackArgserrbackArgs)Peer will receive following PB traceback:T)isError)r   r   r   r@   r   r   r  r  _sendAnswer_sendFailureOrErrorr   r  isClassAllowedr   
_sendErrorr   rL  r   r   rj  )rK   findObjMethodr  r  rr   r  r  r  r   	netResultrg   er  s                r;   r  Broker._recvMessage  sU   0 '3''nnV,G%	;"8,F~/0044TGSI, i88%<D**((00%)$(	 +  $$Y: +  	C a++t}}/K/KKK0 0 OOA11OOOA$6	BB   	CTR#%-GGI	s%   (B3 3
F=AD>D>>AFFc                 (    U R                  SX!5        g)zz
(internal) Send an answer to a previously sent message.

@param netResult: The answer.
@param requestID: The request ID.
s   answerNr8  )rK   r  r  s      r;   r  Broker._sendAnswerH  s     	i6r:   c                 |    U R                   U   nU R                   U	 UR                  U R                  U5      5        g)z
(internal) Got an answer to a previously sent message.

Look up the appropriate callback and call it.

@param requestID: The request ID.
@param netResult: The answer.
N)r  r   r|   )rK   r  r  r_  s       r;   proto_answerBroker.proto_answerQ  s9     ""9-""9-	

4##I./r:   c                 v    UR                  [        5      c  U R                  X5        gU R                  X5        g)z
Call L{_sendError} or L{_sendFailure}, depending on whether C{fail}
represents an L{Error} subclass or not.

@param fail: The failure.
@param requestID: The request ID.
N)checkr@   _sendFailurer  rK   r  r  s      r;   r  Broker._sendFailureOrError^  s-     ::e$d.OOD,r:   c                 ~    [         R                  " S5        [         R                  " U5        U R                  X5        g)zZ
Log error and then send it.

@param fail: The failure.
@param requestID: The request ID.
r  N)r   r   rj  r  r  s      r;   r  Broker._sendFailurek  s(     	;<(r:   c                    [        U[        R                  5      (       a  [        UR                  [        5      (       d4  U R
                  R                  UR                  R                  5      (       a  UR                  nO4[        U[        5      (       d  [        XR                  R                  5      n[        U[        5      (       a  U R                  R                  Ul        U R                  SX R                  U5      5        g)zv
(internal) Send an error for a previously sent message.

@param fail: The failure.
@param requestID: The request ID.
s   errorN)r   r   rZ  rL   r   r  r  r   r   r  rN  r   r8  r   r  s      r;   r  Broker._sendErrorv  s     dGOO,, $**i00DMM4P4P

$$5 5 zzo66'll.K.KLdO,,$(LL$A$AD!h	>>$+?@r:   c                 |    U R                   U   nU R                   U	 UR                  U R                  U5      5        g)z]
(internal) Deal with an error.

@param requestID: The request ID.
@param fail: The failure.
N)r  rY  r|   )rK   r  r  r_  s       r;   proto_errorBroker.proto_error  s9     ""9-""9-			$""4()r:   c                 (    U R                  SU5        g)zF
(internal) Send a DECREF directive.

@param objectID: The object ID.
s   decrefNr  rK   r  s     r;   r   Broker.sendDecRef  s     	i*r:   c                 ^   [        U[        5      (       a  UR                  S5      nU R                  U   R	                  5       nUS:X  ad  U R                  U   R
                  R                  5       nU R                  U	 U R                  U	 U R                  R                  US 5      " 5         gg)z
(internal) Decrement the reference count of an object.

If the reference count is zero, it will free the reference to this
object.

@param objectID: The object ID.
r   r   c                      g rF   r2   r2   r:   r;   r  %Broker.proto_decref.<locals>.<lambda>  s    r:   N)
r   r   rf   r  r   r   rw  r  r  r   )rK   r  refsr|  s       r;   proto_decrefBroker.proto_decref  s     h$$v.H  *11319$$X.55EEGD

4 !!(+""468	 r:   c                 (    U R                  SU5        g)zG
(internal) Send a DECACHE directive.

@param objectID: The object ID.
s   decacheNr  r  s     r;   decCacheRefBroker.decCacheRef  s     	j(+r:   c                    U R                   U   R                  5       nUS:X  a  U R                   U   nUR                  nUR                  n UR	                  U[        XU5      5        UR                  5       nU R                  U	 U R                   U	 U R                  SU5        gg! [         a    [        R                  " 5          N_f = f)z
(internal) Decrement the reference count of a cached object.

If the reference count is zero, free the reference, then send an
'uncached' directive.

@param objectID: The object ID.
r   s   uncacheN)r  r   r   rd   r[  r   rL  r   rM  rw  r  r8  )rK   r  r  r`  ra  rd   r|  s          r;   proto_decacheBroker.proto_decache  s     ))(3::<19--h7DI**K**!4Tk!R
 ,,.D((.**84MM*h/  ! 

s   B& &CCc                 J    U R                   U   nSUl        U R                   U	 g)z`
(internal) Tell the client it is now OK to uncache an object.

@param objectID: The object ID.
N)r  rb   )rK   r  rS   s      r;   proto_uncacheBroker.proto_uncache  s+     ''1
 %%h/r:   )r  r  r  r  r  r  r  r  r  r  r  r\  r  r  ry  r  r]  r  r  r  r  r   r  r   )NNNNrF   )8r4   r5   r6   r7   r8   r@  usernamerN  r,   rH   r)  r,  r0  r4  r<  rB  r8  rI  rR  rU  r  rb  r   rg  rk  r   rs  ry  r}  r  r  r  r  r  r  r  r   r|   r{  r  rc   r  r  r  r  r  r  r  r  r  r   r  r  r  r  r9   r2   r:   r;   r
  r
    s    GHG !N $ L05
A(S
;0 '!R*'+   60 4 7*2( T1#%'R

@;D70-	)A(	*+9$,080r:   r
  c                     [        5       nUR                  U5        UR                  5       n[        5       nUR                  U5        UR                  U 5        UR                  5       nU$ )z
Respond to a challenge.

This is useful for challenge/response authentication.

@param challenge: A challenge.
@param password: A password.
@return: The password hashed twice.
)r   updatedigest)	challengepasswordmhashedPassworddoubleHashedPasswords        r;   respondr    sS     	AHHXXXZNAHH^HHY88:r:   c            	          [        S [        [        R                  " SS5      5       5       5      n [	        U 5      R                  5       n U $ )z

@return: Some random data.
c              3   P   #    U  H  n[         R                  " S S5      v   M     g7f)A   r>   N)randomrandint).0r  s     r;   	<genexpr>challenge.<locals>.<genexpr>  s      Q1PAB''1Ps   $&      )r   r"  r  	randranger   r  )craps    r;   r  r    s=    
 Qv7G7GB7O1PQQDt9DKr:   c                   ~    \ rS rSrSr\rSrS\4S jr	S r
S rS rS rSS	 jrS
 rS rS rS rS rS rSS jrSrg)PBClientFactoryi   z
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.
Fc                 <    Xl         X l        U R                  5         g)a  
@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)r   r  _reset)rK   r   r  s      r;   rH   PBClientFactory.__init__  s     !1 r:   c                 F    U R                  SU R                  S9nXl        U$ )z@
Build the broker instance, passing the security options to it.
Tr  r  )r   r  rN  )rK   addrps      r;   buildProtocolPBClientFactory.buildProtocol  s$     MM4$--M@	r:   c                 .    / U l         S U l        S U l        g rF   )rootObjectRequests_broker_rootr]   s    r;   r  PBClientFactory._reset"  s    "$
r:   c                 p    U R                   nU R                  5         U H  nUR                  U5        M     g rF   )r  r  rY  )rK   r^  	deferredsr_  s       r;   _failAllPBClientFactory._failAll'  s,    ++	AIIf r:   c                 &    U R                  U5        g rF   )r  )rK   	connectorr^  s      r;   clientConnectionFailed&PBClientFactory.clientConnectionFailed-  s    fr:   c                 R    U(       a  SU l         SU l        gU R                  U5        g)z:
Reconnecting subclasses should call with reconnecting=1.
N)r  r  r  )rK   r  r^  reconnectings       r;   clientConnectionLost$PBClientFactory.clientConnectionLost0  s#       DLDJMM&!r:   c                     Xl         UR                  S5      U l        U R                  n/ U l        U H  nUR	                  U R                  5        M      g )Nroot)r  r  r  r  r   )rK   rb   dsr_  s       r;   rO  $PBClientFactory.clientConnectionMade<  sF    ))&1
$$"$AJJtzz" r:   c                     U R                   (       a;  U R                   R                  (       d   [        R                  " U R                  5      $ [        R
                  " 5       nU R                  R                  U5        U$ )zM
Get root object of remote PB server.

@return: Deferred of the root object.
)r  r  r   succeedr  r  r  r   )rK   r_  s     r;   getRootObjectPBClientFactory.getRootObjectD  sO     << 9 9==,,NN&&q)r:   c                 p    U R                   (       a%  U R                   R                  R                  5         gg)z
If 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  r%  rz  r]   s    r;   
disconnectPBClientFactory.disconnectP  s&     <<LL""113 r:   c                 Z    UR                  SU5      R                  U R                  X45      $ )Nlogin)r   addCallback_cbResponse)rK   r'  r  r  clients        r;   _cbSendUsernamePBClientFactory._cbSendUsername[  s+    w1==h
 	
r:   c                 B    Uu  pEUR                  S[        XB5      U5      $ )Nr  )r   r  )rK   
challengesr  r5  r  
challengers         r;   r4  PBClientFactory._cbResponse`  s$     *	$$Y	0LfUUr:   c                 &    UR                  SU5      $ )a
  
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.
loginAnonymous)r   )rK   r'  r5  s      r;   _cbLoginAnonymous!PBClientFactory._cbLoginAnonymousd  s      /88r:   Nc                     U R                  5       n[        R                  " U5      (       a  UR                  U R                  U5        U$ UR                  U R
                  UR                  UR                  U5        U$ )ap  
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.
)r,  r   
providedByr3  r>  r6  r  r  )rK   credentialsr5  r_  s       r;   r2  PBClientFactory.loginv  so        --MM$00&9
  MM$$k&:&:K<P<PRX r:   )r  r  r  r  r   r  rF   )r4   r5   r6   r7   r8   r
  r   r   r,   rH   r  r  r  r   r$  rO  r,  r/  r6  r4  r>  r2  r9   r2   r:   r;   r  r     s[     H(- 

"#
	4

V9$r:   r  c                   :    \ rS rSrSrSr\rS\4S jr	S r
S rSrg)	PBServerFactoryi  a  
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.
Fc                 <    [        U5      U l        X l        X0l        g)a  
@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)r   r'  r   r  )rK   r'  r   r  s       r;   rH   PBServerFactory.__init__  s     DM	 0 r:   c                     U R                  SU R                  S9nXl        UR                  SU R                  R                  U5      5        U$ )zD
Return a Broker attached to the factory (as the service provider).
Fr  r'  )r   r  rN  r  r'  
rootObject)rK   r  protos      r;   r  PBServerFactory.buildProtocol  sC     ut}}Efdii&:&:5&ABr:   c                     g rF   r2   )rK   r   s     r;   rO  $PBServerFactory.clientConnectionMade  r.  r:   )r'  r  r   N)r4   r5   r6   r7   r8   r   r
  r   r,   rH   r  rO  r9   r2   r:   r;   rE  rE    s*    	  H.3n !"r:   rE  c                   $    \ rS rSrSrS rS rSrg)IUsernameMD5Passwordi  aF  
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.
c                     g)a~  
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.
Nr2   r  s    r;   checkPassword"IUsernameMD5Password.checkPassword  rv   r:   c                     g)a  
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.
Nr2   rQ  s    r;   checkMD5Password%IUsernameMD5Password.checkMD5Password  rv   r:   r2   N)r4   r5   r6   r7   r8   rR  rU  r9   r2   r:   r;   rO  rO    s    	r:   rO  c                   $    \ rS rSrSrS rS rSrg)_PortalRooti  z'
Root object, used to login to portal.
c                     Xl         g rF   portal)rK   r[  s     r;   rH   _PortalRoot.__init__  s    r:   c                 .    [        U R                  U5      $ rF   )_PortalWrapperr[  )rK   rb   s     r;   rI  _PortalRoot.rootObject  s    dkk622r:   rZ  N)r4   r5   r6   r7   r8   rH   rI  r9   r2   r:   r;   rX  rX    s    3r:   rX  c                       \ rS rSrSrS rSrg)_JellyableAvatarMixini  z_
Helper class for code which deals with avatars which PB must be capable of
sending to a peer.
c                    ^ Uu  p#m[         R                  " U5      (       d  [        US5      nUR                  5       nT/mU4S jnXPR                  R
                  U'   U R                  R                  U5        U$ )z
Ensure that the avatar to be returned to the client is jellyable and
set up disconnection notification to call the realm's logout object.
rd   c                  4   > T(       d  g TS   n TS	 U " 5         g r  r2   )fnlogouts    r;   maybeLogout3_JellyableAvatarMixin._cbLogin.<locals>.maybeLogout  s    Bq	Dr:   )r)   rA  r   rw  rb   r  r   )rK   result	interfaceavatarr|  rf  re  s         @r;   _cbLogin_JellyableAvatarMixin._cbLogin  ss    
 '-#F$$V,,$V];F%%'
 	 +6!!$'&&{3r:   r2   N)r4   r5   r6   r7   r8   rk  r9   r2   r:   r;   ra  ra    s    
r:   ra  c                   *    \ rS rSrSrS rS rS rSrg)r^  i  z5
Root Referenceable object, used to login to portal.
c                     Xl         X l        g rF   )r[  rb   )rK   r[  rb   s      r;   rH   _PortalWrapper.__init__!  s    r:   c                 \    [        5       nU[        U R                  U R                  X5      4$ )zC
Start of username/password login.

@param username: The username.
)r  _PortalAuthChallengerr[  rb   )rK   r  cs      r;   remote_login_PortalWrapper.remote_login%  s(     K'T[[(NNNr:   c                     U R                   R                  [        5       U[        5      nUR	                  U R
                  5        U$ )a  
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.
)r[  r2  r   ro   r3  rk  )rK   mindr_  s      r;   remote_loginAnonymous$_PortalWrapper.remote_loginAnonymous.  s3     KKik4>	dmm$r:   )rb   r[  N)	r4   r5   r6   r7   r8   rH   rs  rw  r9   r2   r:   r;   r^  r^    s    Or:   r^  c                   0    \ rS rSrSrS rS rS rS rSr	g)	rq  i>  z-
Called with response to password challenge.
c                 4    Xl         X l        X0l        X@l        g rF   )r[  rb   r  r  )rK   r[  rb   r  r  s        r;   rH   _PortalAuthChallenger.__init__D  s     "r:   c                     Xl         U R                  R                  X[        5      nUR	                  U R
                  5        U$ rF   )responser[  r2  ro   r3  rk  )rK   r}  rv  r_  s       r;   remote_respond$_PortalAuthChallenger.remote_respondJ  s2     KKd,7	dmm$r:   c                 R    U R                  [        U5      R                  5       5      $ )zo
L{IUsernameHashedPassword}

@param password: The password.
@return: L{_PortalAuthChallenger.checkMD5Password}
)rU  r   r  )rK   r  s     r;   rR  #_PortalAuthChallenger.checkPasswordP  s"     $$S]%9%9%;<<r:   c                     [        5       nUR                  U5        UR                  U R                  5        UR                  5       nU R                  U:H  $ )zd
L{IUsernameMD5Password}

@param md5Password:
@rtype: L{bool}
@return: L{True} if password matches.
)r   r  r  r  r}  )rK   md5Passwordmdcorrects       r;   rU  &_PortalAuthChallenger.checkMD5PasswordY  sA     U
		+
		$..!))+}}''r:   )rb   r  r[  r}  r  N)
r4   r5   r6   r7   r8   rH   r~  rR  rU  r9   r2   r:   r;   rq  rq  >  s    #=(r:   rq  )(r   r   r   r   r   r!   r    r   r   r   r   r   r   r"   r'   r&   r(   r#   r%   r$   rx  portnor0   r=   r@   rl   rP   ro   ry   r   r   r   r   r  r
  r  r  r  rE  rO  r  )\r8   r  hashlibr   zope.interfacer   r   twisted.cred.credentialsr   r   r   r	   twisted.cred.portalr
   twisted.internetr   r   twisted.persistedr   twisted.pythonr   r   r   twisted.python.compatr   r   twisted.python.componentsr   twisted.spreadr   twisted.spread.flavorsr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   twisted.spread.interfacesr)   r*   twisted.spread.jellyr+   r,   r-   r.   rx  r  rG   r0   r=   r@   rC   rP   rl   ro   ry   r   	Ephemeralr   r   rZ  r   r   r  r  r
  r  r  ClientFactoryr  ServerFactoryrE  rO  rX  ra  r^  rq  __all__r2   r:   r;   <module>r     sH  
4   1  ' , $ 1 0 1 5 !     , ? M M	I  I /) /4 
 
 
@	y 	&9 &R \%? %? %?PVm V \E.lF$4$4 E.  E.P x 1   Hgoox B,,J ,,^  6O0V]] O0d (Lh,, L^-h,, -`'< 'T W	3 	3 	3 VW -   F]$9 D $&:;&(M+@ &( <&(R*r:   