1   
 2   
 3   
 4   
 5   
 6   
 7   
 8   
 9   
10   
11   
12   
13   
14   
15   
16  from twisted.spread import pb 
17  from twisted.python import log 
18  from twisted.spread.interfaces import IJellyable 
19   
21      log.msg("Applying patch for http://twistedmatrix.com/trac/ticket/5079") 
22      if not hasattr(pb, '_JellyableAvatarMixin'): 
23          log.msg("..patch not applicable; please file a bug at buildbot.net") 
24      else: 
25          pb._JellyableAvatarMixin._cbLogin = _fixed_cbLogin 
 26   
27 -def _fixed_cbLogin(self, (interface, avatar, logout)): 
 28      """ 
29      Ensure that the avatar to be returned to the client is jellyable and 
30      set up disconnection notification to call the realm's logout object. 
31      """ 
32      if not IJellyable.providedBy(avatar): 
33          avatar = pb.AsReferenceable(avatar, "perspective") 
34   
35      puid = avatar.processUniqueID() 
36   
37       
38       
39       
40      logout = [ logout ] 
41      def maybeLogout(): 
42          if not logout: return 
43          fn = logout[0] 
44          del logout[0] 
45          fn() 
 46      self.broker._localCleanup[puid] = maybeLogout 
47      self.broker.notifyOnDisconnect(maybeLogout) 
48   
49      return avatar 
50