ia64/xen-unstable

changeset 19609:4d6029814742

xend: Avoid deprecation warnings with Python 2.6.

Signed-off-by: Brendan Cully <brendan@cs.ubc.ca>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 19 01:34:34 2009 +0100 (2009-05-19)
parents 674e4d43955f
children a89e83f2d43e
files tools/python/xen/util/acmpolicy.py tools/python/xen/xend/XendAPI.py
line diff
     1.1 --- a/tools/python/xen/util/acmpolicy.py	Tue May 19 01:31:26 2009 +0100
     1.2 +++ b/tools/python/xen/util/acmpolicy.py	Tue May 19 01:34:34 2009 +0100
     1.3 @@ -17,12 +17,19 @@
     1.4  #============================================================================
     1.5  
     1.6  import os
     1.7 -import sha
     1.8  import stat
     1.9  import array
    1.10  import struct
    1.11  import shutil
    1.12  import commands
    1.13 +
    1.14 +# sha is deprecated as of python 2.6
    1.15 +try:
    1.16 +    from hashlib import sha1
    1.17 +except ImportError:
    1.18 +    # but hashlib was only added in python 2.5
    1.19 +    from sha import new as sha1
    1.20 +
    1.21  from xml.dom import minidom, Node
    1.22  from xen.xend.XendLogging import log
    1.23  from xen.util import xsconstants, bootloader, mkdir
    1.24 @@ -1102,8 +1109,8 @@ class ACMPolicy(XSPolicy):
    1.25          return None
    1.26  
    1.27      def hash(self):
    1.28 -        """ Calculate a SAH1 hash of the XML policy """
    1.29 -        return sha.sha(self.toxml())
    1.30 +        """ Calculate a SHA1 hash of the XML policy """
    1.31 +        return sha1(self.toxml())
    1.32  
    1.33      def save(self):
    1.34          ### Save the XML policy into a file ###
     2.1 --- a/tools/python/xen/xend/XendAPI.py	Tue May 19 01:31:26 2009 +0100
     2.2 +++ b/tools/python/xen/xend/XendAPI.py	Tue May 19 01:34:34 2009 +0100
     2.3 @@ -18,7 +18,6 @@
     2.4  import inspect
     2.5  import os
     2.6  import Queue
     2.7 -import sets
     2.8  import string
     2.9  import sys
    2.10  import traceback
    2.11 @@ -26,6 +25,12 @@ import threading
    2.12  import time
    2.13  import xmlrpclib
    2.14  
    2.15 +# sets is deprecated as of python 2.6, but set is unavailable in 2.3
    2.16 +try:
    2.17 +    set
    2.18 +except NameError:
    2.19 +    from sets import Set as set
    2.20 +
    2.21  import XendDomain, XendDomainInfo, XendNode, XendDmesg
    2.22  import XendLogging, XendTaskManager, XendAPIStore
    2.23  
    2.24 @@ -119,16 +124,17 @@ event_registrations = {}
    2.25  def event_register(session, reg_classes):
    2.26      if session not in event_registrations:
    2.27          event_registrations[session] = {
    2.28 -            'classes' : sets.Set(),
    2.29 +            'classes' : set(),
    2.30              'queue'   : Queue.Queue(EVENT_QUEUE_LENGTH),
    2.31              'next-id' : 1
    2.32              }
    2.33      if not reg_classes:
    2.34          reg_classes = classes
    2.35 -    if hasattr(set, 'union_update'):
    2.36 -        event_registrations[session]['classes'].union_update(reg_classes)
    2.37 +    sessionclasses = event_registrations[session]['classes']
    2.38 +    if hasattr(sessionclasses, 'union_update'):
    2.39 +        sessionclasses.union_update(reg_classes)
    2.40      else:
    2.41 -        event_registrations[session]['classes'].update(reg_classes)
    2.42 +        sessionclasses.update(reg_classes)
    2.43  
    2.44  
    2.45