[Twisted-Python] perspective argument missing from Viewable.view_*
Flint
grindizer at gmail.com
Mon Nov 18 03:14:12 MST 2013
Hi Daniel.
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.
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.
>From the code you gave clients are not "identifyed", my guess is this is
why you get None.
--
Nacim
2013/11/18 Daniel Sank <sank.daniel at gmail.com>
> I'm trying to understand exactly how context management works in
> perspective broker. I thought the point of Viewable was that you
> always know who's calling. However if I run the simple fully working
> example pasted below, I see that the perspective argument is None.
> What gives?
>
> Kind regards,
> Daniel Sank
>
> # Server
>
> import twisted.spread.pb as pb
> import twisted.internet.reactor as reactor
>
> class Server(pb.Root):
> def __init__(self):
> self.v = MyViewable()
>
> def remote_getViewable(self):
> return self.v
>
> class MyViewable(pb.Viewable):
> def view_foo(self, perspective):
> print ("Perspective %s"%perspective)
>
>
> if __name__ == "__main__":
> reactor.listenTCP(54321, pb.PBServerFactory(Server()))
> print("Starting reactor")
> reactor.run()
>
> # Client
>
> import twisted.spread.pb as pb
> import twisted.internet.reactor as reactor
> from twisted.internet.defer import inlineCallbacks
>
> @inlineCallbacks
> def gotRoot(root):
> v1 = yield root.callRemote("getViewable")
> v2 = yield root.callRemote("getViewable")
> print(v1)
> print(v2)
> yield v1.callRemote("foo")
> yield v2.callRemote("foo")
>
> factory = pb.PBClientFactory()
> reactor.connectTCP("localhost", 54321, factory)
> d = factory.getRootObject()
> d.addCallback(gotRoot)
> reactor.run()
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20131118/14886f86/attachment-0002.html>
More information about the Twisted-Python
mailing list