[Twisted-Python] Perspective / Client confusion

Patrick K. O'Brien pobrien at orbtech.com
Thu May 29 20:55:51 EDT 2003


On Thursday 29 May 2003 07:03 pm, Patrick K. O'Brien wrote:
> Itamar suggested that the best approach would be to have one service,
> several Perspective subclasses, and one Perspective instance for each
> client.  So now I think I need to override the service.createPerspective()
> to create the right kind of Perspective instance, or create the Perspective
> independently and then send it to service.addPerspective().  It also seems
> to me that I should hide the Perspective details such that when a user logs
> in they simply choose which of their perspectives they want to use (admin,
> user, customer, for example).  It also seems to me that I should generate
> the perspective names automatically, in order to keep them unique within
> the service (something like identity.name + perspective.__class__.__name__,
> perhaps).

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)

    application.run()

The init for my base Perspective class looks like this:

    def __init__(self, identity):
        """Create a Perspective for the identity."""
        if not isinstance(identity, auth.identityClass):
            raise TypeError("Expected identity instance, got %s." % identity)
        perspectiveName = identity.name + ':' + self.__class__.__name__
        pb.Perspective.__init__(self, perspectiveName, identity.name)

-- 
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