[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xend: Avoid deprecation warnings with Python 2.6.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1242693274 -3600
# Node ID 4d6029814742cf32ca6b6212acb5b291a741c079
# Parent  674e4d43955f594e1677be50dd18e3e8beb72dd7
xend: Avoid deprecation warnings with Python 2.6.

Signed-off-by: Brendan Cully <brendan@xxxxxxxxx>
---
 tools/python/xen/util/acmpolicy.py |   13 ++++++++++---
 tools/python/xen/xend/XendAPI.py   |   16 +++++++++++-----
 2 files changed, 21 insertions(+), 8 deletions(-)

diff -r 674e4d43955f -r 4d6029814742 tools/python/xen/util/acmpolicy.py
--- a/tools/python/xen/util/acmpolicy.py        Tue May 19 01:31:26 2009 +0100
+++ b/tools/python/xen/util/acmpolicy.py        Tue May 19 01:34:34 2009 +0100
@@ -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 @@ class ACMPolicy(XSPolicy):
         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 674e4d43955f -r 4d6029814742 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Tue May 19 01:31:26 2009 +0100
+++ b/tools/python/xen/xend/XendAPI.py  Tue May 19 01:34:34 2009 +0100
@@ -18,13 +18,18 @@ import inspect
 import inspect
 import os
 import Queue
-import sets
 import string
 import sys
 import traceback
 import threading
 import time
 import xmlrpclib
+
+# sets is deprecated as of python 2.6, but set is unavailable in 2.3
+try:
+    set
+except NameError:
+    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)
 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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.