WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Added __repr__ implementation, initialise

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Added __repr__ implementation, initialise last_login_method to None, and
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 29 Dec 2006 14:20:16 -0800
Delivery-date: Fri, 29 Dec 2006 14:21:15 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1167319725 0
# Node ID 766eec31afabc566a54749a8b5795160c8687de5
# Parent  3f24490932cd6e76983bfee12206b14254f2c3cd
Added __repr__ implementation, initialise last_login_method to None, and
use gettext's ugettext explicitly, rather than using gettext.install.  These
things together improve the error messages that you get when using this
module incorrectly in the interactive interpreter.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/python/xen/xm/XenAPI.py |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff -r 3f24490932cd -r 766eec31afab tools/python/xen/xm/XenAPI.py
--- a/tools/python/xen/xm/XenAPI.py     Thu Dec 28 15:26:45 2006 +0000
+++ b/tools/python/xen/xm/XenAPI.py     Thu Dec 28 15:28:45 2006 +0000
@@ -50,7 +50,7 @@ import xen.util.xmlrpclib2
 import xen.util.xmlrpclib2
 
 
-gettext.install('xen-xm')
+translation = gettext.translation('xen-xm')
 
 class Failure(Exception):
     def __init__(self, details):
@@ -68,7 +68,7 @@ class Failure(Exception):
 
     def __str__(self):
         try:
-            return _(self.details[0]) % self._details_map()
+            return translation.ugettext(self.details[0]) % self._details_map()
         except TypeError, exn:
             return "Message database broken: %s.\nXen-API failure: %s" % \
                    (exn, str(self.details))
@@ -108,6 +108,8 @@ class Session(xen.util.xmlrpclib2.Server
                                                  encoding, verbose,
                                                  allow_none)
         self._session = None
+        self.last_login_method = None
+        self.last_login_params = None
 
 
     def xenapi_request(self, methodname, params):
@@ -121,7 +123,11 @@ class Session(xen.util.xmlrpclib2.Server
                 result = _parse_result(getattr(self, methodname)(*full_params))
                 if result == _RECONNECT_AND_RETRY:
                     retry_count += 1
-                    self._login(self.last_login_method, self.last_login_params)
+                    if self.last_login_method:
+                        self._login(self.last_login_method,
+                                    self.last_login_params)
+                    else:
+                        raise xmlrpclib.Fault(401, 'You must log in')
                 else:
                     return result
             raise xmlrpclib.Fault(
@@ -172,10 +178,18 @@ class _Dispatcher:
     def __init__(self, send, name):
         self.__send = send
         self.__name = name
+
+    def __repr__(self):
+        if self.__name:
+            return '<XenAPI._Dispatcher for %s>' % self.__name
+        else:
+            return '<XenAPI._Dispatcher>'
+
     def __getattr__(self, name):
         if self.__name is None:
             return _Dispatcher(self.__send, name)
         else:
             return _Dispatcher(self.__send, "%s.%s" % (self.__name, name))
+
     def __call__(self, *args):
         return self.__send(self.__name, args)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Added __repr__ implementation, initialise last_login_method to None, and, Xen patchbot-unstable <=