xm: fix message in OptionError deprecated since Python 2.6
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 2 Dec 2009 08:47:49 +0000 (08:47 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 2 Dec 2009 08:47:49 +0000 (08:47 +0000)
BaseException.message has been deprecated since Python 2.6.  To
prevent DeprecationWarning from popping up over this pre-existing
attribute, use a new property that takes lookup precedence.

Signed-off-by: Wei Kong <weikong.cn@gmail.com>
tools/python/xen/xm/opts.py

index 3bfa8eb6ad2db1ad9ab25d5720c019600b11b874..5b69fa263a3e2a1af07c558763d8f07b63700dc6 100644 (file)
@@ -55,10 +55,19 @@ def wrap(text, width = 70):
     return lines
 
 class OptionError(Exception):
+    def _get_message(self):
+        return self.__message
+
+    def _set_message(self, value):
+        self.__message = value
+
+    message = property(_get_message, _set_message)
+
     """Denotes an error in option parsing."""
     def __init__(self, message, usage = ''):
         self.message = message
         self.usage = usage
+        Exception.__init__(self, message)
     def __str__(self):
         return self.message