예제 #1
0
파일: shop2.py 프로젝트: irmen/Pyro3
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')

예제 #2
0
# 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')

예제 #3
0
#!/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)
예제 #4
0
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')

예제 #5
0
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')
예제 #6
0
#!/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')
예제 #7
0
#!/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')


예제 #8
0
#!/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)
예제 #9
0
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')

예제 #10
0
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')
예제 #11
0
파일: server.py 프로젝트: irmen/Pyro3
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')


예제 #12
0
#!/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')
예제 #13
0
파일: server.py 프로젝트: irmen/Pyro3
#!/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')

예제 #14
0
#!/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')


예제 #15
0
파일: server.py 프로젝트: irmen/Pyro3
#!/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)

예제 #16
0
#!/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')
예제 #17
0
파일: server.py 프로젝트: irmen/Pyro3
#!/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)


예제 #18
0
파일: server.py 프로젝트: irmen/Pyro3
#!/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')
예제 #19
0
#!/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')