~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to doc/core/howto/listings/pb/pb6server.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-01-16 19:56:10 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060116195610-ykmxbia4mnnod9o2
Tags: 2.1.0-0ubuntu2
debian/copyright: Include copyright for python 2.3; some 2.3 files
are included in the upstream tarball, but not in the binary packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
2
 
 
3
 
from twisted.spread import pb
4
 
from twisted.cred import checkers, portal
5
 
from twisted.internet import reactor
6
 
 
7
 
class MyPerspective(pb.Avatar):
8
 
    def __init__(self, name):
9
 
        self.name = name
10
 
    def perspective_foo(self, arg):
11
 
        print "I am", self.name, "perspective_foo(",arg,") called on", self
12
 
 
13
 
class MyRealm:
14
 
    __implements__ = portal.IRealm
15
 
    def requestAvatar(self, avatarId, mind, *interfaces):
16
 
        if pb.IPerspective not in interfaces:
17
 
            raise NotImplementedError
18
 
        return pb.IPerspective, MyPerspective(avatarId), lambda:None
19
 
 
20
 
p = portal.Portal(MyRealm())
21
 
c = checkers.InMemoryUsernamePasswordDatabaseDontUse(user1="pass1", 
22
 
                                                     user2="pass2")
23
 
p.registerChecker(c)
24
 
reactor.listenTCP(8800, pb.PBServerFactory(p))
25
 
reactor.run()