1
# GNU Enterprise RPC interface - Pythonware-XMLRPC client adapter
3
# Copyright 2001-2005 Free Software Foundation
5
# This file is part of GNU Enterprise.
7
# GNU Enterprise is free software; you can redistribute it
8
# and/or modify it under the terms of the GNU General Public
9
# License as published by the Free Software Foundation; either
10
# version 2, or (at your option) any later version.
12
# GNU Enterprise is distributed in the hope that it will be
13
# useful, but WITHOUT ANY WARRANTY; without even the implied
14
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
# PURPOSE. See the GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public
18
# License along with program; see the file COPYING. If not,
19
# write to the Free Software Foundation, Inc., 59 Temple Place
20
# - Suite 330, Boston, MA 02111-1307, USA.
22
# $Id: ClientAdapter.py 7009 2005-02-11 17:04:16Z reinhard $
29
# url The complete URI address of the XML-RPC service.
30
# e.g, url="https://www.domain.com:9876/service.php"
32
# transport The service transport (either "http" or "https")
33
# host The hostname or IP address of the service
34
# port The port that the service is located on
41
from gnue.common.apps import errors, GDebug
42
from gnue.common.rpc import client
43
from gnue.common.rpc.drivers import Base
48
tmsg = u_("\nUnable to load xmlrpclib. To use the XML-RPC interface, \n"
49
"please install xmlrpc from:\n"
50
" http://www.pythonware.com/products/xmlrpc/")
51
raise client.AdapterInitializationError, tmsg
55
# =============================================================================
57
# =============================================================================
59
class ClientAdapter (Base.Client):
61
_default_transport = 'http'
64
# ---------------------------------------------------------------------------
66
# ---------------------------------------------------------------------------
68
def __init__ (self, params):
70
Base.Client.__init__ (self, params)
73
if hasattr (params, 'loglevel'):
74
verbose = params ['loglevel']
78
# create the real xmlrpc server proxy (i.e. client)
79
self.__proxy = xmlrpclib.Server (self._url, verbose=verbose)
81
# ---------------------------------------------------------------------------
82
# Run a procedure on the server
83
# ---------------------------------------------------------------------------
85
def _runMethod (self, method, *args, **params):
87
__args = [typeconv.python_to_rpc (arg, client.InvalidParameter)
90
# TODO: Add type conversion for **params
92
to_call = getattr (self.__proxy, method);
95
result = to_call (*__args, **params)
97
except xmlrpclib.Fault, e:
98
(exType, exName, exMessage, exDetail) = string.split (e.faultString,
100
raise errors.RemoteError, (exType, exName, exMessage, exDetail)
103
raise errors.AdminError, errors.getException () [2]
105
# check, if an object handle is sent
106
# TODO: make a better check
107
if type(result)==type("String") and len(result)==40 :
109
# create an proxy for this handle
110
return self._createproxy ("[%s]" % result)
113
return typeconv.rpc_to_python (result, client.InvalidParameter)