~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/howto/listings/pb/pb6server.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

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