[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] avoid python 2.6 DeprecationWarnings
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). On Tuesday, 12 May 2009 at 14:49, Brendan Cully wrote: > 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 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 Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |