~ubuntu-branches/ubuntu/hardy/gnue-common/hardy

« back to all changes in this revision

Viewing changes to src/rpc/drivers/xmlrpc/pw_xmlrpc/ClientAdapter.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-03-09 11:06:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050309110631-8gvvn39q7tjz1kj6
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# GNU Enterprise RPC interface - Pythonware-XMLRPC client adapter
 
2
#
 
3
# Copyright 2001-2005 Free Software Foundation
 
4
#
 
5
# This file is part of GNU Enterprise.
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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.
 
21
#
 
22
# $Id: ClientAdapter.py 7009 2005-02-11 17:04:16Z reinhard $
 
23
 
 
24
# NOTES:
 
25
# Requires Python 2.3
 
26
#
 
27
# Client Parameters:
 
28
#
 
29
#    url         The complete URI address of the XML-RPC service.
 
30
#                e.g, url="https://www.domain.com:9876/service.php"
 
31
#    ..or..
 
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
 
35
#
 
36
 
 
37
import string
 
38
import sys
 
39
import socket
 
40
 
 
41
from gnue.common.apps import errors, GDebug
 
42
from gnue.common.rpc import client
 
43
from gnue.common.rpc.drivers import Base
 
44
 
 
45
try:
 
46
  import xmlrpclib
 
47
except ImportError:
 
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
 
52
 
 
53
import typeconv
 
54
 
 
55
# =============================================================================
 
56
# Client driver
 
57
# =============================================================================
 
58
 
 
59
class ClientAdapter (Base.Client):
 
60
 
 
61
  _default_transport = 'http'
 
62
  _default_port      = 8765
 
63
 
 
64
  # ---------------------------------------------------------------------------
 
65
  # Initialize object
 
66
  # ---------------------------------------------------------------------------
 
67
 
 
68
  def __init__ (self, params):
 
69
 
 
70
    Base.Client.__init__ (self, params)
 
71
 
 
72
    # setLoglevel    
 
73
    if hasattr (params, 'loglevel'):
 
74
      verbose = params ['loglevel']
 
75
    else:
 
76
      verbose = 0
 
77
 
 
78
    # create the real xmlrpc server proxy (i.e. client)
 
79
    self.__proxy = xmlrpclib.Server (self._url, verbose=verbose)
 
80
 
 
81
  # ---------------------------------------------------------------------------
 
82
  # Run a procedure on the server
 
83
  # ---------------------------------------------------------------------------
 
84
 
 
85
  def _runMethod (self, method, *args, **params):
 
86
    
 
87
    __args = [typeconv.python_to_rpc (arg, client.InvalidParameter)
 
88
              for arg in args]
 
89
 
 
90
    # TODO: Add type conversion for **params 
 
91
 
 
92
    to_call = getattr (self.__proxy, method);
 
93
        
 
94
    try:
 
95
      result = to_call (*__args, **params)
 
96
 
 
97
    except xmlrpclib.Fault, e:
 
98
      (exType, exName, exMessage, exDetail) = string.split (e.faultString,
 
99
                                                            u'\x91')
 
100
      raise errors.RemoteError, (exType, exName, exMessage, exDetail)
 
101
 
 
102
    except socket.error:
 
103
      raise errors.AdminError, errors.getException () [2]
 
104
 
 
105
    # check, if an object handle is sent
 
106
    # TODO: make a better check
 
107
    if type(result)==type("String") and len(result)==40 :
 
108
 
 
109
      # create an proxy for this handle
 
110
      return self._createproxy ("[%s]" % result)
 
111
 
 
112
    else:
 
113
      return typeconv.rpc_to_python (result, client.InvalidParameter)