import Pyro.core sys.path.insert(0,os.path.join(os.pardir,os.pardir)) # to find testserver.py import testserver Pyro.config.PYRO_MOBILE_CODE=1 # Enable mobile code class MallObj(Pyro.core.ObjBase): def __init__(self): Pyro.core.ObjBase.__init__(self) def goShopping(self, shopper): print "shop2 goshopping:",shopper shopper.visit("Shop 2") try: shop2=Pyro.core.getProxyForURI("PYRONAME://Shop3") except Exception,x: print "ERROR FINDING SHOP 3!!",x else: shopper=shop2.goShopping(shopper) # hop to next shop return shopper def __call__(self): return self # hack for testserver's delegation init mall=MallObj() # finally, start the server. testserver.start(mall,'Shop2')
# So create a subclass from ObjBase and our Mall. class MallObj(Pyro.core.ObjBase, shop.Mall): def __init__(self): Pyro.core.ObjBase.__init__(self) shop.Mall.__init__(self) mall = MallObj() mall.addShop(s1) mall.addShop(s2) mall.addShop(s3) mall.addShop(s4) def codeValidator(n, m, a): # This codevalidator only accepts ShoppingAgent uploads # and object.* downloads. # As an example, to accept all modules in the agent package: # change it to return n.startswith('agent.') if m and a: return n == 'agent.ShoppingAgent' # client uploads to us else: return n.startswith("objects.") # client downloads from us # set a custom codeValidator because the default validator # will accept ALL incoming code (HAZARDOUS). mall.setCodeValidator(codeValidator) # finally, start the server. testserver.start(mall, 'ShoppingMall')
#!/usr/bin/env python import sys, os sys.path.insert(0, os.pardir) # to find testserver.py import testserver import Pyro.core ######## testclass object class testclass(object): def transfer(self, data): print 'received', len(data), 'bytes' return len(data) ######## main program testserver.start(testclass, 'hugetransfer', delegate=1)
import Pyro.core, Pyro.util ######## object that does the callbacks class CallbackThing(Pyro.core.ObjBase): def __init__(self): Pyro.core.ObjBase.__init__(self) self.clients = [] def register(self, client): print 'REGISTER', client self.clients.append(client) #client._setOneway('callback') # don't wait for results for this method def shout(self, message): print 'Got shout:', message # let it know to all clients! for c in self.clients[:]: # use a copy of the list try: c.callback('Somebody shouted: ' + message) # oneway call except Pyro.errors.ConnectionClosedError, x: # connection dropped, remove the listener if it's still there # check for existence because other thread may have killed it already if c in self.clients: self.clients.remove(c) print 'Removed dead listener', c ######## main program testserver.start(CallbackThing, 'callback')
import testserver ######## testclass object (subclassed from ObjBase) class testclass(Pyro.core.ObjBase): def __init__(self): Pyro.core.ObjBase.__init__(self) self.sum = 0 self.changedby = '' # the following only works because Person is in a separate module # that is also available to the client: self.person = Person("Irmen de Jong", "30") ######## testclass object (standalone - delegate approach) class testclass2(object): def __init__(self): self.sum = 0 self.changedby = '' # the following only works because Person is in a separate module # that is also available to the client: self.person = Person("Irmen de Jong", "30") ######## main program testserver.start(testclass, 'attributes')
#!/usr/bin/env python import sys, os sys.path.insert(0, os.pardir) # to find testserver.py import testserver import Pyro.core Pyro.config.PYRO_MULTITHREADING = 0 import bench class benchimpl(Pyro.core.ObjBase, bench.bench): def __init__(self): Pyro.core.ObjBase.__init__(self) ######## main program testserver.start(benchimpl, 'benchmark')
#!/usr/bin/env python import sys, os sys.path.insert(0, os.pardir) # to find testserver.py import testserver import Pyro.core ######## testclass object class testclass(object): def setname(self, name): self.name = name def getname(self): return self.name ######## main program Pyro.core.initServer() Pyro.config.PYRO_TRACELEVEL = 3 Pyro.config.PYRO_LOGFILE = 'server_log' Pyro.config.PYRO_MAXCONNECTIONS = 10 print 'Reduced max number of simultaneous connections to 10' print 'Check the logfile for messages: server_log' testserver.start(testclass, 'maxclients', delegate=1)
import Pyro.core sys.path.insert(0,os.path.join(os.pardir,os.pardir)) # to find testserver.py import testserver Pyro.config.PYRO_MOBILE_CODE=1 # Enable mobile code class MallObj(Pyro.core.ObjBase): def __init__(self): Pyro.core.ObjBase.__init__(self) def goShopping(self, shopper): print "shop1 goshopping:",shopper shopper.visit("Shop 1") try: shop2=Pyro.core.getProxyForURI("PYRONAME://Shop2") except Exception,x: print "ERROR FINDING SHOP 2!!",x else: shopper=shop2.goShopping(shopper) # hop to next shop return shopper def __call__(self): return self # hack for testserver's delegation init mall=MallObj() # finally, start the server. testserver.start(mall,'Shop1')
class MallObj(Pyro.core.ObjBase, shop.Mall): def __init__(self): Pyro.core.ObjBase.__init__(self) shop.Mall.__init__(self) mall = MallObj() mall.addShop(s1) mall.addShop(s2) mall.addShop(s3) mall.addShop(s4) def codeValidator(n, m, a): # This codevalidator only accepts ShoppingAgent uploads # and object.* downloads. # As an example, to accept all modules in the agent package: # change it to return n.startswith('agent.') if m and a: return n == 'agent.ShoppingAgent' # client uploads to us else: return n.startswith("objects.") # client downloads from us # set a custom codeValidator because the default validator # will accept ALL incoming code (HAZARDOUS). mall.setCodeValidator(codeValidator) # finally, start the server. testserver.start(mall, 'ShoppingMall')
import testserver ######## testclass object (subclassed from ObjBase) class testclass(Pyro.core.ObjBase): def __init__(self): Pyro.core.ObjBase.__init__(self) self.sum=0 self.changedby='' # the following only works because Person is in a separate module # that is also available to the client: self.person=Person("Irmen de Jong","30") ######## testclass object (standalone - delegate approach) class testclass2(object): def __init__(self): self.sum=0 self.changedby='' # the following only works because Person is in a separate module # that is also available to the client: self.person=Person("Irmen de Jong","30") ######## main program testserver.start(testclass,'attributes')
#!/usr/bin/env python import sys, os sys.path.insert(0, os.pardir) # to find testserver.py import testserver import Pyro.core import inherit ######## testclass object class testclass(Pyro.core.ObjBase, inherit.Fsub): def __init__(self): Pyro.core.ObjBase.__init__(self) ######## main program testserver.start(testclass, 'inheritance')
#!/usr/bin/env python import sys, os sys.path.insert(0,os.pardir) # to find testserver.py import testserver import Pyro.core import inherit ######## testclass object class testclass(Pyro.core.ObjBase, inherit.Fsub): def __init__(self): Pyro.core.ObjBase.__init__(self) ######## main program testserver.start(testclass, 'inheritance')
#!/usr/bin/env python import sys, os sys.path.insert(0, os.pardir) # to find testserver.py import testserver import Pyro.core import factory ###### For educational purposes, disable threads Pyro.config.PYRO_MULTITHREADED = 0 ######## main program print 'Server PID=', os.getpid() testserver.start(factory.CarFactory, 'factory')
#!/usr/bin/env python import sys, os sys.path.insert(0,os.pardir) # to find testserver.py import testserver import Pyro.core ######## testclass object class testclass(object): def setname(self,name): self.name=name def getname(self): return self.name ######## main program Pyro.core.initServer() Pyro.config.PYRO_TRACELEVEL=3 Pyro.config.PYRO_LOGFILE='server_log' Pyro.config.PYRO_MAXCONNECTIONS = 10 print 'Reduced max number of simultaneous connections to 10' print 'Check the logfile for messages: server_log' testserver.start(testclass, 'maxclients', delegate=1)
#!/usr/bin/env python import sys, os sys.path.insert(0,os.pardir) # to find testserver.py import testserver import Pyro.core ######## testclass object class testclass(object): def transfer(self,data): print 'received',len(data),'bytes' return len(data) ######## main program testserver.start(testclass, 'hugetransfer', delegate=1)
#!/usr/bin/env python import sys,os sys.path.insert(0,os.pardir) # to find testserver.py import testserver import Pyro.core import excep ######## testclass object class testclass(Pyro.core.ObjBase, excep.testclass): def __init__(self): Pyro.core.ObjBase.__init__(self) ######## main program testserver.start(testclass, 'exceptions')
#!/usr/bin/env python import sys, os sys.path.insert(0, os.pardir) # to find testserver.py import testserver import Pyro.core import excep ######## testclass object class testclass(Pyro.core.ObjBase, excep.testclass): def __init__(self): Pyro.core.ObjBase.__init__(self) ######## main program testserver.start(testclass, 'exceptions')