[Twisted-Python] Perspective / Client confusion
Patrick K. O'Brien
pobrien at orbtech.com
Fri May 30 06:04:33 MDT 2003
On Friday 30 May 2003 02:36 am, Luc Stepniewski wrote:
> On Friday 30 May 2003 02:55, Patrick K. O'Brien wrote:
> > This is working so far:
> >
> > identity = auth.createIdentity('root')
> > identity.setPassword('password')
> > identity.save()
> >
> > perspective = AdminPerspective(identity)
> > service.addPerspective(perspective)
> > identity.addKeyForPerspective(perspective)
> >
> > perspective = UserPerspective(identity)
> > service.addPerspective(perspective)
> > identity.addKeyForPerspective(perspective)
>
> If you do this, when the user root/password will log on, how will twisted
> know to which perspective to connect to? How will it differenciate your
> connection as adminperspective or userperpective, as you log as the same
> user/pass?
If you look at twisted.spread.pb you'll see that the pb.connect() function
takes both a username (same as identity.name) and perspectiveName as
parameters:
def connect(host, port, username, password, serviceName,
perspectiveName=None, client=None, timeout=None):
"""Connects and authenticates, then retrieves a PB service.
Required arguments:
- host -- the host the service is running on
- port -- the port on the host to connect to
- username -- the name you will be identified as to the authorizer
- password -- the password for this username
- serviceName -- name of the service to request
Optional (keyword) arguments:
- perspectiveName -- the name of the perspective to request, if
different than the username
- client -- XXX the \"reference\" argument to
perspective.Perspective.attached
- timeout -- see twisted.internet.tcp.Client
@returns: A Deferred instance that gets a callback when the final
Perspective is connected, and an errback when an error
occurs at any stage of connecting.
"""
So my demo/hack client application supplies those details when a user logs on:
def main(self):
name = raw_input('Enter your login name (root): ')
if not name:
name = 'root'
password = raw_input('Enter your password (password): ')
if not password:
password = 'password'
perspective = raw_input('Enter your perspective (root:admin): ')
if not perspective:
perspective = 'root:admin'
df = pb.connect(host='localhost',
port=8789,
username=name,
password=password,
serviceName='BankingService',
perspectiveName=perspective,
client=self,
timeout=30)
df.addCallbacks(self.gotPerspective, self.noPerspective)
reactor.run()
--
Patrick K. O'Brien
Orbtech http://www.orbtech.com/web/pobrien
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------
More information about the Twisted-Python
mailing list