2
# This file is part of GNU Enterprise.
4
# GNU Enterprise is free software; you can redistribute it
5
# and/or modify it under the terms of the GNU General Public
6
# License as published by the Free Software Foundation; either
7
# version 2, or (at your option) any later version.
9
# GNU Enterprise is distributed in the hope that it will be
10
# useful, but WITHOUT ANY WARRANTY; without even the implied
11
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public
15
# License along with program; see the file COPYING. If not,
16
# write to the Free Software Foundation, Inc., 59 Temple Place
17
# - Suite 330, Boston, MA 02111-1307, USA.
19
# Copyright 2001-2005 Free Software Foundation
25
# Class that provides a "proxy" GComm driver (i.e, the client and server
26
# are actually run in the same program instance -- requests are "proxied"
27
# from the client to the server via this driver; no network activity occurs)
33
# _proxy The actual ServerAdapter instance. This has to be set by
34
# the application, not by a config file.
38
# We provide both a client and a server driver...
40
CLIENT = 1 # ClientAdapter
41
SERVER = 1 # ServerAdapter
44
from gnue.common.rpc.drivers import GCommBase
45
from gnue.common.rpc import GComm
49
##############################################################################
53
class ClientAdapter(GCommBase.Client):
55
def __init__(self, params):
56
#print "Proxy Client Adapter created"
58
self._serverproxy = params['_proxy']
60
tmsg = _('Proxy client adapter should be called with the server object')
61
raise GComm.AdapterInitializationError, tmsg
63
def request(self, service, params={}):
64
proxy = _ProxyObject(self, service, \
65
servicer=self._serverproxy._bindings[service],
66
proxyinstance=self._serverproxy._bindings[service]())
72
##############################################################################
76
class ServerAdapter(GCommBase.Server):
78
def __init__(self, rpcdef, bindings, params):
79
#print "Proxy Server Adapter created"
80
GCommBase.Server.__init__(self, rpcdef, bindings, params)
82
def raiseException(self, exception, message, event=None):
83
raise exception, message
88
##############################################################################
92
class _ProxyObject(GCommBase.ProxyObject):
93
def __init__(self, adapter, attr, parent=None, **params):
94
GCommBase.ProxyObject.__init__(self, adapter, attr, parent=None, **params)
97
# Server raised an exception...
98
# Translate the exception into a local python
99
# exception and raise it...
100
def _exceptionRaised(self, data):
101
if data.isGNUeGenerated():
102
name, text = string.split(data.message,': ',1)
104
exception = _lookup[name]
105
raise exception, text
108
raise StandardError, data.message
111
def __call__(self, *args, **params):
112
#print "Calling %s" % self._adapter
113
return self._adapter.runMethod(self, string.join(self._attrPath,'.'),