<div dir="ltr"><div><div>Hi Daniel.<br><br></div>To get the perspective you have to implements the IPerspective interface (generally throw subclassing pb.Avatar class), and attach a login portal to your server.<br>Client then have to authenticate to the server, only then you will receive the perspective object representing the "logged" user into your view_ and perspective_ method.<br>
<br></div><div>From the code you gave clients are not "identifyed", my guess is this is why you get None.<br><br></div><div>--<br></div><div>Nacim<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2013/11/18 Daniel Sank <span dir="ltr"><<a href="mailto:sank.daniel@gmail.com" target="_blank">sank.daniel@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm trying to understand exactly how context management works in<br>
perspective broker. I thought the point of Viewable was that you<br>
always know who's calling. However if I run the simple fully working<br>
example pasted below, I see that the perspective argument is None.<br>
What gives?<br>
<br>
Kind regards,<br>
Daniel Sank<br>
<br>
# Server<br>
<br>
import twisted.spread.pb as pb<br>
import twisted.internet.reactor as reactor<br>
<br>
class Server(pb.Root):<br>
    def __init__(self):<br>
        self.v = MyViewable()<br>
<br>
    def remote_getViewable(self):<br>
        return self.v<br>
<br>
class MyViewable(pb.Viewable):<br>
    def view_foo(self, perspective):<br>
        print ("Perspective %s"%perspective)<br>
<br>
<br>
if __name__ == "__main__":<br>
    reactor.listenTCP(54321, pb.PBServerFactory(Server()))<br>
    print("Starting reactor")<br>
    reactor.run()<br>
<br>
# Client<br>
<br>
import twisted.spread.pb as pb<br>
import twisted.internet.reactor as reactor<br>
from twisted.internet.defer import inlineCallbacks<br>
<br>
@inlineCallbacks<br>
def gotRoot(root):<br>
    v1 = yield root.callRemote("getViewable")<br>
    v2 = yield root.callRemote("getViewable")<br>
    print(v1)<br>
    print(v2)<br>
    yield v1.callRemote("foo")<br>
    yield v2.callRemote("foo")<br>
<br>
factory = pb.PBClientFactory()<br>
reactor.connectTCP("localhost", 54321, factory)<br>
d = factory.getRootObject()<br>
d.addCallback(gotRoot)<br>
reactor.run()<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br></div>