ia64/xen-unstable

changeset 13230:444315d1ca5a

Resurrect cset 13174:766eec31afab, with one fix -- pass the fallback flag to
gettext.translation so that this module works if the message database is
missing (it's still an optional part of the build).

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Fri Dec 29 20:17:01 2006 +0000 (2006-12-29)
parents 974fb31dcbe9
children a578c9703416
files tools/python/xen/xm/XenAPI.py
line diff
     1.1 --- a/tools/python/xen/xm/XenAPI.py	Fri Dec 29 18:17:56 2006 +0000
     1.2 +++ b/tools/python/xen/xm/XenAPI.py	Fri Dec 29 20:17:01 2006 +0000
     1.3 @@ -50,7 +50,7 @@ import xmlrpclib
     1.4  import xen.util.xmlrpclib2
     1.5  
     1.6  
     1.7 -gettext.install('xen-xm')
     1.8 +translation = gettext.translation('xen-xm', fallback = True)
     1.9  
    1.10  class Failure(Exception):
    1.11      def __init__(self, details):
    1.12 @@ -68,7 +68,7 @@ class Failure(Exception):
    1.13  
    1.14      def __str__(self):
    1.15          try:
    1.16 -            return _(self.details[0]) % self._details_map()
    1.17 +            return translation.ugettext(self.details[0]) % self._details_map()
    1.18          except TypeError, exn:
    1.19              return "Message database broken: %s.\nXen-API failure: %s" % \
    1.20                     (exn, str(self.details))
    1.21 @@ -108,6 +108,8 @@ class Session(xen.util.xmlrpclib2.Server
    1.22                                                   encoding, verbose,
    1.23                                                   allow_none)
    1.24          self._session = None
    1.25 +        self.last_login_method = None
    1.26 +        self.last_login_params = None
    1.27  
    1.28  
    1.29      def xenapi_request(self, methodname, params):
    1.30 @@ -121,7 +123,11 @@ class Session(xen.util.xmlrpclib2.Server
    1.31                  result = _parse_result(getattr(self, methodname)(*full_params))
    1.32                  if result == _RECONNECT_AND_RETRY:
    1.33                      retry_count += 1
    1.34 -                    self._login(self.last_login_method, self.last_login_params)
    1.35 +                    if self.last_login_method:
    1.36 +                        self._login(self.last_login_method,
    1.37 +                                    self.last_login_params)
    1.38 +                    else:
    1.39 +                        raise xmlrpclib.Fault(401, 'You must log in')
    1.40                  else:
    1.41                      return result
    1.42              raise xmlrpclib.Fault(
    1.43 @@ -172,10 +178,18 @@ class _Dispatcher:
    1.44      def __init__(self, send, name):
    1.45          self.__send = send
    1.46          self.__name = name
    1.47 +
    1.48 +    def __repr__(self):
    1.49 +        if self.__name:
    1.50 +            return '<XenAPI._Dispatcher for %s>' % self.__name
    1.51 +        else:
    1.52 +            return '<XenAPI._Dispatcher>'
    1.53 +
    1.54      def __getattr__(self, name):
    1.55          if self.__name is None:
    1.56              return _Dispatcher(self.__send, name)
    1.57          else:
    1.58              return _Dispatcher(self.__send, "%s.%s" % (self.__name, name))
    1.59 +
    1.60      def __call__(self, *args):
    1.61          return self.__send(self.__name, args)