fix python 2.6 warnings
PATCH 1/1 fix python 2.6 warnings
Hi,
Attached patch fixes a few python warnings about deprecated modules.
cheers,
Gerd
tools/python/xen/util/acmpolicy.py renamed from tools/python/xen/util/acmpolicy.py.deprecated +2 -2
@@ -17,7 +17,7 @@ #============================================================================ import os -import sha +import hashlib import stat import array import struct
@@ -1103,7 +1103,7 @@ class ACMPolicy(XSPolicy): def hash(self): """ Calculate a SAH1 hash of the XML policy """ - return sha.sha(self.toxml()) + return hashlib.sha1(self.toxml()) def save(self): ### Save the XML policy into a file ###
tools/python/xen/xend/XendAPI.py renamed from tools/python/xen/xend/XendAPI.py.deprecated +1 -2
@@ -18,7 +18,6 @@ import inspect import os import Queue -import sets import string import sys import traceback
@@ -116,7 +115,7 @@ event_registrations = {} def event_register(session, reg_classes): if session not in event_registrations: event_registrations[session] = { - 'classes' : sets.Set(), + 'slasses' : set(), 'queue' : Queue.Queue(EVENT_QUEUE_LENGTH), 'next-id' : 1 }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Gerd Hoffmann
Hi,
Attached patch fixes a few python warnings about deprecated modules.
Oops, that one had a tyops, fixed version attached.
cheers,
Gerd
tools/python/xen/util/acmpolicy.py renamed from tools/python/xen/util/acmpolicy.py.deprecated +2 -2
@@ -17,7 +17,7 @@ #============================================================================ import os -import sha +import hashlib import stat import array import struct
@@ -1103,7 +1103,7 @@ class ACMPolicy(XSPolicy): def hash(self): """ Calculate a SAH1 hash of the XML policy """ - return sha.sha(self.toxml()) + return hashlib.sha1(self.toxml()) def save(self): ### Save the XML policy into a file ###
tools/python/xen/xend/XendAPI.py renamed from tools/python/xen/xend/XendAPI.py.deprecated +1 -2
@@ -18,7 +18,6 @@ import inspect import os import Queue -import sets import string import sys import traceback
@@ -116,7 +115,7 @@ event_registrations = {} 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 }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Gerd Hoffmann writes ("[Xen-devel] [patch] fix python 2.6 warnings"):
Quoted 1 line
Attached patch fixes a few python warnings about deprecated modules.
Can you please confirm in which Python version the new modules were introduced ? Some people (including our automatic test systems!) are using very old versions of python and it would be nice if that kept working.
Ian.
Quoted 7 lines · Ian Jackson
Gerd Hoffmann writes ("[Xen-devel] [patch] fix python 2.6 warnings"):
Quoted 1 line
Attached patch fixes a few python warnings about deprecated modules.
Can you please confirm in which Python version the new modules were introduced ? Some people (including our automatic test systems!) are using very old versions of python and it would be nice if that kept working.
set type (obsoletes sets module) was added in 2.4
hashlib (obsoletes sha module) was added in 2.5
For reference: RHEL-5 ships with python 2.4.
Which makes me think at least the hashlib one needs a more sophisticated approach so it keeps working on pre-2.5 versions ...
cheers,
Gerd
Quoted 7 lines · Gerd Hoffmann
Quoted 4 lines
Can you please confirm in which Python version the new modules were introduced ? Some people (including our automatic test systems!) are using very old versions of python and it would be nice if that kept working.
set type (obsoletes sets module) was added in 2.4
hashlib (obsoletes sha module) was added in 2.5
We're using 2.4 too (we have 2.5, and 2.6, but haven't yet done the work to move versions).
regards
john
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Gerd Hoffmann <[email protected]> 10.03.09 14:44 >>>
Which makes me think at least the hashlib one needs a more sophisticated approach so it keeps working on pre-2.5 versions ...
Something like this (I had hoped this would have been submitted long ago, but apparently it wasn't even attempted).
Jan
tools/python/xen/util/acmpolicy.py +4 -1
@@ -17,7 +17,10 @@ #============================================================================ import os -import sha +try: + import hashlib # python v2.6 or newer +except ImportError: + import sha # python v2.5 or older import stat import array import struct
Review
Quoted 12 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Gerd Hoffmann <[email protected]> 10.03.09 14:44 >>>
Which makes me think at least the hashlib one needs a more sophisticated approach so it keeps working on pre-2.5 versions ...
Something like this (I had hoped this would have been submitted long ago, but apparently it wasn't even attempted).
(quoted diff) +4
-1-import sha +try: + import hashlib # python v2.6 or newer +except ImportError: + import sha # python v2.5 or older
Well, due to the renaming (sha.sha -> hashlib.sha1) it isn't *that* easy. Patch below could work. WARNING: untested.
cheers,
Gerd
tools/python/xen/util/acmpolicy.py renamed from tools/python/xen/util/acmpolicy.py.deprecated +5 -2
@@ -17,7 +17,10 @@ #============================================================================ import os -import sha +try: + from hashlib import sha1 +except ImportError: + from sha import sha as sha1 import stat import array import struct
@@ -1103,7 +1106,7 @@ class ACMPolicy(XSPolicy): def hash(self): """ Calculate a SAH1 hash of the XML policy """ - return sha.sha(self.toxml()) + return sha1(self.toxml()) def save(self): ### Save the XML policy into a file ###
tools/python/xen/xend/XendAPI.py renamed from tools/python/xen/xend/XendAPI.py.deprecated +1 -2
@@ -18,7 +18,6 @@ import inspect import os import Queue -import sets import string import sys import traceback
@@ -116,7 +115,7 @@ event_registrations = {} 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 }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 18 lines · Jan Beulich
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Gerd Hoffmann <[email protected]> 10.03.09 14:44 >>>
Which makes me think at least the hashlib one needs a more sophisticated approach so it keeps working on pre-2.5 versions ...
Something like this (I had hoped this would have been submitted long ago, but apparently it wasn't even attempted).
Jan
tools/python/xen/util/acmpolicy.py +0
-0@@ -17,7 +17,10 @@ #============================================================================
tools/python/xen/util/acmpolicy.py line 26
Quoted 10 lines
tools/python/xen/util/acmpolicy.py +4
-1import os -import sha +try: + import hashlib # python v2.6 or newer +except ImportError: + import sha # python v2.5 or older import stat import array import struct
hello,
this might work better
-import sha
+try:
+ import sha1 from hashlib # python v2.5 or newer
+except ImportError:
+ import sha as sha1 # pre python v2.5
and call it with: sha1( foo )
Marc
Gerd Hoffmann writes ("Re: [Xen-devel] [patch] fix python 2.6 warnings"):
Quoted 4 lines
set type (obsoletes sets module) was added in 2.4
hashlib (obsoletes sha module) was added in 2.5For reference: RHEL-5 ships with python 2.4.
The automated test systems which manage propagation from staging to xen-unstable are running python 2.3.
Ian.
Quoted 1 line · Gerd Hoffmann
Attached patch fixes a few python warnings about deprecated modules.
Do you mean 'slasses'? My knowledge of python isn't great, but that looks like a typo.
Michael Young