zephir.eolerpclib

Package zephir :: Module eolerpclib |
[frames] | no frames]

# Source Code for Module zephir.eolerpclib

      1  # -*- coding: UTF-8 -*-
      2  ###########################################################################
      3  # Eole NG - 2007
      4  # Copyright Pole de Competence Eole  (Ministere Education - Academie Dijon)
      5  # Licence CeCill  cf /root/LicenceEole.txt
      6  # eole@ac-dijon.fr
      7  #
      8  # eolerpclib.py
      9  #
     10  # Surclassage de xmlrpclib pour Zephir
     11  # (non affichage du login/mdp dans les logs en cas d'erreur)
     12  #
     13  ###########################################################################
     14
     15  import xmlrpclib
     16
     17  # modification de ProtocolError pour cacher le login/mot de passe de l'url
     18 -class ProtocolError(xmlrpclib.Error):
     19      """Indicates an HTTP protocol error."""
     20 -    def __init__(self, url, errcode, errmsg, headers):
     21          xmlrpclib.Error.__init__(self)
     22          # on supprime le login/mot de passe de l'url en cas d'affichage
     23          if "@" in url:
     24              url = url.split('@')[1]
     25          self.url = url
     26          self.errcode = errcode
     27          self.errmsg = errmsg
     28          self.headers = headers
     29 -    def __repr__(self):
     30          return (
     31              "<ProtocolError for %s: %s %s>" %
     32              (self.url, self.errcode, self.errmsg)
     33              )
     34
     35 -class EoleProxy:
     36      """uri [,options] -> a logical connection to an XML-RPC server
     37
     38      uri is the connection point on the server, given as
     39      scheme://host/target.
     40
     41      The standard implementation always supports the "http" scheme.  If
     42      SSL socket support is available (Python 2.0), it also supports
     43      "https".
     44
     45      If the target part and the slash preceding it are both omitted,
     46      "/RPC2" is assumed.
     47
     48      The following options can be given as keyword arguments:
     49
     50          transport: a transport factory
     51          encoding: the request encoding (default is UTF-8)
     52
     53      All 8-bit strings passed to the server proxy are assumed to use
     54      the given encoding.
     55      """
     56
     57 -    def __init__(self, uri, transport=None, encoding=None, verbose=0,
     58                   allow_none=0, use_datetime=0):
     59          # establish a "logical" server connection
     60
     61          # get the url
     62          import urllib
     63          type, uri = urllib.splittype(uri)
     64          if type not in ("http", "https"):
     65              raise IOError, "unsupported XML-RPC protocol"
     66          # FIX EOLE : correction pour prise en compte correcte du nom utilisateur/mot de passe
     67          # (exemple : mot de passe contenant '/')
     68          user, uri = urllib.splituser(uri)
     69          if user:
     70              self.__host, self.__handler = urllib.splithost('//'+uri)
     71              self.__host = user[user.index('//')+2:] + '@' + self.__host
     72          else:
     73              self.__host, self.__handler = urllib.splithost(uri)
     74          # END FIX EOLE
     75          if not self.__handler:
     76              self.__handler = "/RPC2"
     77
     78          if transport is None:
     79              if type == "https":
     80                  transport = xmlrpclib.SafeTransport(use_datetime=use_datetime)
     81              else:
     82                  transport = xmlrpclib.Transport(use_datetime=use_datetime)
     83          self.__transport = transport
     84
     85          self.__encoding = encoding
     86          self.__verbose = verbose
     87          self.__allow_none = allow_none
     88
     89 -    def __request(self, methodname, params):
     90          # call a method on the remote server
     91
     92          request = xmlrpclib.dumps(params, methodname, encoding=self.__encoding,
     93                          allow_none=self.__allow_none)
     94
     95          response = self.__transport.request(
     96              self.__host,
     97              self.__handler,
     98              request,
     99              verbose=self.__verbose
    100              )
    101
    102          if len(response) == 1:
    103              response = response[0]
    104
    105          return response
    106
    107 -    def __repr__(self):
    108          return (
    109              "<ServerProxy for %s%s>" %
    110              (self.__host, self.__handler)
    111              )
    112
    113      __str__ = __repr__
    114
    115 -    def __getattr__(self, name):
    116          # magic method dispatcher
    117          return xmlrpclib._Method(self.__request, name)
    118
    119  xmlrpclib.ProtocolError = ProtocolError
    120