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-devel

[Xen-devel] [PATCH] avoid python 2.6 DeprecationWarnings

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] avoid python 2.6 DeprecationWarnings
From: Brendan Cully <brendan@xxxxxxxxx>
Date: Tue, 12 May 2009 14:49:20 -0700
Delivery-date: Tue, 12 May 2009 14:50:59 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.19 (2009-04-29)
The attached patch updates the python tools with python 2.6 versions
of the sha and set classes. Without this, every xm command generates a
warning, and so does xend when it starts.

I don't think I'm actually using the affected methods, so this patch
is only "compile" tested.
# HG changeset patch
# User Brendan Cully <brendan@xxxxxxxxx>
# Date 1242164632 25200
# Node ID 45498072e34cf066226fc0fbbc24849ac147f0f4
# Parent  2522cc95efd2f3fadf7342d18fe86e8f37f89c2a
Avoid DeprecationWarnings in python 2.6.
Use hashlib.sha1 instead of sha.sha, and set instead of sets.Set.
If import fails (as it will on older pythons), fall back to the
old types.

Signed-off-by: Brendan Cully <brendan@xxxxxxxxx>

diff -r 2522cc95efd2 -r 45498072e34c tools/python/xen/util/acmpolicy.py
--- a/tools/python/xen/util/acmpolicy.py        Mon May 11 13:52:04 2009 +0100
+++ b/tools/python/xen/util/acmpolicy.py        Tue May 12 14:43:52 2009 -0700
@@ -17,12 +17,19 @@
 #============================================================================
 
 import os
-import sha
 import stat
 import array
 import struct
 import shutil
 import commands
+
+# sha is deprecated as of python 2.6
+try:
+    from hashlib import sha1
+except ImportError:
+    # but hashlib was only added in python 2.5
+    from sha import new as sha1
+
 from xml.dom import minidom, Node
 from xen.xend.XendLogging import log
 from xen.util import xsconstants, bootloader, mkdir
@@ -1102,8 +1109,8 @@
         return None
 
     def hash(self):
-        """ Calculate a SAH1 hash of the XML policy """
-        return sha.sha(self.toxml())
+        """ Calculate a SHA1 hash of the XML policy """
+        return sha1(self.toxml())
 
     def save(self):
         ### Save the XML policy into a file ###
diff -r 2522cc95efd2 -r 45498072e34c tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Mon May 11 13:52:04 2009 +0100
+++ b/tools/python/xen/xend/XendAPI.py  Tue May 12 14:43:52 2009 -0700
@@ -18,7 +18,6 @@
 import inspect
 import os
 import Queue
-import sets
 import string
 import sys
 import traceback
@@ -26,6 +25,12 @@
 import time
 import xmlrpclib
 
+# sets is deprecated as of python 2.6, but set is unavailable in 2.3
+try:
+    set
+except ImportError:
+    from sets import Set as set
+
 import XendDomain, XendDomainInfo, XendNode, XendDmesg
 import XendLogging, XendTaskManager, XendAPIStore
 
@@ -119,16 +124,17 @@
 def event_register(session, reg_classes):
     if session not in event_registrations:
         event_registrations[session] = {
-            'classes' : sets.Set(),
+            'classes' : set(),
             'queue'   : Queue.Queue(EVENT_QUEUE_LENGTH),
             'next-id' : 1
             }
     if not reg_classes:
         reg_classes = classes
-    if hasattr(set, 'union_update'):
-        event_registrations[session]['classes'].union_update(reg_classes)
+    sessionclasses = event_registrations[session]['classes']
+    if hasattr(sessionclasses, 'union_update'):
+        sessionclasses.union_update(reg_classes)
     else:
-        event_registrations[session]['classes'].update(reg_classes)
+        sessionclasses.update(reg_classes)
 
 
 
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>