avoid python 2.6 DeprecationWarnings
PATCH 1/1 avoid python 2.6 DeprecationWarnings
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 <[email protected]>
# 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.
tools/python/xen/util/acmpolicy.py +10 -3
@@ -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 ###
tools/python/xen/xend/XendAPI.py +11 -5
@@ -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
[email protected]
http://lists.xensource.com/xen-devel
Sorry, that was the wrong version. I don't have python 2.3 at hand, but I believe calling 'set' on it will generate a NameError (not an ImportError).
Quoted 6 lines · Brendan Cully
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 <[email protected]>
# 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.
tools/python/xen/util/acmpolicy.py +10 -3
@@ -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 ###
tools/python/xen/xend/XendAPI.py +11 -5
@@ -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 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): 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
[email protected]
http://lists.xensource.com/xen-devel